-
Notifications
You must be signed in to change notification settings - Fork 57.5k
ci: Ensure stable npm packages are tagged as latest after release #28755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9f6d205
ci: Add script to set "latest" version on monorepo packages
Matsuuu ec21c37
ci: Create workflow to set npm package latest to stable version
Matsuuu 52908f8
chore: Add NPM token to workflow and clean up script error output
Matsuuu 394e8ab
ci: Call release-set-stable in post-release
Matsuuu b320f54
ci: Don't set latest in publish step
Matsuuu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import child_process from 'child_process'; | ||
| import { promisify } from 'node:util'; | ||
|
|
||
| const exec = promisify(child_process.exec); | ||
|
|
||
| /** | ||
| * @typedef PnpmPackage | ||
| * @property { string } name | ||
| * @property { string } version | ||
| * @property { string } path | ||
| * @property { boolean } private | ||
| * */ | ||
|
|
||
| /** | ||
| * @returns { Promise<PnpmPackage[]> } | ||
| * */ | ||
| export async function getMonorepoProjects() { | ||
| return JSON.parse( | ||
| ( | ||
| await exec( | ||
| `pnpm ls -r --only-projects --json | jq -r '[.[] | { name: .name, version: .version, path: .path, private: .private}]'`, | ||
| ) | ||
| ).stdout, | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { trySh } from './github-helpers.mjs'; | ||
| import { getMonorepoProjects } from './pnpm-utils.mjs'; | ||
|
|
||
| async function setLatestForMonorepoPackages() { | ||
| const packages = await getMonorepoProjects(); | ||
|
|
||
| const publishedPackages = packages // | ||
| .filter((pkg) => !pkg.private) | ||
| .filter((pkg) => pkg.version); | ||
|
|
||
| for (const pkg of publishedPackages) { | ||
| const versionName = `${pkg.name}@${pkg.version}`; | ||
| const res = trySh('npm', ['dist-tag', 'add', versionName, 'latest']); | ||
| if (res.ok) { | ||
| console.log(`Set ${versionName} as latest`); | ||
| } else { | ||
| console.warn(`Update failed for ${versionName}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // only run when executed directly, not when imported by tests | ||
| if (import.meta.url === `file://${process.argv[1]}`) { | ||
| setLatestForMonorepoPackages().catch((err) => { | ||
| console.error(err); | ||
| process.exit(1); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
.github/workflows/release-set-stable-npm-packages-to-latest.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: 'Release: Set stable npm packages to latest' | ||
|
|
||
| on: | ||
| workflow_call: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| promote-github-releases: | ||
| name: Promote current stable releases as latest | ||
| runs-on: ubuntu-slim | ||
| environment: release | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| with: | ||
| ref: refs/tags/stable | ||
| fetch-depth: 1 | ||
|
|
||
| - name: Setup NodeJS | ||
| uses: ./.github/actions/setup-nodejs | ||
| with: | ||
| build-command: '' | ||
| install-command: pnpm install --frozen-lockfile --dir ./.github/scripts --ignore-workspace | ||
|
|
||
| # Remove after https://github.com/npm/cli/issues/8547 gets resolved | ||
| - run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc | ||
| env: | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
|
||
| - name: Set npm packages to latest | ||
| run: node ./.github/scripts/set-latest-for-monorepo-packages.mjs |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.