Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
feat(turbo): add sticky-turbo plan support (#190)
Browse files Browse the repository at this point in the history
<!--  Thanks for sending a pull request! -->

#### What this PR does / why we need it:

Introduce new `sticky-turbo plan task` to allow planning of tasks before
running them. Built to parallelize CI pipelines for faster PR review
intervals.

1. **Test [plan]**: `pnpm sticky-turbo plan test` >> packages.json
2. **Test [$p]**: `for p packages.json`
   1. `pnpm turbo run test --filter=p --concurency=2`
3. **Test [completed]**: for "Branch Protection: Require status checks
to pass before merging"
  • Loading branch information
fuxingloh committed Jun 26, 2023
1 parent 9fa7a7d commit 3998d78
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 16 deletions.
62 changes: 52 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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<<EOF' >> $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

Expand All @@ -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
5 changes: 3 additions & 2 deletions .github/workflows/oss-governance-bot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: OSS Governance
name: OSS

on:
pull_request_target:
Expand All @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/oss-governance-labeler.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: OSS Governance
name: OSS

on:
pull_request_target:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/oss-governance-labels.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: OSS Governance
name: OSS

on:
push:
Expand Down
58 changes: 58 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/turbo/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /usr/bin/env node
/* eslint-disable */
require('./dist/cli.js');
6 changes: 6 additions & 0 deletions packages/turbo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"main": "./dist/index.js",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"bin": {
"sticky-turbo": "./cli.js"
},
"files": [
"dist/**"
],
Expand Down Expand Up @@ -36,6 +39,9 @@
"jest": {
"preset": "@stickyjs/jest"
},
"dependencies": {
"clipanion": "3.2.1"
},
"devDependencies": {
"@stickyjs/jest": "workspace:*",
"turbo": "1.10.6"
Expand Down
30 changes: 30 additions & 0 deletions packages/turbo/src/TurboPlanCommand.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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');
}
}
6 changes: 6 additions & 0 deletions packages/turbo/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { runExit } from 'clipanion';

import { TurboPlanCommand } from './TurboPlanCommand';

// noinspection JSIgnoredPromiseFromCall
void runExit([TurboPlanCommand]);
4 changes: 4 additions & 0 deletions packages/turbo/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["//"],
"pipeline": {}
}
6 changes: 4 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3998d78

Please sign in to comment.