Skip to content

Commit e6ad742

Browse files
authored
fix: improve workflow file
1 parent bfb5344 commit e6ad742

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

.github/workflows/release.yml

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,35 @@ on:
33
push:
44
branches:
55
- main
6+
- development
67
jobs:
8+
check-commit:
9+
runs-on: ubuntu-latest
10+
outputs:
11+
should_release: ${{ steps.check.outputs.should_release }}
12+
commit_message: ${{ steps.check.outputs.commit_message }}
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 1
18+
19+
- name: Check commit message
20+
id: check
21+
run: |
22+
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
23+
echo "commit_message=$COMMIT_MESSAGE" >> $GITHUB_OUTPUT
24+
25+
if [[ $COMMIT_MESSAGE =~ ^feat!.* ]] || [[ $COMMIT_MESSAGE =~ ^feat:.* ]] || [[ $COMMIT_MESSAGE =~ ^fix:.* ]]; then
26+
echo "should_release=true" >> $GITHUB_OUTPUT
27+
else
28+
echo "should_release=false" >> $GITHUB_OUTPUT
29+
echo "No version bump needed (commit: $COMMIT_MESSAGE)"
30+
fi
31+
732
release:
33+
needs: check-commit
34+
if: needs.check-commit.outputs.should_release == 'true'
835
runs-on: macos-latest
936
steps:
1037
# Checkout the repository with full commit history
@@ -19,6 +46,15 @@ jobs:
1946
with:
2047
swift-version: "6.1"
2148

49+
# Cache SwiftPM dependencies
50+
- name: Cache SwiftPM dependencies
51+
uses: actions/cache@v3
52+
with:
53+
path: .build
54+
key: ${{ runner.os }}-swiftpm-${{ hashFiles('**/Package.resolved') }}
55+
restore-keys: |
56+
${{ runner.os }}-swiftpm-
57+
2258
# Resolve Swift package dependencies
2359
- name: Resolve dependencies
2460
run: swift package resolve
@@ -47,7 +83,7 @@ jobs:
4783
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
4884
4985
# Get the latest commit message
50-
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
86+
COMMIT_MESSAGE="${{ needs.check-commit.outputs.commit_message }}"
5187
5288
# Determine version bump based on conventional commits
5389
if [[ $COMMIT_MESSAGE =~ ^feat!.* ]]; then
@@ -79,7 +115,16 @@ jobs:
79115
git config user.email "actions@github.com"
80116
git add VERSION
81117
git commit -m "chore(release): bump version to $NEW_VERSION [skip ci]" || echo "No changes to commit"
82-
git push origin main
118+
119+
# Determine if this is a pre-release (development branch)
120+
IS_PRERELEASE="false"
121+
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
122+
if [ "$BRANCH_NAME" = "development" ]; then
123+
IS_PRERELEASE="true"
124+
git push origin development
125+
else
126+
git push origin main
127+
fi
83128
84129
# Create and push tag
85130
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
@@ -89,7 +134,16 @@ jobs:
89134
RELEASE_NOTES="Automated release for v$NEW_VERSION\n\nChanges:\n- $COMMIT_MESSAGE"
90135
91136
# Create GitHub release
92-
gh release create "v$NEW_VERSION" \
93-
--title "Release v$NEW_VERSION" \
94-
--notes "$RELEASE_NOTES" \
95-
--latest
137+
if [ "$IS_PRERELEASE" = "true" ]; then
138+
# Create pre-release for development branch
139+
gh release create "v$NEW_VERSION" \
140+
--title "Pre-release v$NEW_VERSION" \
141+
--notes "$RELEASE_NOTES" \
142+
--prerelease
143+
else
144+
# Create regular release for main branch
145+
gh release create "v$NEW_VERSION" \
146+
--title "Release v$NEW_VERSION" \
147+
--notes "$RELEASE_NOTES" \
148+
--latest
149+
fi

0 commit comments

Comments
 (0)