Skip to content
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

feat(.github/actions): add create-release-v1 action #104

Merged
merged 29 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b320da2
feat(.github/actions): add `create-release-v1` action
Zidious Dec 5, 2023
24b815f
composite action to fetch all git history
Zidious Dec 5, 2023
8b97948
remove var spacing
Zidious Dec 5, 2023
7b150ac
try to get env vars added
Zidious Dec 5, 2023
416c1d6
try to get env vars added
Zidious Dec 5, 2023
f47bfba
add PR body formatting and package/lerna version
Zidious Dec 6, 2023
b667d4b
account for not setting the env
Zidious Dec 6, 2023
865bbda
add release notes
Zidious Dec 6, 2023
00586fd
add comment to PR body about pasting CHANGELOG if required
Zidious Dec 6, 2023
6cc7865
use github.token no need to add it as input
Zidious Dec 6, 2023
aa9d34c
add default token value
Zidious Dec 6, 2023
95199f1
add default token value
Zidious Dec 6, 2023
2e1a366
remove checkout, we should run action from release
Zidious Dec 6, 2023
3d78459
more clean up and add message about redacted env values
Zidious Dec 7, 2023
6d53670
structure workflow
Zidious Dec 7, 2023
40731ca
add README
Zidious Dec 7, 2023
a9b8b76
add footer about PR was created by a robot
Zidious Dec 7, 2023
7e17145
borrow and amend `git show`command to pull new changes
Zidious Dec 7, 2023
0345a23
format changelog PR body
Zidious Dec 7, 2023
3379b4d
pretty-fy PR body output
Zidious Dec 7, 2023
b623144
Merge branch 'main' of https://github.com/dequelabs/axe-api-team-publ…
Zidious Dec 20, 2023
c729ef6
replace get-env shell with ts action
Zidious Dec 20, 2023
5066313
clean up new env var displaying
Zidious Dec 20, 2023
7a3b6f1
clean up new env var displaying
Zidious Dec 20, 2023
0f90f48
clean up new env var displaying
Zidious Dec 20, 2023
d865195
clean up new env var displaying
Zidious Dec 20, 2023
c6b17b5
clean up new env var displaying
Zidious Dec 20, 2023
7127aac
remove useless file
Zidious Dec 20, 2023
b9e1890
apply verbage feedback from Steve
Zidious Jan 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/actions/create-release-v1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# create-release-v1

A GitHub Action to create a release.

## Inputs

| Name | Required | Description | Default |
| ---------------- | -------- | ----------------------------------------------------------------------------- | -------------- |
| `base` | Yes | The base branch to merge the release into | NA |
| `token` | No | The GitHub token to use | `github.token` |
| `migrations-dir` | No | The directory containing the database migrations e.g. src/database/migrations | NA |
| `env-file-path` | No | The path to the `.env` file e.g. src/service/sample.env | NA |

## Example usage

```yaml
name: create release

on: workflow_dispatch

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- uses: dequelabs/axe-api-team-public/.github/actions/create-release-v1@main
with:
base: 'main'
```
132 changes: 132 additions & 0 deletions .github/actions/create-release-v1/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Create release
description: A GitHub Action to create a production release

inputs:
token:
description: The GitHub token to use. Defaults to GITHUB_TOKEN
default: ${{ github.token }}
base:
description: The base branch to merge into
required: true
migrations-dir:
description: The directory containing the database migrations e.g. src/database/migrations
env-file-path:
description: The path to the `.env` file e.g. src/service/sample.env

runs:
using: 'composite'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Fetch all history
fetch-depth: 0
Zidious marked this conversation as resolved.
Show resolved Hide resolved

- name: Is release in progress
uses: dequelabs/axe-api-team-public/.github/actions/is-release-in-progress-v1@main
id: is_release_in_progress
with:
github-token: ${{ inputs.token }}

- name: Cancel release if a release is already in progress
shell: bash
if: ${{ steps.is_release_in_progress.outputs.in_progress == 'true' }}
run: |
echo "A release is already in progress. Cancelling this release."
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}

- name: Get release version
id: get_release_version
shell: bash
run: |
git checkout release

Zidious marked this conversation as resolved.
Show resolved Hide resolved
# Get the version number from the prepare_release shell script and set it as an output
Zidious marked this conversation as resolved.
Show resolved Hide resolved
# Monorepos have a lerna.json file that contains the updated version number
# Non-monorepos, or non-npm repos, have a package.json file that contains the updated version number
if [ -f "lerna.json" ]; then
echo "RELEASE_VERSION=$(cat lerna.json | jq -r '.version')" >> $GITHUB_OUTPUT
else
echo "RELEASE_VERSION=$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT
fi

- name: Get CHANGELOG changes
shell: bash
run: |
echo "## Changelog Additions:" >> /tmp/release-notes.txt
echo "" >> /tmp/release-notes.txt

new_changelog_entries=$(git show origin/${{ inputs.base }}...origin/release --no-color --no-prefix --output-indicator-new=! CHANGELOG.md | egrep '^!' | awk -F'^[!]' '{print $2}' | sed -e 's/\n/$0A/g')

echo "$new_changelog_entries" >> /tmp/release-notes.txt
echo "" >> /tmp/release-notes.txt

- name: Find new migration files
Zidious marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
run: |
if [ -z "${{ inputs.migrations-dir }}" ]; then
echo "No migrations directory provided. Skipping migrations check"
else
repo_url="https://github.com/$GITHUB_REPOSITORY"

echo "Checking for new migration files in ${{ inputs.migrations-dir }}"
echo "Repo url: $repo_url"

# Only get new files added to release branch that are within the provided migrations directory and end in .sql

new_migration_files=$(git diff --name-only --diff-filter=A origin/${{ inputs.base }}...origin/release -- "${{ inputs.migrations-dir }}" | grep -E '\.sql$')

if [ -z "$new_migration_files" ]; then
echo "## No new migration files found" >> /tmp/release-notes.txt
else
echo "## New migration files found:" >> /tmp/release-notes.txt

for file in $new_migration_files; do
# Create permalink to file
url="$repo_url/blob/$GITHUB_SHA/$file"

echo "- [$file]($url)" >> /tmp/release-notes.txt
done

echo "" >> /tmp/release-notes.txt
fi
fi

- name: Find new env variables
if: ${{ inputs.env-file-path != '' }}
uses: dequelabs/axe-api-team-public/.github/actions/get-new-env-vars-v1@main
id: get_new_env_vars
with:
env-file-path: ${{ inputs.env-file-path }}
base: ${{ inputs.base }}
head: release

- name: Add new env vars to release notes
if: ${{ steps.get_new_env_vars.outputs.new-env-vars != '' }}
shell: bash
run: |
echo "## New environment variables:" >> /tmp/release-notes.txt
echo "" >> /tmp/release-notes.txt

new_vars=$(echo "${{ steps.get_new_env_vars.outputs.new-env-vars }}" | tr ',' '\n')

for var in $new_vars; do
echo "- $var" >> /tmp/release-notes.txt
done

echo "" >> /tmp/release-notes.txt

- name: Create release pull request
shell: bash
run: |
echo "_This PR was automatically created by a :robot:_" >> /tmp/release-notes.txt

gh pr create \
--title "chore: release v${{ steps.get_release_version.outputs.RELEASE_VERSION }}" \
--body-file /tmp/release-notes.txt \
--base ${{ inputs.base }} \
--head release
env:
# Required for GH CLI
GH_TOKEN: ${{ inputs.token }}