Skip to content

Commit 6cb536a

Browse files
authored
Merge pull request #701 from thecodacus/auto-versioning #release
chore: Adding workflow
2 parents 8cc2b4c + 648d7fe commit 6cb536a

File tree

2 files changed

+64
-38
lines changed

2 files changed

+64
-38
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: PR Validation
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, labeled, unlabeled]
6+
branches:
7+
- main
8+
9+
jobs:
10+
validate:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Validate PR Labels
17+
run: |
18+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'stable-release') }}" == "true" ]]; then
19+
echo "✓ PR has stable-release label"
20+
21+
# Check version bump labels
22+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'major') }}" == "true" ]]; then
23+
echo "✓ Major version bump requested"
24+
elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'minor') }}" == "true" ]]; then
25+
echo "✓ Minor version bump requested"
26+
else
27+
echo "✓ Patch version bump will be applied"
28+
fi
29+
else
30+
echo "This PR doesn't have the stable-release label. No release will be created."
31+
fi

.github/workflows/update-stable.yml

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
name: Update Stable Branch
22

33
on:
4-
pull_request:
5-
types: [closed]
4+
push:
65
branches:
76
- main
87

98
permissions:
109
contents: write
1110

1211
jobs:
13-
update-stable:
14-
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'stable-release')
12+
prepare-release:
13+
if: contains(github.event.head_commit.message, '#release')
1514
runs-on: ubuntu-latest
16-
permissions:
17-
contents: write
18-
pull-requests: read
1915

2016
steps:
2117
- uses: actions/checkout@v4
2218
with:
2319
fetch-depth: 0
24-
token: ${{ secrets.GITHUB_TOKEN }}
20+
2521
- name: Configure Git
2622
run: |
2723
git config --global user.name 'github-actions[bot]'
@@ -52,17 +48,6 @@ jobs:
5248
restore-keys: |
5349
${{ runner.os }}-pnpm-store-
5450
55-
- name: Determine Version Bump
56-
id: version_bump
57-
run: |
58-
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'major') }}" == "true" ]]; then
59-
echo "bump=major" >> $GITHUB_OUTPUT
60-
elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'minor') }}" == "true" ]]; then
61-
echo "bump=minor" >> $GITHUB_OUTPUT
62-
else
63-
echo "bump=patch" >> $GITHUB_OUTPUT
64-
fi
65-
6651
- name: Get Current Version
6752
id: current_version
6853
run: |
@@ -72,6 +57,18 @@ jobs:
7257
- name: Install semver
7358
run: pnpm add -g semver
7459

60+
- name: Determine Version Bump
61+
id: version_bump
62+
run: |
63+
COMMIT_MSG="${{ github.event.head_commit.message }}"
64+
if [[ $COMMIT_MSG =~ "#release:major" ]]; then
65+
echo "bump=major" >> $GITHUB_OUTPUT
66+
elif [[ $COMMIT_MSG =~ "#release:minor" ]]; then
67+
echo "bump=minor" >> $GITHUB_OUTPUT
68+
else
69+
echo "bump=patch" >> $GITHUB_OUTPUT
70+
fi
71+
7572
- name: Bump Version
7673
id: bump_version
7774
run: |
@@ -161,32 +158,30 @@ jobs:
161158
echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
162159
echo "EOF" >> $GITHUB_OUTPUT
163160
164-
- name: Commit Version Update
161+
- name: Commit and Tag Release
165162
run: |
166163
git pull
167164
git add package.json pnpm-lock.yaml changelog.md
168-
git commit -m "chore: bump version to ${{ steps.bump_version.outputs.new_version }}"
165+
git commit -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
166+
git tag "v${{ steps.bump_version.outputs.new_version }}"
169167
git push
168+
git push --tags
170169
171170
- name: Update Stable Branch
172171
run: |
173-
# Ensure stable branch exists
174-
git checkout stable 2>/dev/null || git checkout -b stable
175-
git merge main --no-ff -m "chore: merge main into stable for version ${{ steps.bump_version.outputs.new_version }}"
176-
git push --set-upstream origin stable
172+
if ! git checkout stable 2>/dev/null; then
173+
echo "Creating new stable branch..."
174+
git checkout -b stable
175+
fi
176+
git merge main --no-ff -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
177+
git push --set-upstream origin stable --force
177178
178-
- name: Create and Push Tag
179+
- name: Create GitHub Release
180+
env:
181+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
179182
run: |
180183
VERSION="v${{ steps.bump_version.outputs.new_version }}"
181-
git tag -a "$VERSION" -m "Release $VERSION"
182-
git push origin "$VERSION"
183-
184-
# - name: Create GitHub Release
185-
# env:
186-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
187-
# run: |
188-
# VERSION="v${{ steps.bump_version.outputs.new_version }}"
189-
# gh release create "$VERSION" \
190-
# --title "Release $VERSION" \
191-
# --notes "${{ steps.changelog.outputs.content }}" \
192-
# --target stable
184+
gh release create "$VERSION" \
185+
--title "Release $VERSION" \
186+
--notes "${{ steps.changelog.outputs.content }}" \
187+
--target stable

0 commit comments

Comments
 (0)