3
3
push :
4
4
branches :
5
5
- main
6
+ - development
6
7
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
+
7
32
release :
33
+ needs : check-commit
34
+ if : needs.check-commit.outputs.should_release == 'true'
8
35
runs-on : macos-latest
9
36
steps :
10
37
# Checkout the repository with full commit history
19
46
with :
20
47
swift-version : " 6.1"
21
48
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
+
22
58
# Resolve Swift package dependencies
23
59
- name : Resolve dependencies
24
60
run : swift package resolve
47
83
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
48
84
49
85
# Get the latest commit message
50
- COMMIT_MESSAGE=$(git log -1 --pretty=%B)
86
+ COMMIT_MESSAGE="${{ needs.check-commit.outputs.commit_message }}"
51
87
52
88
# Determine version bump based on conventional commits
53
89
if [[ $COMMIT_MESSAGE =~ ^feat!.* ]]; then
@@ -79,7 +115,16 @@ jobs:
79
115
git config user.email "actions@github.com"
80
116
git add VERSION
81
117
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
83
128
84
129
# Create and push tag
85
130
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
@@ -89,7 +134,16 @@ jobs:
89
134
RELEASE_NOTES="Automated release for v$NEW_VERSION\n\nChanges:\n- $COMMIT_MESSAGE"
90
135
91
136
# 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