Skip to content

Commit 7989241

Browse files
committed
feat: implement PR-based release workflow to work with branch protection
1 parent 523a0c4 commit 7989241

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

.github/workflows/release.yml

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,93 @@ on:
33
push:
44
branches:
55
- master
6+
7+
env:
8+
HUSKY: 0
9+
610
jobs:
711
release:
12+
permissions:
13+
contents: write # for release publishing
14+
pull-requests: write # for creating PRs
15+
issues: write # additional permission that might be needed
16+
817
name: Release
18+
env:
19+
commitmsg: ${{ github.event.head_commit.message }}
920
runs-on: ubuntu-latest
1021
steps:
11-
- name: Checkout
12-
uses: actions/checkout@v2
22+
- name: Checkout repository
23+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
1324
with:
1425
fetch-depth: 0
1526
- name: Setup Node.js
16-
uses: actions/setup-node@v3
27+
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v3
1728
with:
18-
node-version: 20
29+
node-version: lts/*
30+
cache: 'yarn'
1931
- name: Install dependencies
2032
run: yarn install --frozen-lockfile --non-interactive
33+
- run: yarn build
2134
- name: Release
35+
id: semantic_release
2236
env:
2337
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2438
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2539
run: npx semantic-release
40+
- name: Create PR with release changes
41+
if: ${{ success() && steps.semantic_release.outcome == 'success' }}
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
run: |
46+
# Check if there are any changes to commit
47+
if [[ -n $(git status --porcelain) ]]; then
48+
# Get the version from package.json
49+
VERSION=$(node -p "require('./package.json').version")
50+
BRANCH_NAME="release/v${VERSION}"
51+
52+
echo "Creating PR for release version: ${VERSION}"
53+
54+
# Create and switch to new branch
55+
git checkout -b $BRANCH_NAME
56+
57+
# Configure git
58+
git config --local user.email "[email protected]"
59+
git config --local user.name "GitHub Action"
60+
61+
# Add and commit changes (only add files that exist)
62+
git add package.json || true
63+
git add yarn.lock || true
64+
git add CHANGELOG.md || true
65+
66+
# Check if there are actually changes to commit after adding
67+
if [[ -n $(git diff --cached --name-only) ]]; then
68+
git commit -m "chore(release): ${VERSION}"
69+
70+
# Push the branch
71+
git push origin $BRANCH_NAME
72+
73+
# Create PR using GitHub CLI
74+
gh pr create \
75+
--title "chore(release): ${VERSION}" \
76+
--body "Automated release PR for version ${VERSION}
77+
78+
This PR contains:
79+
- Updated package.json version
80+
- Updated yarn.lock (if changed)
81+
- Updated CHANGELOG.md
82+
83+
Please review and merge to complete the release process." \
84+
--head $BRANCH_NAME \
85+
--base master
86+
87+
echo "Created PR for release ${VERSION}"
88+
else
89+
echo "No changes to commit after staging files"
90+
git checkout master
91+
git branch -D $BRANCH_NAME
92+
fi
93+
else
94+
echo "No changes detected after semantic-release"
95+
fi

0 commit comments

Comments
 (0)