Repository navigation
70 lines (59 loc) · 2.21 KB
/
Copy pathrelease.yml
File metadata and controls
70 lines (59 loc) · 2.21 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
name: Release
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to release or revert to (e.g., v3.2.1)'
required: true
type: string
revert:
description: 'Revert releases/vX to this existing tag?'
required: false
type: boolean
default: false
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Validate tag format
run: |
TAG="${{ inputs.tag }}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Invalid tag format: $TAG. Expected: v<major>.<minor>.<patch>"
exit 1
fi
- name: Parse version
id: version
run: |
TAG="${{ inputs.tag }}"
MAJOR=$(echo "$TAG" | cut -d. -f1)
echo "major=${MAJOR}" >> $GITHUB_OUTPUT
echo "branch=releases/${MAJOR}" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.revert == true && inputs.tag || steps.version.outputs.branch }}
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Release new tag
if: ${{ inputs.revert == false }}
run: |
MAJOR="${{ steps.version.outputs.major }}"
# Update the major tag (e.g., v3) to point to same commit as inputs.tag
git tag -fa ${MAJOR} -m "Release ${{ inputs.tag }}"
git push origin ${MAJOR} --force
echo "## ✅ Release ${{ inputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "- Tag: \`${{ inputs.tag }}\`" >> $GITHUB_STEP_SUMMARY
echo "- Branch: \`${{ steps.version.outputs.branch }}\`" >> $GITHUB_STEP_SUMMARY
- name: Revert to existing tag
if: ${{ inputs.revert == true }}
run: |
BRANCH="${{ steps.version.outputs.branch }}"
git push origin ${{ inputs.tag }}:refs/heads/${BRANCH} --force
echo "## ⏪ Reverted ${BRANCH} to ${{ inputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "- \`${BRANCH}\` now points to \`${{ inputs.tag }}\`" >> $GITHUB_STEP_SUMMARY