-
Notifications
You must be signed in to change notification settings - Fork 23
Release workflow #544
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
paul-sachs
wants to merge
16
commits into
main
Choose a base branch
from
psachs/add-release-workflow
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.
Open
Release workflow #544
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
727f29b
A release workflow github action
paul-sachs ee2c908
Format
paul-sachs bc3644d
Add some cleanup and fix potential edge cases
paul-sachs 5600868
Add support for alternative base ref
paul-sachs da0dc69
Format again
paul-sachs e608382
Review updates
paul-sachs 4953690
Naming files consistently
paul-sachs 7ec7e09
Use npm trusted publishing
paul-sachs fda61ca
Move permissions to single location
paul-sachs f743b8e
Fixed a minor bug on cleanup and validated trusted publishing
paul-sachs 73177a9
Updated semver version check with official regex
paul-sachs 7446a78
Improved set version requirements
paul-sachs fbd6ac5
Revert file rename
paul-sachs 1c2cb27
Update setup-node action
paul-sachs 0cc3e60
Review comments addressed
paul-sachs 32b8f39
Fix lint and add some explanation of base_branch to release.md
paul-sachs 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
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,91 @@ | ||
| name: Prepare Release | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: "Version to release (e.g. 1.2.3)" | ||
| required: true | ||
| type: string | ||
| base_branch: | ||
| description: | | ||
| Base branch for release (release/v1.x, or main). Specifying | ||
| a base branch other than main will require that release branch to | ||
| exist. Select something like release/v1.x to create a release | ||
| for a hotfix of a major version that is behind the current main | ||
| branch. | ||
| required: false | ||
| default: "main" | ||
| type: string | ||
|
|
||
| jobs: | ||
| prepare-release: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ inputs.base_branch }} | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version-file: ".nvmrc" | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Create release branch | ||
| run: | | ||
| git config --global user.name 'github-actions[bot]' | ||
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | ||
| git checkout -b "release/prep-release-${{ inputs.version }}" | ||
|
|
||
| - name: Get current workspace version | ||
| id: workspace_version | ||
| run: | | ||
| VERSION=$(npm run getversion --silent) | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Set version and run build | ||
| run: | | ||
| npm run setversion ${{ inputs.version }} | ||
|
|
||
| - name: Commit version changes | ||
| run: | | ||
| git add . | ||
| git commit -s -m "Release ${{ inputs.version }}" | ||
| git push --set-upstream origin "release/prep-release-${{ inputs.version }}" | ||
|
|
||
| - name: Get release notes | ||
| id: release_notes | ||
| run: | | ||
| RELEASE_NOTES=$( | ||
| gh api \ | ||
| --method POST \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| /repos/${{ github.repository }}/releases/generate-notes \ | ||
| -f 'tag_name=v${{ inputs.version }}' -f 'target_commitish=${{ inputs.base_branch }}' -f 'previous_tag_name=v${{ steps.workspace_version.outputs.version }}' \ | ||
| --jq ".body" \ | ||
| ) | ||
| echo "notes<<EOF" >> $GITHUB_OUTPUT | ||
| echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT | ||
| echo "EOF" >> $GITHUB_OUTPUT | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Create pull request | ||
| run: | | ||
| gh pr create \ | ||
| --title "Release ${{ inputs.version }}" \ | ||
| --body "${{ steps.release_notes.outputs.notes }}" \ | ||
| --base "${{ inputs.base_branch }}" | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
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,63 @@ | ||
| name: Publish Release | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| branches: | ||
| - main | ||
| - "release/**" | ||
|
|
||
| jobs: | ||
| publish-release: | ||
| runs-on: ubuntu-latest | ||
| # Only run if PR was merged and branch name starts with release/prep-release- | ||
| if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/prep-release-') | ||
| permissions: | ||
| id-token: write # Required for OIDC | ||
| contents: write | ||
| pull-requests: write | ||
| issues: write | ||
|
|
||
| steps: | ||
| - name: Checkout base branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event.pull_request.base.ref }} | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version-file: ".nvmrc" | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Get current workspace version | ||
| id: workspace_version | ||
| run: | | ||
| VERSION=$(npm run getversion --silent) | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Get updated release notes from PR | ||
| id: pr_notes | ||
| run: | | ||
| RELEASE_NOTES=$(gh pr view ${{ github.event.pull_request.number }} --json body | jq -r ".body") | ||
| echo "notes<<EOF" >> $GITHUB_OUTPUT | ||
| echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT | ||
| echo "EOF" >> $GITHUB_OUTPUT | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Publish to npm | ||
| run: npm run release | ||
|
|
||
| - name: Publish GitHub release | ||
| run: | | ||
| gh release create v${{ steps.workspace_version.outputs.version }} \ | ||
| --title "Release v${{ steps.workspace_version.outputs.version }}" \ | ||
| --notes "${{ steps.pr_notes.outputs.notes }}" | ||
| # --discussion-category "Announcements" ## Enable if discussions are enabled | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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 |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ | |
| "oneof", | ||
| "typesafe", | ||
| "setversion", | ||
| "getversion", | ||
| "postsetversion", | ||
| "postgenerate", | ||
| "npmjs" | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright 2021-2023 The Connect Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import { findWorkspaceVersion } from "./utils.js"; | ||
|
|
||
| process.stdout.write(`${findWorkspaceVersion("packages")}\n`); |
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
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,50 @@ | ||
| // Copyright 2021-2023 The Connect Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import { readdirSync, readFileSync, existsSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
|
|
||
| /** | ||
| * Retrieves the workspace version from the package directory. | ||
| * | ||
| * @param {string} packagesDir | ||
| * @returns {string} | ||
| */ | ||
| export function findWorkspaceVersion(packagesDir) { | ||
| let version = undefined; | ||
| for (const entry of readdirSync(packagesDir, { withFileTypes: true })) { | ||
| if (!entry.isDirectory()) { | ||
| continue; | ||
| } | ||
| const path = join(packagesDir, entry.name, "package.json"); | ||
| if (existsSync(path)) { | ||
| const pkg = JSON.parse(readFileSync(path, "utf-8")); | ||
| if (pkg.private === true) { | ||
| continue; | ||
| } | ||
| if (!pkg.version) { | ||
| throw new Error(`${path} is missing "version"`); | ||
| } | ||
| if (version === undefined) { | ||
| version = pkg.version; | ||
| } else if (version !== pkg.version) { | ||
| throw new Error(`${path} has unexpected version ${pkg.version}`); | ||
| } | ||
| } | ||
| } | ||
| if (version === undefined) { | ||
| throw new Error(`unable to find workspace version`); | ||
| } | ||
| return version; | ||
| } |
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.
Is this the reason to draft a release? Then I suggest that we create a draft, get the generated release notes, and delete the draft.
Can you add a comment that we should switch to an API call to generate release notes without creating a release? https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#generate-release-notes-content-for-a-release
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.
Updated script to use api directly, much easier to understand with less side effects 🚀