diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59bfa5b..2fc7832 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,8 @@ jobs: - run: pnpm build - Test: + lint_prettier: + name: Lint [prettier] runs-on: ubuntu-latest steps: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 @@ -40,15 +41,31 @@ jobs: cache: pnpm - run: pnpm install --frozen-lockfile - - run: pnpm test -- -- --maxWorkers=100% --coverage - - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + - run: pnpm prettier --check . + + lint_eslint: + name: Lint [eslint] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + + - run: corepack enable pnpm + + - uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 with: - fail_ci_if_error: true + node-version-file: '.nvmrc' + cache: pnpm - lint_prettier: - name: Lint (prettier) + - run: pnpm install --frozen-lockfile + + - run: pnpm turbo run lint + + test_plan: + name: Test [plan] runs-on: ubuntu-latest + outputs: + packages: ${{ steps.plan.outputs.packages }} steps: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 @@ -61,11 +78,23 @@ jobs: - run: pnpm install --frozen-lockfile - - run: pnpm prettier --check . + # this step is only required in this repo because the cli source is not yet built + - run: pnpm turbo run build --filter=@stickyjs/turbo - lint_eslint: - name: Lint (eslint) + - id: plan + run: | + echo 'packages<> $GITHUB_OUTPUT + pnpm sticky-turbo plan test >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT + + test_run: + name: Test [run] runs-on: ubuntu-latest + needs: test_plan + strategy: + fail-fast: false + matrix: + package: ${{ fromJSON(needs.test_plan.outputs.packages) }} steps: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 @@ -78,4 +107,17 @@ jobs: - run: pnpm install --frozen-lockfile - - run: pnpm turbo run lint + - run: pnpm turbo run test --concurrency=1 --filter=${{ matrix.package }} -- --coverage --forceExit + + - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + + test_completed: + name: Test [completed] + runs-on: ubuntu-latest + needs: test_run + if: always() + steps: + - run: | + if ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'skipped') || contains(needs.*.result, 'cancelled') }} ; then + exit 1 + fi diff --git a/.github/workflows/oss-governance-bot.yml b/.github/workflows/oss-governance-bot.yml index 5e4f884..00d72fe 100644 --- a/.github/workflows/oss-governance-bot.yml +++ b/.github/workflows/oss-governance-bot.yml @@ -1,4 +1,4 @@ -name: OSS Governance +name: OSS on: pull_request_target: @@ -16,7 +16,8 @@ permissions: checks: write jobs: - Bot: + main: + name: Governance Bot runs-on: ubuntu-latest steps: - uses: BirthdayResearch/oss-governance-bot@37c8583c6b8596d173b68ffaed543e2485f4f193 # v3.0.0 diff --git a/.github/workflows/oss-governance-labeler.yml b/.github/workflows/oss-governance-labeler.yml index 4fe1829..e51e627 100644 --- a/.github/workflows/oss-governance-labeler.yml +++ b/.github/workflows/oss-governance-labeler.yml @@ -1,4 +1,4 @@ -name: OSS Governance +name: OSS on: pull_request_target: diff --git a/.github/workflows/oss-governance-labels.yml b/.github/workflows/oss-governance-labels.yml index 90303ca..df53bc5 100644 --- a/.github/workflows/oss-governance-labels.yml +++ b/.github/workflows/oss-governance-labels.yml @@ -1,4 +1,4 @@ -name: OSS Governance +name: OSS on: push: diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..4fa3907 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/packages/turbo/cli.js b/packages/turbo/cli.js new file mode 100755 index 0000000..ae51adc --- /dev/null +++ b/packages/turbo/cli.js @@ -0,0 +1,3 @@ +#! /usr/bin/env node +/* eslint-disable */ +require('./dist/cli.js'); diff --git a/packages/turbo/package.json b/packages/turbo/package.json index ea12f23..901ffcd 100644 --- a/packages/turbo/package.json +++ b/packages/turbo/package.json @@ -7,6 +7,9 @@ "main": "./dist/index.js", "source": "./src/index.ts", "types": "./dist/index.d.ts", + "bin": { + "sticky-turbo": "./cli.js" + }, "files": [ "dist/**" ], @@ -36,6 +39,9 @@ "jest": { "preset": "@stickyjs/jest" }, + "dependencies": { + "clipanion": "3.2.1" + }, "devDependencies": { "@stickyjs/jest": "workspace:*", "turbo": "1.10.6" diff --git a/packages/turbo/src/TurboPlanCommand.ts b/packages/turbo/src/TurboPlanCommand.ts new file mode 100644 index 0000000..e36fba1 --- /dev/null +++ b/packages/turbo/src/TurboPlanCommand.ts @@ -0,0 +1,30 @@ +import { Command, Option } from 'clipanion'; +import * as process from 'process'; + +import { Turbo } from './Turbo'; + +/** + * Running `sticky-turbo plan test` generate a list of packages that contains a `test` script in the package. + * You can use the output and loop through an array to run test individually via `turbo run test --filter=package` + */ +export class TurboPlanCommand extends Command { + static override paths = [[`plan`]]; + + task = Option.String({ required: true }); + + scope = Option.Boolean('--scope', true, { + description: 'Include scope in the package name, default to true', + }); + + async execute(): Promise { + const turbo = new Turbo(process.cwd()); + const packages = turbo.planPackages(this.task).map((name) => { + if (this.scope) { + return name; + } + return name.replace(/^@[^/]+\//, ''); + }); + this.context.stdout.write(`${JSON.stringify(packages, null, 2)}`); + this.context.stdout.write('\n'); + } +} diff --git a/packages/turbo/src/cli.ts b/packages/turbo/src/cli.ts new file mode 100644 index 0000000..af42132 --- /dev/null +++ b/packages/turbo/src/cli.ts @@ -0,0 +1,6 @@ +import { runExit } from 'clipanion'; + +import { TurboPlanCommand } from './TurboPlanCommand'; + +// noinspection JSIgnoredPromiseFromCall +void runExit([TurboPlanCommand]); diff --git a/packages/turbo/turbo.json b/packages/turbo/turbo.json new file mode 100644 index 0000000..60825e3 --- /dev/null +++ b/packages/turbo/turbo.json @@ -0,0 +1,4 @@ +{ + "extends": ["//"], + "pipeline": {} +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 542c276..badad60 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -128,6 +128,10 @@ importers: version: 2.6.11 packages/turbo: + dependencies: + clipanion: + specifier: 3.2.1 + version: 3.2.1(typanion@3.9.0) devDependencies: '@stickyjs/jest': specifier: workspace:* @@ -1822,7 +1826,6 @@ packages: typanion: '*' dependencies: typanion: 3.9.0 - dev: true /cliui@7.0.4: resolution: {integrity: sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==} @@ -5832,7 +5835,6 @@ packages: /typanion@3.9.0: resolution: {integrity: sha512-7yPk67IIquhKQcUXOBM27vDuGmZf6oJbEmzgVfDniHCkT6+z4JnKY85nKqbstoec8Kp7hD06TP3Kc98ij43PIg==} - dev: true /type-check@0.4.0: resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==}