-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from planningcenter/km/rc-deploy
feat(Release Candidate): Add action to build release candidate releases
- Loading branch information
Showing
3 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 @@ | ||
# Create Release Candidate Github Action | ||
|
||
## Summary | ||
|
||
This action helps to automate the process of creating a pre-release build of a release PR. It works | ||
best when setting up a listener on a comment of a PR like `@pco-release rc`. | ||
|
||
## Usage | ||
|
||
Add a workflow file to listen on a `@pco-release rc` comment. | ||
|
||
```yml | ||
name: Create RC Prerelease | ||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
auto-deploy-after-release: | ||
if: github.event.issue.pull_request && contains(github.event.comment.body, '@pco-release rc') | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- uses: planningcenter/pco-release-action/create-release-candidate@v1 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
############################## | ||
# the following are optional # | ||
############################## | ||
# node-version: 20 | ||
# package-json-path: 'package.json' | ||
# yarn-version-command: 'yarn version' | ||
``` | ||
|
||
Then in Release PRs, you can comment with something like this: | ||
|
||
``` | ||
@pco-release rc | ||
This Release Candidate is testing out the Widget feature. | ||
It is important to test: | ||
- Thing A | ||
- Thing B | ||
``` | ||
|
||
This comment will add all the extra text in the comment to the release information. |
This file contains 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,96 @@ | ||
name: "PCO Release RC release" | ||
inputs: | ||
GITHUB_TOKEN: | ||
description: token for access | ||
required: true | ||
package-json-path: | ||
description: "path to package.json" | ||
required: false | ||
default: "package.json" | ||
yarn-version-command: | ||
description: "command to run to update version" | ||
required: false | ||
default: "yarn version" | ||
node-version: | ||
description: "node version to use" | ||
required: false | ||
default: "20" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Get PR head ref | ||
id: get-pr-ref | ||
uses: actions/github-script@v5 | ||
with: | ||
script: | | ||
const issueUrl = context.payload.issue.pull_request.url; | ||
const prNumber = issueUrl.split('/').pop(); | ||
const pr = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: prNumber, | ||
}); | ||
return pr.data.head.ref; | ||
result-encoding: string | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ steps.get-pr-ref.outputs.result }} | ||
fetch-tags: true | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ inputs.node-version}} | ||
- run: git checkout -b rc | ||
shell: bash | ||
- name: Set Git user | ||
shell: bash | ||
run: | | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git config --global user.name "github-actions[bot]" | ||
- name: Find new version | ||
id: version_step | ||
shell: bash | ||
run: | | ||
git fetch origin 'refs/tags/*:refs/tags/*' | ||
current_version=$(jq -r .version ${{ inputs.package-json-path }}) | ||
i=0 | ||
while [ "$finished" != "true" ] | ||
do | ||
new_version=${current_version}-rc.$i | ||
if [ $(git tag -l | grep -w "v$new_version") ]; then | ||
echo "Version $new_version already exists, trying again" | ||
i=$((i+1)) | ||
else | ||
echo "Version $new_version is new, continuing" | ||
finished="true" | ||
fi | ||
done | ||
${{ inputs.yarn-version-command }} --new-version $new_version --no-git-tag-version | ||
echo "new_version=$new_version" >> $GITHUB_ENV | ||
- name: Commit changes | ||
shell: bash | ||
run: | | ||
git add . | ||
git commit -m "Release candidate v${{ env.new_version }}" | ||
git tag v${{ env.new_version }} | ||
- name: Push changes | ||
shell: bash | ||
run: | | ||
git push --force origin rc | ||
git push --tags | ||
- name: Set Release notes | ||
id: set_release_notes | ||
shell: bash | ||
run: | | ||
touch release_notes.md | ||
MODIFIED_COMMENT="${{ github.event.comment.body }}" | ||
MODIFIED_COMMENT="${MODIFIED_COMMENT//@pco-release rc/}" | ||
echo "$MODIFIED_COMMENT" > release_notes.md | ||
- name: Create Release | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
prerelease: true | ||
tag: v${{ env.new_version }} | ||
commit: rc | ||
generateReleaseNotes: true | ||
bodyFile: release_notes.md |