Skip to content

Commit

Permalink
Merge pull request #2 from planningcenter/km/rc-deploy
Browse files Browse the repository at this point in the history
feat(Release Candidate): Add action to build release candidate releases
  • Loading branch information
kylemellander authored Aug 27, 2024
2 parents 9eea916 + 1b1dd98 commit 97efd2d
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ jobs:
- uses: planningcenter/pco-release-action/dependabot-automation@v1
```
#### Automate the creation of Release candidate releases
See [create-prerelease-candidate](./create-release-candidate/README.md)
#### Automate the creation of QA releases
See [create-qa-release](./create-qa-release/README.md)
Expand Down
50 changes: 50 additions & 0 deletions create-release-candidate/README.md
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.
96 changes: 96 additions & 0 deletions create-release-candidate/action.yml
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

0 comments on commit 97efd2d

Please sign in to comment.