-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (67 loc) · 2.92 KB
/
create-version-tag.yml
File metadata and controls
79 lines (67 loc) · 2.92 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
name: Create Version Tag
on:
workflow_run:
workflows: ["Build"]
types: [completed]
branches: [main]
permissions:
contents: write
jobs:
create-tag:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Extract version
id: version
run: |
VERSION=$(sed -n 's/.*"version": "\([^"]*\)".*/\1/p' sources.json | head -1)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "major=${VERSION%%.*}" >> "$GITHUB_OUTPUT"
- name: Check if version tag exists
id: check-tag
run: |
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create version tag
if: steps.check-tag.outputs.exists == 'false'
run: |
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
- name: Update moving tags
if: steps.check-tag.outputs.exists == 'false'
run: |
VERSION="${{ steps.version.outputs.version }}"
MAJOR="${{ steps.version.outputs.major }}"
git push origin :refs/tags/latest 2>/dev/null || true
git push origin ":refs/tags/v$MAJOR" 2>/dev/null || true
git tag -d latest 2>/dev/null || true
git tag -d "v$MAJOR" 2>/dev/null || true
git tag -a latest -m "Latest release: v$VERSION"
git tag -a "v$MAJOR" -m "Latest v$MAJOR release: v$VERSION"
git push origin latest "v$MAJOR"
- name: Summary
run: |
echo "## Tag Summary" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "| Tag | Points To |" >> "$GITHUB_STEP_SUMMARY"
echo "| --- | --- |" >> "$GITHUB_STEP_SUMMARY"
if [ "${{ steps.check-tag.outputs.exists }}" = "false" ]; then
echo "| v${{ steps.version.outputs.version }} | $(git rev-parse --short HEAD) |" >> "$GITHUB_STEP_SUMMARY"
echo "| v${{ steps.version.outputs.major }} | v${{ steps.version.outputs.version }} |" >> "$GITHUB_STEP_SUMMARY"
echo "| latest | v${{ steps.version.outputs.version }} |" >> "$GITHUB_STEP_SUMMARY"
else
echo "| v${{ steps.version.outputs.version }} | unchanged (already existed) |" >> "$GITHUB_STEP_SUMMARY"
echo "| v${{ steps.version.outputs.major }} | unchanged |" >> "$GITHUB_STEP_SUMMARY"
echo "| latest | unchanged |" >> "$GITHUB_STEP_SUMMARY"
fi