Skip to content

Commit e7d1a0c

Browse files
authored
fix: release workflow
1 parent 85e2e54 commit e7d1a0c

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

.github/workflows/release.yml

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ on:
55
- main
66
- development
77
permissions:
8-
contents: write
9-
actions: read
8+
contents: write
9+
actions: read
1010
jobs:
1111
check-commit:
1212
runs-on: ubuntu-latest
@@ -37,19 +37,16 @@ jobs:
3737
if: needs.check-commit.outputs.should_release == 'true'
3838
runs-on: macos-latest
3939
steps:
40-
# Checkout the repository with full commit history
4140
- name: Checkout code
4241
uses: actions/checkout@v4
4342
with:
44-
fetch-depth: 0
43+
fetch-depth: 0 # Full history needed for tag inspection
4544

46-
# Set up Swift environment
4745
- name: Setup Swift
4846
uses: swift-actions/setup-swift@v2
4947
with:
5048
swift-version: "6.1"
5149

52-
# Cache SwiftPM dependencies
5350
- name: Cache SwiftPM dependencies
5451
uses: actions/cache@v3
5552
with:
@@ -58,31 +55,32 @@ jobs:
5855
restore-keys: |
5956
${{ runner.os }}-swiftpm-
6057
61-
# Resolve Swift package dependencies
6258
- name: Resolve dependencies
6359
run: swift package resolve
6460

65-
# Run tests to validate the package
6661
- name: Run tests
6762
run: swift test
6863
continue-on-error: false
6964

70-
# Install GitHub CLI for release creation
7165
- name: Setup GitHub CLI
7266
run: |
7367
brew install gh
7468
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
7569
76-
# Bump version, create tag, and release
7770
- name: Bump version and create release
7871
env:
7972
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8073
run: |
8174
#!/bin/bash
8275
set -e
8376
84-
# Get the current version from VERSION file (default to 0.0.0 if not exists)
85-
CURRENT_VERSION=$(cat VERSION 2>/dev/null || echo "0.0.0")
77+
# Get the latest version tag (default to 0.0.0 if no tags exist)
78+
LATEST_TAG=$(git tag -l 'v*' --sort=-v:refname | head -n 1)
79+
if [ -z "$LATEST_TAG" ]; then
80+
CURRENT_VERSION="0.0.0"
81+
else
82+
CURRENT_VERSION="${LATEST_TAG#v}" # Remove 'v' prefix (e.g., v0.0.0 -> 0.0.0)
83+
fi
8684
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
8785
8886
# Get the latest commit message
@@ -110,14 +108,9 @@ jobs:
110108
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
111109
echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION"
112110
113-
# Update VERSION file
114-
echo "$NEW_VERSION" > VERSION
115-
116-
# Commit version changes
111+
# Configure git
117112
git config user.name "GitHub Actions"
118113
git config user.email "actions@github.com"
119-
git add VERSION
120-
git commit -m "chore(release): bump version to $NEW_VERSION [skip ci]" || echo "No changes to commit"
121114
122115
# Configure git to use GitHub token
123116
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/maclong9/web-ui.git
@@ -136,10 +129,6 @@ jobs:
136129
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
137130
git push origin "v$NEW_VERSION"
138131
139-
# Create and push tag
140-
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
141-
git push origin "v$NEW_VERSION"
142-
143132
# Generate release notes from commit message
144133
RELEASE_NOTES="Automated release for v$NEW_VERSION\n\nChanges:\n- $COMMIT_MESSAGE"
145134

0 commit comments

Comments
 (0)