-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub Action for staging release workflow
- Loading branch information
Showing
1 changed file
with
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: 'Stage Release Action' | ||
description: 'Reusable GitHub Action to create stage release PRs' | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
version_type: | ||
description: "Version type (minor or patch)" | ||
required: true | ||
type: string | ||
default: "patch" | ||
secrets: | ||
GH_TOKEN: | ||
description: "GitHub token" | ||
required: true | ||
|
||
jobs: | ||
create-release: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
|
||
- name: Bump version | ||
run: | | ||
CURRENT_VERSION=$(node -p "require('./package.json').version") | ||
CLEAN_VERSION=$(echo "$CURRENT_VERSION" | sed -E 's/-hotfix.*//') | ||
NEW_VERSION=$(npx semver "$CLEAN_VERSION" -i ${{ inputs.version_type }}) | ||
echo "New version: $NEW_VERSION" | ||
npm version "$NEW_VERSION" --no-git-tag-version | ||
echo "VERSION=v$NEW_VERSION" >> $GITHUB_ENV | ||
echo "RELEASE_BRANCH=release/v$NEW_VERSION" >> $GITHUB_ENV | ||
- name: Setup git config | ||
run: | | ||
git config user.name "${{ github.actor }}" | ||
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" | ||
- name: Create release branch | ||
run: | | ||
git checkout -b ${{ env.RELEASE_BRANCH }} | ||
git add package.json package-lock.json | ||
git commit -m "🔖 Bump version to \`${{ env.VERSION }}\`" | ||
git push --set-upstream origin ${{ env.RELEASE_BRANCH }} | ||
- name: Create Pull Request | ||
env: | ||
GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
run: | | ||
gh pr create --base env/stage \ | ||
--head ${{ env.RELEASE_BRANCH }} \ | ||
--title "📦 Prepare release \`${{ env.VERSION }}\` and deploy to stage" \ | ||
--body "This is an automated release PR for version \`${{ env.VERSION }}\`" \ | ||
--label "deployment" |