-
Notifications
You must be signed in to change notification settings - Fork 147
343 lines (306 loc) · 13.2 KB
/
node-zxcron-release-branching.yaml
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# SPDX-License-Identifier: Apache-2.0
name: "ZXCron: Automatic Release Branching"
on:
schedule:
- cron: "*/10 * * * *"
workflow_dispatch:
defaults:
run:
shell: bash
permissions:
contents: write
env:
GITHUB_CLI_VERSION: 2.21.2
YQ_CLI_VERSION: 4.30.8
WORKFLOW_CONFIG_FILE: ".github/workflows/config/node-release.yaml"
RELEASE_BRANCH_CHECK_SCRIPT: ".github/workflows/support/scripts/release-branch-check.sh"
jobs:
check-trigger:
name: Check Trigger Conditions
runs-on: hiero-network-node-linux-small-scheduler
if: ${{ !github.event.workflow_dispatch.repository.fork }}
outputs:
triggered: ${{ steps.evaluate.outputs.triggered }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
egress-policy: audit
- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Read Trigger Time
id: time
uses: mikefarah/yq@8bf425b4d1344db7cd469a8d10a390876e0c77fd # v4.45.1
with:
cmd: yq '.release.branching.execution.time' '${{ env.WORKFLOW_CONFIG_FILE }}'
- name: Evaluate Trigger
id: evaluate
env:
REQUESTED_TIME: ${{ steps.time.outputs.result }}
run: |
set -x
if [[ -z "${REQUESTED_TIME}" ]]; then
echo "::error file=${WORKFLOW_CONFIG_FILE},title=Configuration Error::The release branch execution time must be specified and may not be omitted."
exit 1
fi
if ! date --date="${REQUESTED_TIME} today" +%s >/dev/null 2>&1; then
echo "::error file=${WORKFLOW_CONFIG_FILE},title=Configuration Error::The release branch execution time of '${REQUESTED_TIME}' is invalid."
exit 1
fi
BEGIN_TRIGGER_EPOCH="$(date --date="${REQUESTED_TIME} today" +%s)"
END_TRIGGER_EPOCH="$(date --date="${REQUESTED_TIME} today +2 hours" +%s)"
CURRENT_EPOCH="$(date +%s)"
TRIGGERED="false"
[[ "${CURRENT_EPOCH}" -ge "${BEGIN_TRIGGER_EPOCH}" && "${CURRENT_EPOCH}" -le "${END_TRIGGER_EPOCH}" ]] && TRIGGERED="true"
echo "triggered=${TRIGGERED}" >> "${GITHUB_OUTPUT}"
check-branch:
name: Check Branching Conditions
runs-on: hiero-network-node-linux-small-scheduler
needs:
- check-trigger
outputs:
schedule-trigger: ${{ steps.branch-creation.outputs.schedule-trigger }}
branch-create: ${{ steps.branch-creation.outputs.branch-create }}
branch-name: ${{ steps.branch-creation.outputs.branch-name }}
tag-create: ${{ steps.branch-creation.outputs.tag-create }}
tag-name: ${{ steps.branch-creation.outputs.tag-name }}
env:
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
if: ${{ needs.check-trigger.outputs.triggered == 'true' && !cancelled() }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
egress-policy: audit
- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Branch Creation Check
id: branch-creation
run: bash "${{ github.workspace }}/${{ env.RELEASE_BRANCH_CHECK_SCRIPT }}"
create-branch:
name: Create Release Branch
runs-on: hiero-network-node-linux-small-scheduler
needs:
- check-branch
env:
GITHUB_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
if: ${{ needs.check-branch.outputs.branch-create == 'true' && !cancelled() }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
egress-policy: audit
- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
token: ${{ secrets.GH_ACCESS_TOKEN }}
- name: Create Branch
id: branch
uses: peterjgrainger/action-create-branch@10c7d268152480ae859347db45dc69086cef1d9c # v3.0.0
with:
branch: refs/heads/${{ needs.check-branch.outputs.branch-name }}
- name: Compute Commit Identifier
id: commit
run: echo "short-id=$(echo -n "${{ github.sha }}" | tr -d '[:space:]' | cut -c1-8)" >> "${GITHUB_OUTPUT}"
- name: Send Slack Notification
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
with:
webhook: ${{ secrets.SLACK_RELEASE_WEBHOOK }}
webhook-type: incoming-webhook
payload-templated: true
payload: |
{
"attachments": [
{
"color": "#7647cd",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":evergreen_tree: Hedera Services - Automatic Release Branching",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Branch Name:*"
},
{
"type": "mrkdwn",
"text": "*Source Branch:*"
},
{
"type": "mrkdwn",
"text": "<${{ github.server_url }}/${{ github.repository }}/tree/${{ needs.check-branch.outputs.branch-name }}|${{ needs.check-branch.outputs.branch-name }}>"
},
{
"type": "mrkdwn",
"text": "<${{ github.server_url }}/${{ github.repository }}/tree/${{ github.ref_name }}|${{ github.ref_name }}>"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Source Commit*: \n<${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|${{ steps.commit.outputs.short-id }}>"
}
},
{
"type": "divider"
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": ":watch: Initiated by scheduled repository event at date & time: `${{ needs.check-branch.outputs.schedule-trigger }} UTC`"
}
]
}
]
}
]
}
create-tag:
name: Create Release Tag
runs-on: hiero-network-node-linux-medium
needs:
- check-branch
- create-branch
if: ${{ needs.check-branch.outputs.tag-create == 'true' && needs.create-branch.result == 'success' && !cancelled() }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
egress-policy: audit
- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ needs.check-branch.outputs.branch-name }}
token: ${{ secrets.GH_ACCESS_TOKEN }}
fetch-depth: 0
- name: Setup Java
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
with:
distribution: temurin
java-version: 21.0.6
- name: Install Semantic Version Tools
run: |
echo "::group::Download SemVer Binary"
sudo curl -L -o /usr/local/bin/semver https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver
echo "::endgroup::"
echo "::group::Change SemVer Binary Permissions"
sudo chmod -v +x /usr/local/bin/semver
echo "::endgroup::"
echo "::group::Show SemVer Binary Version Info"
semver --version
echo "::endgroup::"
- name: Import GPG key for commit signoff
id: gpg_import
uses: step-security/ghaction-import-gpg@6c8fe4d0126a59d57c21f87c9ae5dd3451fa3cca # v6.1.0
with:
gpg_private_key: ${{ secrets.PLATFORM_GPG_KEY_CONTENTS }}
passphrase: ${{ secrets.PLATFORM_GPG_KEY_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_tag_gpgsign: true
git_config_global: true
- name: Calculate Version
id: version
run: |
VALID_VERSION="$(semver validate "${{ needs.check-branch.outputs.tag-name }}" | tr -d '[:space:]')"
if [[ "${VALID_VERSION}" != "valid" ]]; then
echo "::error title=Invalid Version::The supplied tag name (${{ needs.check-branch.outputs.tag-name }}) is not a valid semantic version number."
exit 1
fi
REL_PART="$(semver get release "${{ needs.check-branch.outputs.tag-name }}")"
PRE_PART="$(semver get prerel "${{ needs.check-branch.outputs.tag-name }}")"
VERSION="${REL_PART}"
[[ -n "${PRE_PART}" ]] && VERSION="${VERSION}-${PRE_PART}"
echo "number=${VERSION}" >> "${GITHUB_OUTPUT}"
- name: Update Software Version
run: ./gradlew versionAsSpecified -PnewVersion=${{ steps.version.outputs.number }}
- name: Commit Version Changes
id: git-commit
uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9.1.4
with:
author_name: ${{ secrets.PLATFORM_GIT_USER_NAME }}
author_email: ${{ secrets.PLATFORM_GIT_USER_EMAIL }}
commit: --signoff --gpg-sign
tag: "v${{ steps.version.outputs.number }} -f -m '[Automated Release] Hedera Node v${{ steps.version.outputs.number }}'"
message: "[Automated Release] Hedera Node v${{ steps.version.outputs.number }}"
- name: Compute Commit Identifier
id: commit
run: |
echo "id=$(echo -n "${{ steps.git-commit.outputs.commit_long_sha }}" | tr -d '[:space:]')" >> "${GITHUB_OUTPUT}"
echo "short-id=$(echo -n "${{ steps.git-commit.outputs.commit_long_sha }}" | tr -d '[:space:]' | cut -c1-8)" >> "${GITHUB_OUTPUT}"
- name: Send Slack Notification
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
with:
webhook: ${{ secrets.SLACK_RELEASE_WEBHOOK }}
webhook-type: incoming-webhook
payload-templated: "true"
payload: |
{
"attachments": [
{
"color": "#16bec7",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":ideograph_advantage: Hedera Services - Automatic Release Tagging",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Tag Name:*"
},
{
"type": "mrkdwn",
"text": "*Source Branch:*"
},
{
"type": "mrkdwn",
"text": "<${{ github.server_url }}/hiero-ledger/hiero-consensus-node/tree/v${{ steps.version.outputs.number }}|v${{ steps.version.outputs.number }}>"
},
{
"type": "mrkdwn",
"text": "<${{ github.server_url }}/hiero-ledger/hiero-consensus-node/tree/${{ needs.check-branch.outputs.branch-name }}|${{ needs.check-branch.outputs.branch-name }}>"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Source Commit*: \n<${{ github.server_url }}/${{ github.repository }}/commit/${{ steps.commit.outputs.id }}|${{ steps.commit.outputs.short-id }}>"
}
},
{
"type": "divider"
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": ":watch: Initiated by scheduled repository event at date & time: `${{ needs.check-branch.outputs.schedule-trigger }} UTC`"
}
]
}
]
}
]
}