Skip to content

Commit

Permalink
Updated automated release to support manual trigger (#1212)
Browse files Browse the repository at this point in the history
Updating the release process to avoid depending on the context of the
current PR, but instead rely on the branch based on the version found in
the `.version` file, restoring behavior like we had when we published
through Circle CI.

- Add a `.version` file and configure Ship CLI to automatically bump the
version
- Update `get-version` to read from the `.version` file instead of the
branch name.
- Add an action to get the release notes instead of relying on the
current PR associated with the workflow trigger.
- No longer create a tag manually, but rely on
`softprops/action-gh-release` to create the tag when we create the
GitHub release.

Note: Because the release-notes are multiline, I was unable to use
GITHUB_OUTPUT, but had to resort to GITHUB_ENV instead, exposing the
release notes as an environment variable.
  • Loading branch information
frederikprijck authored Dec 11, 2023
1 parent f073914 commit 0dda1ab
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 48 deletions.
38 changes: 38 additions & 0 deletions .github/actions/get-release-notes/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Return the release notes extracted from the PR body

#
# Returns the release notes from the content of a pull request linked to a release branch. It expects the branch name to be in the format release/vX.Y.Z, release/X.Y.Z, release/vX.Y.Z-beta.N. etc.
#
# TODO: Remove once the common repo is public.
#
inputs:
version :
required: true
repo_name:
required: false
repo_owner:
required: true
token:
required: true

runs:
using: composite

steps:
- uses: actions/github-script@v7
id: get_release_notes
with:
result-encoding: string
script: |
const { data: pulls } = await github.rest.pulls.list({
owner: process.env.REPO_OWNER,
repo: process.env.REPO_NAME,
state: 'all',
head: `${process.env.REPO_OWNER}:release/${process.env.VERSION}`,
});
core.exportVariable('RELEASE_NOTES', pulls[0].body)
env:
GITHUB_TOKEN: ${{ inputs.token }}
REPO_OWNER: ${{ inputs.repo_owner }}
REPO_NAME: ${{ inputs.repo_name }}
VERSION: ${{ inputs.version }}
6 changes: 2 additions & 4 deletions .github/actions/get-version/action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Return the version extracted from the branch name

#
# Returns the version from a branch name of a pull request. It expects the branch name to be in the format release/vX.Y.Z, release/X.Y.Z, release/vX.Y.Z-beta.N. etc.
# Returns the version from the .version file.
#
# TODO: Remove once the common repo is public.
#
Expand All @@ -17,7 +17,5 @@ runs:
- id: get_version
shell: bash
run: |
VERSION=$(echo ${BRANCH_NAME} | sed -r 's#release/+##g')
VERSION=$(head -1 .version)
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
env:
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
33 changes: 0 additions & 33 deletions .github/actions/tag-create/action.yml

This file was deleted.

21 changes: 13 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
types:
- closed
workflow_dispatch:

permissions:
contents: write
Expand All @@ -16,7 +17,7 @@ env:

jobs:
release:
if: github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/')
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
environment: release

Expand All @@ -35,6 +36,16 @@ jobs:
uses: ./.github/actions/get-prerelease
with:
version: ${{ steps.get_version.outputs.version }}

# Get the release notes
# This will expose the release notes as env.RELEASE_NOTES
- id: get_release_notes
uses: ./.github/actions/get-release-notes
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ steps.get_version.outputs.version }}
repo_owner: ${{ github.repository_owner }}
repo_name: ${{ github.event.repository.name }}

# Check if the tag already exists
- id: tag_exists
Expand All @@ -53,18 +64,12 @@ jobs:
node-version: ${{ env.NODE_VERSION }}
npm-token: ${{ secrets.NPM_TOKEN }}

# Create a tag for the release
- uses: ./.github/actions/tag-create
with:
tag: ${{ steps.get_version.outputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}

# Create a release for the tag
- uses: ./.github/actions/release-create
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ steps.get_version.outputs.version }}
body: ${{ github.event.pull_request.body }}
body: ${{ env.RELEASE_NOTES }}
tag: ${{ steps.get_version.outputs.version }}
commit: ${{ github.sha }}
prerelease: ${{ steps.get_prerelease.outputs.prerelease }}
11 changes: 8 additions & 3 deletions .shiprc
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"files": {
"src/version.ts": [],
"README.md": ["{MAJOR}.{MINOR}"],
"FAQ.md": ["{MAJOR}.{MINOR}.{PATCH}"]
".version": [],
"README.md": [
"{MAJOR}.{MINOR}"
],
"FAQ.md": [
"{MAJOR}.{MINOR}.{PATCH}"
]
},
"postbump": "npm run docs"
}
}
1 change: 1 addition & 0 deletions .version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v2.1.2

0 comments on commit 0dda1ab

Please sign in to comment.