-
-
Notifications
You must be signed in to change notification settings - Fork 2
299 lines (261 loc) · 12 KB
/
versioning.yml
File metadata and controls
299 lines (261 loc) · 12 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# This GitHub Actions workflow handles version bumping, releases, and tag updates.
# It can be triggered by:
# 1. Merging a PR to main branch - automatically bumps version, creates a GitHub Release,
# and updates stable/latest tags
# 2. Manual dispatch - allows independent control over stable and latest tags
#
# The workflow skips execution if the commit message contains [skip-versioning] to prevent loops.
---
name: Version, Release & Tags
on: # yamllint disable-line rule:truthy
pull_request:
types:
- closed
branches:
- main
paths-ignore:
- 'versioning/version.yaml'
workflow_dispatch:
inputs:
update_stable:
description: "Update stable tag?"
required: true
default: false
type: boolean
update_latest:
description: "Update latest tag?"
required: true
default: false
type: boolean
jobs:
version-and-release:
# Only run if PR was merged (not just closed)
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
runs-on: ubuntu-latest
concurrency:
group: version-and-release
cancel-in-progress: false
permissions:
contents: write
pull-requests: read
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for skip marker
id: skip_check
if: github.event_name == 'pull_request'
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if echo "$COMMIT_MESSAGE" | grep -q "\[skip-versioning\]"; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "Skipping workflow due to [skip-versioning] marker"
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Set up Git
if: github.event_name == 'workflow_dispatch' || steps.skip_check.outputs.skip == 'false'
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
- name: Set up yq
if: github.event_name == 'workflow_dispatch' || steps.skip_check.outputs.skip == 'false'
uses: mikefarah/yq@v4.43.1
- name: Get PR information
id: pr_info
if: (github.event_name == 'pull_request' && steps.skip_check.outputs.skip == 'false')
uses: actions/github-script@v7
with:
script: |
try {
// Get the PR that was just merged
const pr = context.payload.pull_request;
return {
title: pr.title,
body: pr.body || 'No description provided',
number: pr.number,
found: true
};
} catch (error) {
console.log('Could not get PR info:', error.message);
return {
title: 'Version update',
body: 'Automated version bump',
number: null,
found: false
};
}
- name: Read current version
id: current_version
if: github.event_name == 'workflow_dispatch' || steps.skip_check.outputs.skip == 'false'
run: |
VERSION=$(yq eval '.version' ./versioning/version.yaml)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Calculate next version
id: next_version
if: github.event_name == 'workflow_dispatch' || steps.skip_check.outputs.skip == 'false'
run: |
CURRENT_VERSION="${{ steps.current_version.outputs.version }}"
# Validate the current version format
if ! [[ "$CURRENT_VERSION" =~ ^[0-9]{4}\.[0-9]{1,2}\.[0-9]+$ ]]; then
echo "Error: Invalid version format: $CURRENT_VERSION"
exit 1
fi
# Extract components
CURRENT_YEAR=$(date +%Y)
CURRENT_MONTH=$(date +%-m) # Avoid leading zero for the month
CURRENT_SEQ=$(echo "$CURRENT_VERSION" | awk -F. '{print $3}')
VERSION_YEAR=$(echo "$CURRENT_VERSION" | awk -F. '{print $1}')
VERSION_MONTH=$(echo "$CURRENT_VERSION" | awk -F. '{print $2}')
# Determine new version
if [[ "$CURRENT_YEAR" == "$VERSION_YEAR" && "$CURRENT_MONTH" == "$VERSION_MONTH" ]]; then
NEXT_SEQ=$((CURRENT_SEQ + 1))
else
NEXT_SEQ=1 # Reset sequence for a new month
fi
NEXT_VERSION="${CURRENT_YEAR}.${CURRENT_MONTH}.${NEXT_SEQ}"
echo "version=${NEXT_VERSION}" >> $GITHUB_OUTPUT
- name: Update version.yaml file
if: github.event_name == 'workflow_dispatch' || steps.skip_check.outputs.skip == 'false'
env:
NEW_VERSION: ${{ steps.next_version.outputs.version }}
run: |
yq eval '.version = env(NEW_VERSION)' -i ./versioning/version.yaml
- name: Extract version information
id: versions
if: github.event_name == 'workflow_dispatch' || steps.skip_check.outputs.skip == 'false'
run: |
# Extract versions from version.yaml and esphome/nspanel_esphome_version.yaml
VERSION=$(yq eval '.version' ./versioning/version.yaml)
MIN_BLUEPRINT_VERSION=$(yq eval '.substitutions.min_blueprint_version' esphome/nspanel_esphome_version.yaml)
MIN_TFT_VERSION=$(yq eval '.substitutions.min_tft_version' esphome/nspanel_esphome_version.yaml)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "min_blueprint_version=${MIN_BLUEPRINT_VERSION}" >> $GITHUB_OUTPUT
echo "min_tft_version=${MIN_TFT_VERSION}" >> $GITHUB_OUTPUT
- name: Update bug report template with current versions
if: github.event_name == 'workflow_dispatch' || steps.skip_check.outputs.skip == 'false'
env:
VERSION: ${{ steps.versions.outputs.version }}
MIN_BLUEPRINT_VERSION: ${{ steps.versions.outputs.min_blueprint_version }}
MIN_TFT_VERSION: ${{ steps.versions.outputs.min_tft_version }}
run: |
# Update TFT Version placeholder
yq eval '.body[3].attributes.placeholder = strenv(MIN_TFT_VERSION) | "e.g., " + .' -i .github/ISSUE_TEMPLATE/bug.yml
# Update Firmware Version placeholder
yq eval '.body[4].attributes.placeholder = strenv(VERSION) | "e.g., " + .' -i .github/ISSUE_TEMPLATE/bug.yml
# Update Blueprint Version placeholder
yq eval '.body[5].attributes.placeholder = strenv(MIN_BLUEPRINT_VERSION) | "e.g., " + .' -i .github/ISSUE_TEMPLATE/bug.yml
- name: Commit version and template changes
id: commit
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && steps.skip_check.outputs.skip == 'false')
env:
NEW_VERSION: ${{ steps.next_version.outputs.version }}
run: |
git add ./versioning/version.yaml .github/ISSUE_TEMPLATE/bug.yml
git commit -m "Bump version to $NEW_VERSION [skip-versioning]"
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
- name: Create tag message
id: tag_message
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && steps.skip_check.outputs.skip == 'false')
env:
PR_TITLE: ${{ github.event_name == 'pull_request' && steps.pr_info.outcome == 'success' && fromJson(steps.pr_info.outputs.result).title || '' }}
PR_BODY: ${{ github.event_name == 'pull_request' && steps.pr_info.outcome == 'success' && fromJson(steps.pr_info.outputs.result).body || '' }}
run: |
NEW_VERSION="${{ steps.commit.outputs.version }}"
if [ "${{ github.event_name }}" == "pull_request" ] && [ "${{ steps.pr_info.outcome }}" == "success" ]; then
{
printf '# v%s - %s\n\n' "$NEW_VERSION" "$PR_TITLE"
printf '%s\n' "$PR_BODY"
} > tag_message.txt
else
# Manual dispatch or PR info unavailable - simpler message
cat > tag_message.txt << EOF
# v${NEW_VERSION} - Manual tag update
Tag updated via manual workflow dispatch.
EOF
fi
# Store for use in subsequent steps
echo "TAG_MESSAGE_FILE=tag_message.txt" >> $GITHUB_ENV
echo "PR_TITLE=${PR_TITLE}" >> $GITHUB_ENV
- name: Push changes
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && steps.skip_check.outputs.skip == 'false')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push origin HEAD:main
- name: Create version tag and push
id: push_tag
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && steps.skip_check.outputs.skip == 'false')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
NEW_VERSION="${{ steps.commit.outputs.version }}"
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
git tag -a "v${NEW_VERSION}" -F "$TAG_MESSAGE_FILE"
git push origin "v${NEW_VERSION}"
- name: Build release name
id: release_name
if: (github.event_name == 'pull_request' && steps.skip_check.outputs.skip == 'false' || github.event_name == 'workflow_dispatch') && steps.push_tag.outcome == 'success'
run: |
VERSION="v${{ steps.push_tag.outputs.version }}"
if [ -n "$PR_TITLE" ]; then
echo "name=${VERSION} - ${PR_TITLE}" >> $GITHUB_OUTPUT
else
echo "name=${VERSION}" >> $GITHUB_OUTPUT
fi
- name: Create GitHub Release
if: (github.event_name == 'pull_request' && steps.skip_check.outputs.skip == 'false' || github.event_name == 'workflow_dispatch') && steps.push_tag.outcome == 'success'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.push_tag.outputs.version }}
name: ${{ steps.release_name.outputs.name }}
generate_release_notes: true
- name: Update stable tag
if: |
(github.event_name == 'workflow_dispatch' && inputs.update_stable ||
github.event_name == 'pull_request' && steps.skip_check.outputs.skip == 'false') &&
steps.push_tag.outcome == 'success'
run: |
# Verify version update was successful
if [ ! -f "./versioning/version.yaml" ]; then
echo "Error: version.yaml file not found. Version update may have failed."
exit 1
fi
# Capture existing tag SHA for logging
if git rev-parse --verify stable >/dev/null 2>&1; then
OLD_STABLE=$(git rev-parse stable)
echo "Backing up current stable tag ($OLD_STABLE)"
fi
# Update tag with detailed message
NEW_VERSION="${{ steps.commit.outputs.version }}"
echo "Updating stable tag to $NEW_VERSION"
git tag -fa stable -F "$TAG_MESSAGE_FILE"
git push origin stable --force
- name: Update latest tag
if: |
(github.event_name == 'workflow_dispatch' && inputs.update_latest ||
github.event_name == 'pull_request' && steps.skip_check.outputs.skip == 'false') &&
steps.push_tag.outcome == 'success'
run: |
# Verify version update was successful
if [ ! -f "./versioning/version.yaml" ]; then
echo "Error: version.yaml file not found. Version update may have failed."
exit 1
fi
# Capture existing tag SHA for logging
if git rev-parse --verify latest >/dev/null 2>&1; then
OLD_LATEST=$(git rev-parse latest)
echo "Backing up current latest tag ($OLD_LATEST)"
fi
# Update tag with detailed message
NEW_VERSION="${{ steps.commit.outputs.version }}"
echo "Updating latest tag to $NEW_VERSION"
git tag -fa latest -F "$TAG_MESSAGE_FILE"
git push origin latest --force
- name: Cleanup
if: always()
run: |
# Clean up temporary files
[ -f tag_message.txt ] && rm tag_message.txt || true
...