Skip to content

Commit 73d1589

Browse files
committed
🔖 Update version to v$VERSION
- Extracted version from src-tauri/Cargo.toml with enhanced error handling - Updated version badges in markdown files - Synchronized package.json version (if exists) - Synchronized tauri.conf.json version (if exists) Auto-generated by GitHub Actions
1 parent 156ddb9 commit 73d1589

File tree

1 file changed

+151
-15
lines changed

1 file changed

+151
-15
lines changed

.github/workflows/update-version.yml

Lines changed: 151 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,193 @@ jobs:
1616
with:
1717
token: ${{ secrets.GITHUB_TOKEN }}
1818

19-
- name: Extract version from Cargo.toml
19+
- name: Extract version from Tauri Cargo.toml
2020
id: get_version
2121
run: |
22+
# Check if Tauri Cargo.toml exists
23+
if [ ! -f "src-tauri/Cargo.toml" ]; then
24+
echo "Error: src-tauri/Cargo.toml not found"
25+
exit 1
26+
fi
27+
2228
# Extract version using multiple methods for robustness
29+
VERSION=""
30+
31+
# Method 1: Using toml command if available
2332
if command -v toml &> /dev/null; then
24-
VERSION=$(toml get Cargo.toml package.version --raw 2>/dev/null)
33+
VERSION=$(toml get src-tauri/Cargo.toml package.version --raw 2>/dev/null)
34+
fi
35+
36+
# Method 2: Using grep and sed (fallback)
37+
if [ -z "$VERSION" ]; then
38+
VERSION=$(grep '^version = ' src-tauri/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
2539
fi
2640
41+
# Method 3: Using awk (another fallback)
2742
if [ -z "$VERSION" ]; then
28-
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
43+
VERSION=$(awk -F'"' '/^version = / {print $2; exit}' src-tauri/Cargo.toml)
2944
fi
3045
46+
# Validate version format
3147
if [ -z "$VERSION" ]; then
32-
echo "Error: Could not extract version from Cargo.toml"
48+
echo "Error: Could not extract version from src-tauri/Cargo.toml"
49+
cat src-tauri/Cargo.toml | head -20 # Debug: show first 20 lines
50+
exit 1
51+
fi
52+
53+
# Validate version format (semantic versioning)
54+
if ! echo "$VERSION" | grep -E '^[0-9]+\.[0-9]+\.[0-9]+' > /dev/null; then
55+
echo "Error: Invalid version format: $VERSION"
3356
exit 1
3457
fi
3558
3659
echo "version=$VERSION" >> $GITHUB_OUTPUT
37-
echo "Extracted version: $VERSION"
60+
echo "Extracted version: $VERSION"
3861
3962
- name: Update version badges in all markdown files
4063
run: |
4164
VERSION="${{ steps.get_version.outputs.version }}"
42-
echo "Updating badges to version: $VERSION"
65+
echo "🔄 Updating badges to version: $VERSION"
66+
67+
# Counter for updated files
68+
UPDATED_COUNT=0
4369
4470
# Find all markdown files and update the version badge
45-
find . -name "*.md" -type f | while read -r file; do
46-
echo "Checking file: $file"
71+
find . -name "*.md" -type f -not -path "./node_modules/*" -not -path "./.git/*" | while read -r file; do
72+
echo "🔍 Checking file: $file"
73+
74+
# Check if file contains version badge
4775
if grep -q "img.shields.io/badge/Version-" "$file"; then
48-
echo "Updating badge in: $file"
76+
echo "📝 Updating badge in: $file"
77+
78+
# Create backup
79+
cp "$file" "$file.bak"
80+
81+
# Update the badge (handle different badge formats)
4982
sed -i "s|https://img\.shields\.io/badge/Version-[^-]*-informational|https://img.shields.io/badge/Version-$VERSION-informational|g" "$file"
83+
sed -i "s|https://img\.shields\.io/badge/Version-[^-]*-blue|https://img.shields.io/badge/Version-$VERSION-blue|g" "$file"
84+
sed -i "s|https://img\.shields\.io/badge/Version-[^-]*-green|https://img.shields.io/badge/Version-$VERSION-green|g" "$file"
85+
sed -i "s|https://img\.shields\.io/badge/version-[^-]*-informational|https://img.shields.io/badge/version-$VERSION-informational|g" "$file"
86+
87+
# Check if the update was successful
88+
if grep -q "Version-$VERSION-" "$file"; then
89+
echo "✅ Successfully updated: $file"
90+
rm "$file.bak"
91+
UPDATED_COUNT=$((UPDATED_COUNT + 1))
92+
else
93+
echo "❌ Failed to update: $file"
94+
mv "$file.bak" "$file" # Restore backup
95+
fi
5096
fi
5197
done
98+
99+
echo "📊 Updated $UPDATED_COUNT file(s)"
100+
101+
- name: Update package.json version (if exists)
102+
run: |
103+
VERSION="${{ steps.get_version.outputs.version }}"
104+
105+
if [ -f "package.json" ]; then
106+
echo "📦 Updating package.json version to: $VERSION"
107+
108+
# Install jq if not available
109+
if ! command -v jq &> /dev/null; then
110+
sudo apt-get update && sudo apt-get install -y jq
111+
fi
112+
113+
# Update version in package.json
114+
jq --arg version "$VERSION" '.version = $version' package.json > package.json.tmp
115+
mv package.json.tmp package.json
116+
117+
echo "✅ Updated package.json version"
118+
else
119+
echo "ℹ️ No package.json found, skipping"
120+
fi
121+
122+
- name: Update Tauri config version
123+
run: |
124+
VERSION="${{ steps.get_version.outputs.version }}"
125+
126+
if [ -f "src-tauri/tauri.conf.json" ]; then
127+
echo "⚙️ Updating tauri.conf.json version to: $VERSION"
128+
129+
# Install jq if not available
130+
if ! command -v jq &> /dev/null; then
131+
sudo apt-get update && sudo apt-get install -y jq
132+
fi
133+
134+
# Update version in tauri.conf.json
135+
jq --arg version "$VERSION" '.package.version = $version' src-tauri/tauri.conf.json > src-tauri/tauri.conf.json.tmp
136+
mv src-tauri/tauri.conf.json.tmp src-tauri/tauri.conf.json
137+
138+
echo "✅ Updated tauri.conf.json version"
139+
else
140+
echo "ℹ️ No tauri.conf.json found, skipping"
141+
fi
52142
53143
- name: Check for changes
54144
id: check_changes
55145
run: |
56146
if git diff --quiet; then
57147
echo "changes=false" >> $GITHUB_OUTPUT
58-
echo "No changes detected"
148+
echo "ℹ️ No changes detected"
59149
else
60150
echo "changes=true" >> $GITHUB_OUTPUT
61-
echo "Changes detected:"
151+
echo "📋 Changes detected:"
62152
git diff --name-only
153+
echo ""
154+
echo "📊 Changed files summary:"
155+
git diff --stat
63156
fi
64157
65158
- name: Commit and push changes
66159
if: steps.check_changes.outputs.changes == 'true'
67160
run: |
68-
git config --local user.email "action@github.com"
69-
git config --local user.name "GitHub Action"
161+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
162+
git config --local user.name "github-actions[bot]"
163+
164+
# Add all changes
70165
git add -A
71-
git commit -m "🔖 Update version badge to v${{ steps.get_version.outputs.version }}"
72-
git push
166+
167+
# Create detailed commit message
168+
VERSION="${{ steps.get_version.outputs.version }}"
169+
COMMIT_MSG="🔖 Update version to v$VERSION
170+
171+
- Updated version badges in markdown files
172+
- Synchronized package.json version (if exists)
173+
- Synchronized tauri.conf.json version (if exists)
174+
175+
Auto-generated by GitHub Actions"
176+
177+
git commit -m "$COMMIT_MSG"
178+
179+
# Push with retry logic
180+
for i in {1..3}; do
181+
if git push; then
182+
echo "✅ Successfully pushed changes"
183+
break
184+
else
185+
echo "⚠️ Push failed, retrying in 5 seconds... (attempt $i/3)"
186+
sleep 5
187+
git pull --rebase
188+
fi
189+
done
190+
191+
- name: Create summary
192+
if: always()
193+
run: |
194+
VERSION="${{ steps.get_version.outputs.version }}"
195+
196+
echo "## 🔖 Version Update Summary" >> $GITHUB_STEP_SUMMARY
197+
echo "" >> $GITHUB_STEP_SUMMARY
198+
echo "**Version:** \`v$VERSION\`" >> $GITHUB_STEP_SUMMARY
199+
echo "" >> $GITHUB_STEP_SUMMARY
200+
201+
if [ "${{ steps.check_changes.outputs.changes }}" == "true" ]; then
202+
echo "✅ **Status:** Successfully updated version badges and configuration files" >> $GITHUB_STEP_SUMMARY
203+
echo "" >> $GITHUB_STEP_SUMMARY
204+
echo "**Files updated:**" >> $GITHUB_STEP_SUMMARY
205+
git diff --name-only HEAD~1 | sed 's/^/- /' >> $GITHUB_STEP_SUMMARY
206+
else
207+
echo "ℹ️ **Status:** No changes required" >> $GITHUB_STEP_SUMMARY
208+
fi

0 commit comments

Comments
 (0)