-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.yml.j2
More file actions
179 lines (156 loc) · 5.75 KB
/
release.yml.j2
File metadata and controls
179 lines (156 loc) · 5.75 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Release
on:
push:
branches: [main]
workflow_dispatch: {}
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
jobs:
version-and-release:
name: Bump version, tag, and release
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
{% raw %}
- uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get current version
id: current
run: |
{% endraw %}
{% if type == 'cursor-plugin' %}
version=$(python3 -c "import json; print(json.load(open('.cursor-plugin/plugin.json'))['version'])")
{% else %}
version=$(python3 -c "import json; print(json.load(open('package.json'))['version'])")
{% endif %}
{% raw %}
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Current version: $version"
- name: Determine bump type from commits
id: bump
run: |
last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$last_tag" ]; then
commits=$(git log --oneline --format="%s")
else
commits=$(git log "$last_tag"..HEAD --oneline --format="%s")
fi
echo "Commits since last release:"
echo "$commits"
bump="patch"
if echo "$commits" | grep -qiE "^(feat|feature)(\(.+\))?!:|BREAKING CHANGE"; then
bump="major"
elif echo "$commits" | grep -qiE "^(feat|feature)(\(.+\))?:"; then
bump="minor"
fi
echo "bump=$bump" >> "$GITHUB_OUTPUT"
echo "Bump type: $bump"
- name: Compute new version
id: new
run: |
current="${{ steps.current.outputs.version }}"
bump="${{ steps.bump.outputs.bump }}"
IFS='.' read -r major minor patch <<< "$current"
# Initial release: when there is no prior tag, hold version at the
# value already in the manifest. The first release is cut at the
# scaffolded version (typically 0.1.0) instead of bumping to 0.2.0
# on the first feat: commit. After the first tag exists, normal
# conventional-commit-driven bumping resumes.
last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$last_tag" ]; then
new_version="$current"
else
case "$bump" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
esac
new_version="$major.$minor.$patch"
fi
echo "version=$new_version" >> "$GITHUB_OUTPUT"
echo "New version: $new_version"
- name: Check if tag already exists
id: check
run: |
new_version="${{ steps.new.outputs.version }}"
if git rev-parse "v$new_version" >/dev/null 2>&1; then
echo "skip=true" >> "$GITHUB_OUTPUT"
echo "Tag v$new_version already exists, skipping"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Update version files
if: steps.check.outputs.skip == 'false'
env:
NEW_VERSION: ${{ steps.new.outputs.version }}
OLD_VERSION: ${{ steps.current.outputs.version }}
run: |
python3 -c "
import json, os
new_version = os.environ['NEW_VERSION']
old_version = os.environ['OLD_VERSION']
{% endraw %}
{% if type == 'cursor-plugin' %}
path = '.cursor-plugin/plugin.json'
with open(path) as f:
data = json.load(f)
data['version'] = new_version
with open(path, 'w') as f:
json.dump(data, f, indent=2)
f.write('\n')
{% endif %}
readme = 'README.md'
if os.path.exists(readme):
with open(readme) as f:
content = f.read()
content = content.replace(
f'version-{old_version}-blue',
f'version-{new_version}-blue'
)
with open(readme, 'w') as f:
f.write(content)
"
{% raw %}
- name: Sync release docs
if: steps.check.outputs.skip == 'false'
uses: TMHSDigital/Developer-Tools-Directory/.github/actions/release-doc-sync@v1
with:
plugin-version: ${{ steps.new.outputs.version }}
previous-version: ${{ steps.current.outputs.version }}
- name: Commit version bump
if: steps.check.outputs.skip == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --cached --quiet; then
echo "No changes to commit"
else
git commit -m "chore: bump version to ${{ steps.new.outputs.version }} [skip ci]"
git push origin main
fi
- name: Create and push tags
if: steps.check.outputs.skip == 'false'
run: |
new_version="${{ steps.new.outputs.version }}"
IFS='.' read -r major minor _patch <<< "$new_version"
git tag "v$new_version"
git tag -f "v$major"
git tag -f "v$major.$minor"
git push origin "v$new_version"
git push origin "v$major" --force
git push origin "v$major.$minor" --force
- name: Create GitHub Release
if: steps.check.outputs.skip == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "v${{ steps.new.outputs.version }}" \
--title "v${{ steps.new.outputs.version }}" \
--generate-notes
{% endraw %}