Skip to content

Commit

Permalink
Read version from .version file and add get_release_notes
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck committed Dec 6, 2023
1 parent baa3c8f commit 7cb584b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 13 deletions.
51 changes: 51 additions & 0 deletions .github/actions/get-release-notes/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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


outputs:
release_notes:
value: ${{ steps.get_version.outputs.release_notes }}
release_notes2:
description: 'Release Notes'

runs:
using: composite

steps:
- id: get_release_notes
shell: bash
run: |
RELEASE_PR_BRANCH="release/$VERSION"
API_URL="https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/pulls"
RELEASE_NOTES=$(curl -G \
-H "Accept: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
--data-urlencode "state=all" \
--data-urlencode "head=$REPO_OWNER:$RELEASE_PR_BRANCH" \
"$API_URL" | jq -r ".[0].body"
)
{
echo 'RELEASE_NOTES<<EOF'
echo $RELEASE_NOTES
echo 'EOF'
} >> $GITHUB_ENV
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 }}
30 changes: 24 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
types:
- closed
push:
branches:
- feat/automated-release
workflow_dispatch:

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

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

Expand All @@ -25,6 +29,11 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- shell: bash
run: |
echo $EVENTNAME
env:
EVENTNAME: ${{ github.event_name }}

# Get the version from the branch name
- id: get_version
Expand All @@ -35,6 +44,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 @@ -43,28 +62,27 @@ jobs:
tag: ${{ steps.get_version.outputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}

# If the tag already exists, exit with an error
- if: steps.tag_exists.outputs.exists == 'true'
run: exit 1

# Publish the release to our package manager
- uses: ./.github/actions/publish-package
if: steps.tag_exists.outputs.exists == 'false'
with:
node-version: ${{ env.NODE_VERSION }}
npm-token: ${{ secrets.NPM_TOKEN }}

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

# Create a release for the tag
- uses: ./.github/actions/release-create
if: steps.tag_exists.outputs.exists == 'false'
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 7cb584b

Please sign in to comment.