Skip to content

Commit

Permalink
Add GitHub Action for staging release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
enxtur committed Feb 25, 2025
1 parent 4b46425 commit 8b653bf
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/stage-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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
id: 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_OUTPUT
echo "release_branch=release/v$NEW_VERSION" >> $GITHUB_OUTPUT
- 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 ${{ steps.bump_version.outputs.release_branch }}
git add package.json
if [ -f "package-lock.json" ]; then
git add package-lock.json
elif [ -f "yarn.lock" ]; then
git add yarn.lock
fi
git commit -m "🔖 Bump version to \`${{ steps.bump_version.outputs.version }}\`"
git push --set-upstream origin ${{ steps.bump_version.outputs.release_branch }}
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
gh pr create --base env/stage \
--head ${{ steps.bump_version.outputs.release_branch }} \
--title "📦 Prepare release \`${{ steps.bump_version.outputs.version }}\` and deploy to stage" \
--body "This is an automated release PR for version \`${{ steps.bump_version.outputs.version }}\`" \
--label "deployment"

0 comments on commit 8b653bf

Please sign in to comment.