-
Notifications
You must be signed in to change notification settings - Fork 11
98 lines (85 loc) · 3.72 KB
/
Copy pathcreate-tag.yml
File metadata and controls
98 lines (85 loc) · 3.72 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
90
91
92
93
94
95
96
97
98
name: Create Release Tag
on:
workflow_dispatch:
inputs:
version:
description: "Version number (e.g., 1.3.0 without the v prefix)"
required: true
type: string
create_release:
description: "Create GitHub Release immediately"
required: true
type: boolean
default: true
permissions:
contents: write
jobs:
create-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Validate version format
run: |
VERSION="${{ inputs.version }}"
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format X.Y.Z (e.g., 1.3.0)"
exit 1
fi
echo "Version format is valid: $VERSION"
- name: Check if tag already exists
run: |
VERSION="v${{ inputs.version }}"
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "Error: Tag $VERSION already exists"
exit 1
fi
echo "Tag $VERSION does not exist, proceeding..."
- name: Verify version in workflow/__init__.py
run: |
VERSION="${{ inputs.version }}"
CURRENT_VERSION=$(python -c "exec(open('workflow/__init__.py').read()); print(__version__)")
echo "Version in workflow/__init__.py: $CURRENT_VERSION"
echo "Version to tag: $VERSION"
if [ "$CURRENT_VERSION" != "$VERSION" ]; then
echo "Warning: Version in workflow/__init__.py ($CURRENT_VERSION) does not match tag version ($VERSION)"
echo "Please update workflow/__init__.py before creating the tag"
exit 1
fi
- name: Verify CHANGELOG.md has entry
run: |
VERSION="${{ inputs.version }}"
if ! grep -q "## \[$VERSION\]" CHANGELOG.md; then
echo "Warning: No entry found for version $VERSION in CHANGELOG.md"
echo "Please add a changelog entry before creating the tag"
exit 1
fi
echo "CHANGELOG.md contains entry for version $VERSION"
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Create and push tag
run: |
VERSION="v${{ inputs.version }}"
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION"
echo "Successfully created and pushed tag: $VERSION"
- name: Trigger release workflow
if: ${{ inputs.create_release }}
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'release.yml',
ref: 'main',
inputs: {
tag: 'v${{ inputs.version }}'
}
});
console.log('Triggered release workflow for v${{ inputs.version }}');