1
1
name : Automated Release
2
2
on :
3
- pull_request :
4
- branches :
5
- - main
6
- - next
7
3
push :
8
- branches :
9
- - main
10
- - next
4
+ branches : [main, next]
5
+ pull_request :
6
+ branches : [main, next]
11
7
12
8
permissions :
13
9
contents : write
14
10
actions : read
15
11
16
- jobs :
17
- check-commit :
18
- runs-on : macos-latest
19
- outputs :
20
- should_release : ${{ steps.check.outputs.should_release }}
21
- steps :
22
- - name : Checkout code
23
- uses : actions/checkout@v4
24
- with :
25
- fetch-depth : 1
26
-
27
- - name : Check commit message and branch
28
- id : check
29
- run : |
30
- COMMIT_MESSAGE=$(git log -1 --pretty=%B)
31
- BRANCH_NAME=${{ github.ref_name }}
32
-
33
- if [[ $COMMIT_MESSAGE =~ ^feat!.* ]] || [[ $COMMIT_MESSAGE =~ ^feat:.* ]] || [[ $COMMIT_MESSAGE =~ ^fix:.* ]]; then
34
- echo "should_release=true" >> $GITHUB_OUTPUT
35
- else
36
- echo "should_release=false" >> $GITHUB_OUTPUT
37
- echo "No version bump needed (commit: $COMMIT_MESSAGE)"
38
- fi
12
+ concurrency :
13
+ group : release-${{ github.ref }}
14
+ cancel-in-progress : true
39
15
16
+ jobs :
40
17
release :
41
- needs : check-commit
42
- if : needs.check-commit.outputs.should_release == 'true'
43
18
runs-on : macos-latest
44
19
steps :
45
20
- name : Checkout code
46
21
uses : actions/checkout@v4
47
22
with :
48
- fetch-depth : 0
23
+ fetch-depth : 0
49
24
50
25
- name : Setup Swift
51
26
uses : swift-actions/setup-swift@v2
65
40
66
41
- name : Run tests
67
42
run : swift test
68
- continue-on-error : false
69
43
70
44
- name : Setup GitHub CLI
71
45
run : |
@@ -77,38 +51,22 @@ jobs:
77
51
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
78
52
run : |
79
53
set -e
54
+ COMMIT_MESSAGE=$(git log -1 --pretty=%B)
55
+ [[ $COMMIT_MESSAGE =~ ^(feat!|feat:|fix:) ]] || { echo "No release needed"; exit 0; }
80
56
81
- # Get the latest version tag (default to 0.0.0 if none)
82
57
LATEST_TAG=$(git tag -l '[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n 1)
83
- if [ -z "$LATEST_TAG" ]; then
84
- CURRENT_VERSION="0.0.0"
85
- else
86
- CURRENT_VERSION="$LATEST_TAG"
87
- fi
58
+ CURRENT_VERSION="${LATEST_TAG:-0.0.0}"
88
59
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
89
60
90
- # Get last commit message
91
- COMMIT_MESSAGE=$(git log -1 --pretty=%B)
92
-
93
- # Determine version bump
94
- if [[ $COMMIT_MESSAGE =~ ^feat!.* ]]; then
95
- MAJOR=$((MAJOR + 1))
96
- MINOR=0
97
- PATCH=0
98
- elif [[ $COMMIT_MESSAGE =~ ^feat:.* ]]; then
99
- MINOR=$((MINOR + 1))
100
- PATCH=0
101
- elif [[ $COMMIT_MESSAGE =~ ^fix:.* ]]; then
102
- PATCH=$((PATCH + 1))
103
- else
104
- echo "No version bump needed (commit: $COMMIT_MESSAGE)"
105
- exit 0
106
- fi
61
+ case "$COMMIT_MESSAGE" in
62
+ feat!*) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
63
+ feat:*) MINOR=$((MINOR + 1)); PATCH=0 ;;
64
+ fix:*) PATCH=$((PATCH + 1)) ;;
65
+ esac
107
66
108
67
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
109
68
BRANCH_NAME=${{ github.ref_name }}
110
69
111
- # Determine tag and release type based on branch
112
70
if [ "$BRANCH_NAME" = "main" ]; then
113
71
RELEASE_TAG="$NEW_VERSION"
114
72
RELEASE_TITLE="Release $NEW_VERSION"
@@ -119,26 +77,19 @@ jobs:
119
77
IS_PRERELEASE=true
120
78
fi
121
79
122
- echo "Bumping version from $CURRENT_VERSION to $RELEASE_TAG"
123
-
80
+ echo "Bumping version to $RELEASE_TAG"
124
81
git config user.name "GitHub Actions"
125
82
git config user.email "actions@github.com"
126
83
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git
127
- git push origin "$BRANCH_NAME"
128
-
129
84
git tag -a "$RELEASE_TAG" -m "$RELEASE_TAG"
130
85
git push origin "$RELEASE_TAG"
131
86
132
- # Generate release notes from commits since last tag
133
87
if [ -z "$LATEST_TAG" ]; then
134
88
RELEASE_NOTES=$(git log --pretty=format:"- %s")
135
89
else
136
90
RELEASE_NOTES=$(git log "$LATEST_TAG"..HEAD --pretty=format:"- %s")
137
91
fi
138
92
139
- echo "Release notes:"
140
- echo "$RELEASE_NOTES"
141
-
142
93
gh release create "$RELEASE_TAG" \
143
94
--title "$RELEASE_TITLE" \
144
95
--notes "$RELEASE_NOTES" \
0 commit comments