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

ci: add support for patch releases and added branch whitelist checks #182

Merged
merged 12 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
46 changes: 43 additions & 3 deletions .github/workflows/create-release-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,36 @@ jobs:
name: Create Release PR
runs-on: ubuntu-latest
steps:
- name: Check if a branch is whitelisted and maintained
id: branch-check
run: |
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
WHITELISTED_BRANCHES=("main" "releases/*")

IS_WHITELISTED=false
# Check the branch against the whitelist using wildcard matching
for BRANCH in "${WHITELISTED_BRANCHES[@]}"; do
if [[ "$BRANCH_NAME" == $BRANCH ]]; then
IS_WHITELISTED=true;
break;
fi
done

if [ "$IS_WHITELISTED" == true ]; then
echo "Branch is whitelisted: $BRANCH_NAME"
else
echo "Branch $BRANCH_NAME is not whitelisted."
exit 1
fi

echo "branch_name=${BRANCH_NAME}" >> "$GITHUB_OUTPUT"

- name: Checkout Repo
uses: actions/checkout@v4
with:
persist-credentials: false
ref: ${{ steps.branch-check.outputs.branch_name }}
fetch-depth: 0 # Needed for comparison in `extract-package-versions` step.

- name: Check for changeset files
run: |
Expand All @@ -30,13 +56,27 @@ jobs:
with:
install-nodejs: 'true'

- name: Extract the old and new versions of the package
id: extract-package-versions
run: |
# https://github.com/changesets/changesets/issues/1055#issuecomment-1602572294
npm run cs -- status --output=release.json --since=origin/main

NEW_PACKAGE_VERSION=$(jq -r '.releases[0].newVersion' release.json)
OLD_PACKAGE_VERSION=$(jq -r '.releases[0].oldVersion' release.json)
rm release.json

echo "new_package_version=${NEW_PACKAGE_VERSION}" >> "$GITHUB_OUTPUT"
echo "old_package_version=${OLD_PACKAGE_VERSION}" >> "$GITHUB_OUTPUT"

# Keep the version of the PRs up-to-date
- name: Create Release Pull Request
id: release-pr
uses: changesets/action@aba318e9165b45b7948c60273e0b72fce0a64eb9 # v1.4.7
with:
branch: 'main'
title: 'chore(release): bump version and update changelog'
commit: 'chore(release): bump version and update changelog'
# This branch context is ignored in this step: `https://github.com/changesets/action/blob/50750fa876cc1e54c7cb972db5e2f7271fc53d99/src/run.ts#L328`, therefore the usage of `branch` selection in the workflow trigger.
branch: ${{ steps.branch-check.outputs.branch_name }}
title: 'chore(release): bump version and update changelog for the release from `${{ steps.extract-package-versions.outputs.old_package_version }}` to `${{ steps.extract-package-versions.outputs.new_package_version }}`'
commit: 'chore(release): bump version and update changelog from `${{ steps.extract-package-versions.outputs.old_package_version }}` to `${{ steps.extract-package-versions.outputs.new_package_version }}`'
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
3 changes: 2 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
name: Release

on:
# Once the PR gets merged to `main`
# Once the PR gets merged to `main` or `release` branches
pull_request:
branches:
- main
- releases/**
types: [closed]

concurrency: ${{ github.workflow }}-${{ github.ref }}
Expand Down