-
-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add reusable release workflow #237
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
Open
Eomm
wants to merge
5
commits into
main
Choose a base branch
from
feat/reusable-release
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
663f056
feat: add reusable release workflow
Eomm 2ce8205
feat: gate the release behind a deployment environment
Eomm 7d11b7f
fix: rename reusable workflow and address CodeQL injection alert
github-actions[bot] 282ecd8
Potential fix for pull request finding 'CodeQL / Environment variable…
Eomm 6d55d94
Merge branch 'main' into feat/reusable-release
Tony133 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,89 @@ | ||
| name: release | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| semver: | ||
| description: 'Release bump type: patch, minor or major.' | ||
| required: true | ||
| type: string | ||
| node-version: | ||
| description: 'The Node.js version used to build and publish the package.' | ||
| required: false | ||
| default: 'lts/*' | ||
| type: string | ||
| runs-on: | ||
| description: 'The runner used to publish the package.' | ||
| required: false | ||
| default: 'ubuntu-latest' | ||
| type: string | ||
| environment: | ||
| description: 'The deployment environment that gates the release. Configure it with the required reviewers that are allowed to release.' | ||
| required: false | ||
| default: 'release' | ||
| type: string | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| release: | ||
| name: Release | ||
| runs-on: ${{ inputs.runs-on }} | ||
| environment: ${{ inputs.environment }} | ||
| permissions: | ||
| id-token: write # required for npm provenance via OIDC | ||
| contents: write # required to push the release commit and the tag | ||
| env: | ||
| BUMP_TYPE: ${{ inputs.semver }} | ||
| steps: | ||
| - name: Validate the semver input | ||
| run: | | ||
| case "$BUMP_TYPE" in | ||
| patch|minor|major) ;; | ||
| *) echo "::error::Invalid semver input '$BUMP_TYPE': expected patch, minor or major." && exit 1 ;; | ||
| esac | ||
|
|
||
| - name: Check out repo | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: true # explicit: the release commit and tag are pushed below | ||
|
|
||
| - name: Setup Node ${{ inputs.node-version }} | ||
| uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | ||
| with: | ||
| check-latest: true | ||
| node-version: ${{ inputs.node-version }} | ||
| registry-url: 'https://registry.npmjs.org' | ||
| package-manager-cache: false # never use caching in release builds | ||
|
|
||
| - name: Bump package version | ||
| run: | | ||
| git config --global user.name "github-actions[bot]" | ||
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
| NEW_VERSION=$(npm version "$(printf '%s' "$BUMP_TYPE")" --no-git-tag-version) | ||
| git add -u # stages package.json and the lockfile, whichever the repo tracks | ||
| git commit -m "Bumped v$(printf '%s' "${NEW_VERSION#v}")" | ||
| SAFE_NEW_VERSION=$(printf '%s' "${NEW_VERSION#v}" | tr -d '\r\n') | ||
| printf 'NEW_VERSION=%s\n' "$SAFE_NEW_VERSION" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install --ignore-scripts --no-audit --no-fund | ||
|
|
||
| - name: Build the release artifacts | ||
| run: npm run --if-present release:build | ||
|
|
||
| - name: Publish to npm | ||
| run: npm publish --provenance --access public | ||
|
|
||
| - name: Push release commit | ||
| run: git push origin HEAD | ||
|
|
||
| - name: Create GitHub release | ||
| uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v3.0.3 | ||
| with: | ||
| tag_name: v${{ env.NEW_VERSION }} | ||
| target_commitish: ${{ github.ref_name }} | ||
| name: v${{ env.NEW_VERSION }} | ||
| generate_release_notes: true # "What's Changed" from merged PRs + contributors + Full Changelog link | ||
| make_latest: true | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the first point is still open:
npm publishstill runs beforegit push origin HEAD. In repositories wheremainis protected against direct pushes viaGITHUB_TOKEN, the push would fail after the version is already on npm, leaving no commit or tag in the repo and making any retry fail.Could we move the "Push release commit" step before "Publish to npm"? If the push fails, nothing gets published. It would also be worth adding a note to the README about allowing GitHub Actions to bypass branch protection (e.g. via a ruleset).