diff --git a/.github/workflows/stage-release.yml b/.github/workflows/stage-release.yml new file mode 100644 index 0000000..462d719 --- /dev/null +++ b/.github/workflows/stage-release.yml @@ -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"