Skip to content

Commit

Permalink
ci: use nx distribution (#1462)
Browse files Browse the repository at this point in the history
* ci: use nx distribution

* chore: set sha

* chore: remove nx token

* chore: fix

* chore: fix

* chore: fix

* chore: fix

* chore: fix

* chore: fix

* chore: fix

* chore: fix

* chore: also update main branch ci
  • Loading branch information
Saul-Mirone authored Aug 8, 2024
1 parent e126bb2 commit 7614b64
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 71 deletions.
70 changes: 54 additions & 16 deletions .github/workflows/ci-for-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,65 @@ on:

env:
CI: true
NX_CLOUD_DISTRIBUTED_EXECUTION: true
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
start:
uses: ./.github/workflows/start-nx-cloud.yml

test:
needs: start
uses: ./.github/workflows/test.yml
secrets:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

report:
if: ${{ always() }}
needs: [test]
build-and-test:
runs-on: ubuntu-latest
steps:
- name: on error
if: ${{ needs.test.result != 'success' }}
run: exit 1
- name: checkout code repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: setup node.js
uses: actions/setup-node@v4
with:
node-version: 20.11.0

- uses: pnpm/action-setup@v4.0.0
with:
run_install: false

- name: get pnpm store directory
id: pnpm-cache
run: echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT

- name: load cache
uses: actions/cache@v4
with:
path: |
~/.cache/Cypress
${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}

- uses: nrwl/nx-set-shas@v4

- run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --require-explicit-completion

- name: install dependencies
run: pnpm install

- name: build packs
run: pnpm nx affected -t build

- name: run lint
run: pnpm test:lint

- name: run cypress
run: pnpm nx affected -t e2e-ci @milkdown/e2e

- run: npx nx-cloud complete-ci-run
if: always()

- name: Upload test results
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: test-results-main
path: dist/cypress
if-no-files-found: ignore
88 changes: 65 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,71 @@ on:

env:
CI: true
NX_CLOUD_DISTRIBUTED_EXECUTION: true
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

jobs:
start:
uses: ./.github/workflows/start-nx-cloud.yml

test:
needs: start
uses: ./.github/workflows/test.yml
secrets:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

release:
needs: test
uses: ./.github/workflows/release-package.yml
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

report:
if: ${{ always() }}
needs: [release]
build-test-release:
runs-on: ubuntu-latest
steps:
- name: on error
if: ${{ needs.release.result != 'success' }}
run: exit 1
- name: checkout code repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: setup node.js
uses: actions/setup-node@v4
with:
node-version: 20.11.0

- uses: pnpm/action-setup@v4.0.0
with:
run_install: false

- name: get pnpm store directory
id: pnpm-cache
run: echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT

- name: load cache
uses: actions/cache@v4
with:
path: |
~/.cache/Cypress
${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}

- uses: nrwl/nx-set-shas@v4

- run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --require-explicit-completion

- name: install dependencies
run: pnpm install

# build all the packages to prepare for release
- name: build packs
run: pnpm build

- name: run lint
run: pnpm test:lint

- name: run cypress
run: pnpm nx affected -t e2e-ci @milkdown/e2e

- run: npx nx-cloud complete-ci-run
if: always()

- name: create versions or publish to npm registry
uses: changesets/action@v1
with:
publish: pnpm release
commit: 'ci(changeset): release milkdown'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Upload test results
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: test-results-main
path: dist/cypress
if-no-files-found: ignore
8 changes: 4 additions & 4 deletions e2e/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ export default defineConfig({
e2e: {
...nxE2EPreset(__filename, {
cypressDir: 'cypress',
bundler: 'vite',
webServerConfig: {
reuseExistingServer: true,
reuseExistingServer: !process.env.CI,
},
webServerCommands: {
default: 'nx run @milkdown/e2e:start',
},
ciWebServerCommand: 'nx run @milkdown/e2e:start',
ciWebServerCommand: 'nx serve @milkdown/e2e',
}),
baseUrl: 'http://localhost:5173',
baseUrl: `http://localhost:${process.env.CI ? 4173 : 5173}`,
fileServerFolder: '.',
},
retries: process.env.CI ? 2 : 0,
})
15 changes: 15 additions & 0 deletions e2e/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { resolve } from 'node:path'
import { cases } from './src/data'

const data = cases.reduce((acc, { link }) => {
const name = link.match(/[\w-]+/)?.[0] as string
return {
...acc,
[name]: resolve(__dirname, `src${link}index.html`),
}
}, {} as Record<string, string>)

export const input = {
main: resolve(__dirname, 'src/index.html'),
...data,
}
16 changes: 14 additions & 2 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"scripts": {
"start": "vite",
"build": "vite build",
"serve": "vite preview",
"preview": "vite preview",
"serve": "serve lib --listen 4173 -L",
"test": "nx cypress:e2e",
"test:verbose": "nx open-cypress"
},
Expand Down Expand Up @@ -43,7 +44,8 @@
"tslib": "^2.5.0"
},
"devDependencies": {
"cypress": "^13.0.0"
"cypress": "^13.0.0",
"serve": "^14.2.3"
},
"nx": {
"targets": {
Expand All @@ -54,6 +56,16 @@
"dependsOn": [
"build"
]
},
"preview": {
"dependsOn": [
"build"
]
},
"serve": {
"dependsOn": [
"build"
]
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions e2e/src/crepe/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Crepe, CrepeFeature } from '@milkdown/crepe'
import { basicLight } from '@uiw/codemirror-theme-basic'
import '@milkdown/crepe/theme/common/style.css'
import '@milkdown/crepe/theme/nord.css'

Expand All @@ -10,6 +11,9 @@ const crepe = new Crepe({
[CrepeFeature.CodeMirror]: true,
},
featureConfigs: {
[CrepeFeature.CodeMirror]: {
theme: basicLight,
},
[CrepeFeature.Placeholder]: {
text: 'Type / to use slash command',
},
Expand Down
2 changes: 2 additions & 0 deletions e2e/vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { defineConfig } from 'vite'
import { input } from './entry'

export default defineConfig({
root: 'src',
build: {
outDir: '../lib',
emptyOutDir: true,
rollupOptions: { input },
},
server: {
fs: {
Expand Down
22 changes: 4 additions & 18 deletions nx.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"targetDefaults": {
"build": {
"dependsOn": ["^build"],
Expand Down Expand Up @@ -28,27 +29,12 @@
"cache": true
}
},
"extends": "@nx/workspace/presets/npm.json",
"affected": {
"defaultBase": "main"
},
"pluginsConfig": {
"@nrwl/js": {
"analyzeSourceFiles": false
}
},
"$schema": "./node_modules/nx/schemas/nx-schema.json",
"namedInputs": {
"default": ["{projectRoot}/**/*", "sharedGlobals"],
"sharedGlobals": ["{workspaceRoot}/vite.config.ts"],
"production": [
"default",
"!{projectRoot}/cypress/**/*",
"!{projectRoot}/**/*.cy.[jt]s?(x)",
"!{projectRoot}/cypress.config.[jt]s"
]
"production": ["default"]
},
"nxCloudAccessToken": "ODhlMWM3YmItMjRmOC00OTBjLTk4N2ItN2Q1OWJhMWVlODcyfHJlYWQtd3JpdGU=",
"nxCloudAccessToken": "YTAwYWM5ZDgtOGM3OC00YTQwLThlZjUtNjQwZWE5NzUxZjk4fHJlYWQ=",
"plugins": [
{
"plugin": "@nx/storybook/plugin",
Expand All @@ -63,7 +49,7 @@
"plugin": "@nx/cypress/plugin",
"options": {
"targetName": "e2e",
"openTargetName": "open-cypress",
"openTargetName": "e2e-open",
"componentTestingTargetName": "component-test",
"ciTargetName": "e2e-ci"
}
Expand Down
1 change: 1 addition & 0 deletions packages/crepe/src/theme/common/block-edit.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
}

li {
min-width: 220px;
display: flex;
justify-content: flex-start;
align-items: center;
Expand Down
Loading

0 comments on commit 7614b64

Please sign in to comment.