-
Notifications
You must be signed in to change notification settings - Fork 23
fix: use OIDC trusted publishing instead of npm token for releases #1031
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
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,110 @@ | ||
| name: Package Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| env: | ||
| GH_PACKAGES_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }} | ||
|
|
||
| permissions: | ||
| # Enable the use of OIDC for trusted publishing and npm provenance | ||
| id-token: write | ||
| # Enable the use of GitHub Packages registry | ||
| packages: write | ||
| # Enable `semantic-release` to publish a GitHub release and push commits | ||
| contents: write | ||
| # Enable `semantic-release` to post comments on issues | ||
| issues: write | ||
| # Enable `semantic-release` to post comments on pull requests | ||
| pull-requests: write | ||
|
|
||
| # The release workflow involves many crucial steps that once triggered shouldn't be cancelled until | ||
| # finished, otherwise we might end up in an inconsistent state (e.g., published to GitHub Packages | ||
| # but not npm), so new workflow runs are queued until the previous one has completely finished. | ||
| concurrency: | ||
| group: ${{ github.workflow }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| release-and-publish: | ||
| name: Release & Publish | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
|
|
||
| steps: | ||
| - name: Generate release bot token | ||
| id: release-bot | ||
| uses: actions/create-github-app-token@v3 | ||
| with: | ||
| app-id: ${{ secrets.DOIST_RELEASE_BOT_ID }} | ||
| private-key: ${{ secrets.DOIST_RELEASE_BOT_PRIVATE_KEY }} | ||
| permission-contents: write | ||
| permission-issues: write | ||
| permission-pull-requests: write | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| token: ${{ steps.release-bot.outputs.token }} | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Prepare Node.js environment | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| cache: npm | ||
| node-version-file: .node-version | ||
|
|
||
| - name: Cache project 'node_modules' directory | ||
| id: node-modules-cache | ||
| uses: actions/cache@v5 | ||
| with: | ||
| key: node-modules-cache-${{ hashFiles('**/package-lock.json', '**/.node-version', 'patches/**') }} | ||
| path: node_modules/ | ||
|
|
||
| - name: Install project npm dependencies | ||
| if: ${{ steps.node-modules-cache.outputs.cache-hit != 'true' }} | ||
| run: | | ||
| npm ci | ||
|
|
||
| - name: Build package | ||
| run: | | ||
| npm run build | ||
|
|
||
| # The Node.js environment is prepared based on the `.npmrc` file in the repo, which | ||
| # configures Doist scoped packages to use the public npm registry with OIDC | ||
| # authentication for the initial `semantic-release` publish, after which we remove the | ||
| # Doist registry configuration, and prepare the Node.js environment for the GitHub | ||
| # Packages registry, providing a predictable release workflow for both registries. | ||
| - name: Publish package to public npm registry | ||
| id: semantic-release | ||
| run: | | ||
| npx semantic-release | ||
| env: | ||
| GITHUB_TOKEN: ${{ steps.release-bot.outputs.token }} | ||
| GIT_AUTHOR_EMAIL: doistbot@users.noreply.github.com | ||
| GIT_AUTHOR_NAME: Doist Bot | ||
| GIT_COMMITTER_EMAIL: doistbot@users.noreply.github.com | ||
| GIT_COMMITTER_NAME: Doist Bot | ||
|
|
||
| - name: Remove Doist registry configuration from `.npmrc` | ||
| if: ${{ steps.semantic-release.outputs.package-published == 'true' }} | ||
| run: | | ||
| npm config delete @doist:registry --location=project | ||
|
|
||
| - name: Prepare Node.js environment for GitHub Packages registry | ||
| if: ${{ steps.semantic-release.outputs.package-published == 'true' }} | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| cache: npm | ||
| node-version-file: .node-version | ||
| registry-url: https://npm.pkg.github.com/ | ||
| scope: '@doist' | ||
|
|
||
| - name: Publish package to private GitHub Packages registry | ||
| if: ${{ steps.semantic-release.outputs.package-published == 'true' }} | ||
| run: | | ||
| npm publish | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }} | ||
This file was deleted.
Oops, something went wrong.
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
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.