Skip to content

Commit 5cabe16

Browse files
authored
fix: streamlined workflow
1 parent 44e033a commit 5cabe16

File tree

1 file changed

+17
-66
lines changed

1 file changed

+17
-66
lines changed

.github/workflows/release.yml

Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,26 @@
11
name: Automated Release
22
on:
3-
pull_request:
4-
branches:
5-
- main
6-
- next
73
push:
8-
branches:
9-
- main
10-
- next
4+
branches: [main, next]
5+
pull_request:
6+
branches: [main, next]
117

128
permissions:
139
contents: write
1410
actions: read
1511

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
3915

16+
jobs:
4017
release:
41-
needs: check-commit
42-
if: needs.check-commit.outputs.should_release == 'true'
4318
runs-on: macos-latest
4419
steps:
4520
- name: Checkout code
4621
uses: actions/checkout@v4
4722
with:
48-
fetch-depth: 0
23+
fetch-depth: 0
4924

5025
- name: Setup Swift
5126
uses: swift-actions/setup-swift@v2
@@ -65,7 +40,6 @@ jobs:
6540

6641
- name: Run tests
6742
run: swift test
68-
continue-on-error: false
6943

7044
- name: Setup GitHub CLI
7145
run: |
@@ -77,38 +51,22 @@ jobs:
7751
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7852
run: |
7953
set -e
54+
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
55+
[[ $COMMIT_MESSAGE =~ ^(feat!|feat:|fix:) ]] || { echo "No release needed"; exit 0; }
8056
81-
# Get the latest version tag (default to 0.0.0 if none)
8257
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}"
8859
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
8960
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
10766
10867
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
10968
BRANCH_NAME=${{ github.ref_name }}
11069
111-
# Determine tag and release type based on branch
11270
if [ "$BRANCH_NAME" = "main" ]; then
11371
RELEASE_TAG="$NEW_VERSION"
11472
RELEASE_TITLE="Release $NEW_VERSION"
@@ -119,26 +77,19 @@ jobs:
11977
IS_PRERELEASE=true
12078
fi
12179
122-
echo "Bumping version from $CURRENT_VERSION to $RELEASE_TAG"
123-
80+
echo "Bumping version to $RELEASE_TAG"
12481
git config user.name "GitHub Actions"
12582
git config user.email "actions@github.com"
12683
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git
127-
git push origin "$BRANCH_NAME"
128-
12984
git tag -a "$RELEASE_TAG" -m "$RELEASE_TAG"
13085
git push origin "$RELEASE_TAG"
13186
132-
# Generate release notes from commits since last tag
13387
if [ -z "$LATEST_TAG" ]; then
13488
RELEASE_NOTES=$(git log --pretty=format:"- %s")
13589
else
13690
RELEASE_NOTES=$(git log "$LATEST_TAG"..HEAD --pretty=format:"- %s")
13791
fi
13892
139-
echo "Release notes:"
140-
echo "$RELEASE_NOTES"
141-
14293
gh release create "$RELEASE_TAG" \
14394
--title "$RELEASE_TITLE" \
14495
--notes "$RELEASE_NOTES" \

0 commit comments

Comments
 (0)