-
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
base: main
Are you sure you want to change the base?
Release workflow #544
Changes from 12 commits
727f29b
ee2c908
bc3644d
5600868
da0dc69
e608382
4953690
7ec7e09
fda61ca
f743b8e
73177a9
7446a78
fbd6ac5
1c2cb27
0cc3e60
32b8f39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| 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 (e.g. release/v1.x, hotfix/v1.2.x)" | ||
|
||
| 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@v4 | ||
| with: | ||
| node-version-file: ".nvmrc" | ||
| cache: "npm" | ||
paul-sachs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Create draft release | ||
| run: gh release create v${{ inputs.version }} --draft --generate-notes | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
paul-sachs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - 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: 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🚀 |
||
| id: release_notes | ||
| run: | | ||
| RELEASE_NOTES=$(gh release view v${{ inputs.version }} --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: 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 }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| name: Publish Release | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| branches: | ||
| - main | ||
| - "release/**" | ||
| - "hotfix/**" | ||
|
||
|
|
||
| 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: Extract version from branch name | ||
| id: extract_version | ||
| run: | | ||
| BRANCH_NAME="${{ github.event.pull_request.head.ref }}" | ||
| VERSION=$(echo "$BRANCH_NAME" | sed 's/release\/prep-release-//') | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| - 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@v4 | ||
| with: | ||
| node-version-file: ".nvmrc" | ||
| cache: "npm" | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - 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 edit v${{ steps.extract_version.outputs.version }} \ | ||
| --notes "${{ steps.pr_notes.outputs.notes }}" \ | ||
| --draft=false | ||
paul-sachs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| cleanup-canceled-release: | ||
| runs-on: ubuntu-latest | ||
| # Only run if PR was closed without merge and branch name starts with release/prep-release- | ||
| if: github.event.pull_request.merged == false && startsWith(github.event.pull_request.head.ref, 'release/prep-release-') | ||
| permissions: | ||
| contents: write | ||
| pull-requests: 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: Extract version from branch name | ||
| id: extract_version | ||
| run: | | ||
| BRANCH_NAME="${{ github.event.pull_request.head.ref }}" | ||
| VERSION=$(echo "$BRANCH_NAME" | sed 's/release\/prep-release-//') | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
paul-sachs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - name: Delete draft release | ||
| run: | | ||
| if gh release view v${{ steps.extract_version.outputs.version }} --json isDraft | jq -r ".isDraft" | grep -q "true"; then | ||
| echo "Deleting draft release v${{ steps.extract_version.outputs.version }}" | ||
| gh release delete v${{ steps.extract_version.outputs.version }} --yes | ||
| else | ||
| echo "Release v${{ steps.extract_version.outputs.version }} is not a draft, skipping deletion" | ||
| fi | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
paul-sachs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - name: Delete release branch | ||
| continue-on-error: true | ||
| run: | | ||
| echo "Deleting release branch ${{ github.event.pull_request.head.ref }}" | ||
| git push origin --delete ${{ github.event.pull_request.head.ref }} | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
paul-sachs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.