-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (75 loc) · 3.33 KB
/
version-tag.yml
File metadata and controls
89 lines (75 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Create Version Tag
on:
push:
branches: [main]
paths:
- "build.zig.zon"
jobs:
check-version-and-tag:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check if version changed
id: version-check
run: |
# Extract current version from build.zig.zon
CURRENT_VERSION=$(grep -E '^\s*\.version\s*=\s*"[^"]*"' build.zig.zon | sed -E 's/.*"([^"]*)".*$/\1/')
echo "Current version: $CURRENT_VERSION"
# Check if this is the first commit or if we can get the previous version
if git show HEAD~1:build.zig.zon > /dev/null 2>&1; then
PREVIOUS_VERSION=$(git show HEAD~1:build.zig.zon | grep -E '^\s*\.version\s*=\s*"[^"]*"' | sed -E 's/.*"([^"]*)".*$/\1/')
echo "Previous version: $PREVIOUS_VERSION"
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
echo "version-changed=true" >> $GITHUB_OUTPUT
echo "new-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
else
echo "Version unchanged"
echo "version-changed=false" >> $GITHUB_OUTPUT
fi
else
echo "First commit or previous version not found, creating tag for current version"
echo "version-changed=true" >> $GITHUB_OUTPUT
echo "new-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
fi
- name: Update README.md with new version
if: steps.version-check.outputs.version-changed == 'true'
run: |
VERSION="${{ steps.version-check.outputs.new-version }}"
# Update the zig fetch command in README.md
sed -i "s|zig fetch --save \"git+https://github.com/xarunoba/env-struct.zig#v[^\"]*\"|zig fetch --save \"git+https://github.com/xarunoba/env-struct.zig#v${VERSION}\"|g" README.md
# Check if README.md was actually modified
if git diff --quiet README.md; then
echo "No changes needed in README.md"
else
echo "Updated README.md with version v${VERSION}"
# Commit and push the README update
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "Update README.md with version v${VERSION}"
git push
fi
- name: Create or update tag
if: steps.version-check.outputs.version-changed == 'true'
run: |
VERSION="${{ steps.version-check.outputs.new-version }}"
# Check if tag already exists
if git tag | grep -q "^v${VERSION}$"; then
echo "Tag v${VERSION} already exists, deleting and recreating..."
# Delete the tag locally and remotely
git tag -d "v${VERSION}" || true
git push --delete origin "v${VERSION}" || true
else
echo "Creating new tag v${VERSION}"
fi
# Create and push the tag
git tag -a "v${VERSION}" -m "${VERSION} Release"
git push origin "v${VERSION}"
echo "Successfully created/updated and pushed tag v${VERSION}"