-
Notifications
You must be signed in to change notification settings - Fork 0
60 lines (60 loc) · 2.1 KB
/
auto-tag.yml
File metadata and controls
60 lines (60 loc) · 2.1 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
name: Auto Tag
on:
push:
branches: [main]
paths:
- Cargo.toml
permissions:
contents: write
jobs:
tag:
runs-on: ubuntu-latest
steps:
- name: Verify RELEASE_TOKEN is configured
run: |
if [ -z "${{ secrets.RELEASE_TOKEN }}" ]; then
echo "::error::RELEASE_TOKEN secret is not configured. Tags pushed with the default GITHUB_TOKEN cannot trigger the Release workflow."
exit 1
fi
- uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN }}
- name: Check for version bump
id: version
run: |
CURRENT=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
if [ "${{ github.event.before }}" = "0000000000000000000000000000000000000000" ]; then
PREVIOUS="$CURRENT"
else
PREVIOUS=$(git show ${{ github.event.before }}:Cargo.toml | grep '^version' | head -1 | sed 's/.*"\(.*\)"/\1/')
fi
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
echo "previous=$PREVIOUS" >> "$GITHUB_OUTPUT"
if [ "$CURRENT" != "$PREVIOUS" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Create and push tag
if: steps.version.outputs.changed == 'true'
run: |
VERSION="${{ steps.version.outputs.current }}"
TAG="v${VERSION}"
if git ls-remote --tags origin "refs/tags/$TAG" | grep -q .; then
echo "Tag $TAG already exists on origin, skipping"
exit 0
fi
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists locally, skipping"
exit 0
fi
git tag "$TAG"
if ! git push origin "$TAG"; then
if git ls-remote --tags origin "refs/tags/$TAG" | grep -q .; then
echo "Tag $TAG was created concurrently on origin, skipping"
exit 0
fi
echo "Failed to push tag $TAG"
exit 1
fi