From f7a2bdf7a8aa51d811850d9641d7db387e63972c Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Fri, 30 Dec 2022 13:49:00 +0800 Subject: [PATCH] ci: separate release groups (#2775) --- .github/workflows/changesets.yml | 16 +++++----- .scripts/version.js | 41 +++++++++++++++++++++++++ packages/integration-tests/package.json | 2 +- pnpm-lock.yaml | 2 +- 4 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 .scripts/version.js diff --git a/.github/workflows/changesets.yml b/.github/workflows/changesets.yml index 369d52c1f..97f62648a 100644 --- a/.github/workflows/changesets.yml +++ b/.github/workflows/changesets.yml @@ -11,14 +11,16 @@ concurrency: jobs: changesets: + strategy: + matrix: + group: [core, toolkit] + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: - # Set Git operations with the bot PAT since we have tag protection rule token: ${{ secrets.BOT_PAT }} - fetch-depth: 0 - name: Setup Node and pnpm uses: silverhand-io/actions-node-pnpm-run-steps@v2 @@ -39,7 +41,7 @@ jobs: - name: Version packages run: | - pnpm changeset version + node .scripts/version.js ${{ matrix.group }} pnpm i --no-frozen-lockfile git status @@ -48,10 +50,10 @@ jobs: uses: peter-evans/create-pull-request@v4 with: token: ${{ secrets.BOT_PAT }} - commit-message: 'release: version packages' + commit-message: 'release: version ${{ matrix.group }} packages' committer: silverhand-bot author: silverhand-bot base: master - branch: release/version-packages - title: 'release: version packages' - body: 'This is an automatic pull request from the result of `pnpm changeset version` command. Merge it will trigger the publish flow for versioned packages.' + branch: release/version-${{ matrix.group }}-packages + title: 'release: version ${{ matrix.group }} packages' + body: 'This is an automatic pull request from the result of `node .scripts/version.js ${{ matrix.group }}` command. Merge it will trigger the publish flow for versioned packages.' diff --git a/.scripts/version.js b/.scripts/version.js new file mode 100644 index 000000000..6a22b0418 --- /dev/null +++ b/.scripts/version.js @@ -0,0 +1,41 @@ +import { exec } from 'node:child_process'; +import { promisify } from 'node:util'; + +const execAsync = promisify(exec); +const versionGroup = process.argv[2]; + +if (process.argv.length > 3) { + throw new Error('Extraneous arguments found. Only one optional argument for version group name is allowed.'); +} + +// This is configured based on our practice. Change with care. +const allowedGroups = { core: 'core', toolkit: 'toolkit' }; +if (!Object.values(allowedGroups).includes(versionGroup)) { + throw new Error('Version group is invalid. Should be one of ' + Object.values(allowedGroups).join(', ') + '.'); +} + +const { allPackages } = await import('./packages-meta.js'); + +const getIgnoreGroup = () => { + console.log(`=== Versioning ${versionGroup} group packages ===`); + + return allPackages.filter(({ path }) => { + if (versionGroup === allowedGroups.toolkit) { + return !path.includes(allowedGroups.toolkit + '/'); + } + + return false; + }); +} + +const ignoreCmd = getIgnoreGroup() + .map(({ name }) => ` \\\n --ignore ${name}`) + .join(''); +const cmd = ('pnpm changeset version' + ignoreCmd); + +console.log(cmd); + +await execAsync(cmd).catch(({ stderr, code }) => { + console.error(stderr); + process.exit(code ?? 1); +}); diff --git a/packages/integration-tests/package.json b/packages/integration-tests/package.json index 505a010a8..ff86ff85b 100644 --- a/packages/integration-tests/package.json +++ b/packages/integration-tests/package.json @@ -21,7 +21,7 @@ }, "devDependencies": { "@jest/types": "^29.1.2", - "@logto/connector-kit": "workspace:1.0.0-beta.30", + "@logto/connector-kit": "workspace:*", "@logto/js": "1.0.0-beta.14", "@logto/node": "1.0.0-beta.14", "@logto/schemas": "workspace:*", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e8775498c..51704dbbc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -462,7 +462,7 @@ importers: packages/integration-tests: specifiers: '@jest/types': ^29.1.2 - '@logto/connector-kit': workspace:1.0.0-beta.30 + '@logto/connector-kit': workspace:* '@logto/js': 1.0.0-beta.14 '@logto/node': 1.0.0-beta.14 '@logto/schemas': workspace:*