-
Notifications
You must be signed in to change notification settings - Fork 143
210 lines (179 loc) · 7.91 KB
/
flow-trigger-release.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
##
# Copyright (C) 2025 Hedera Hashgraph, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##
name: "[Main] Create New Release"
on:
workflow_dispatch:
inputs:
build_number:
description: "Build Number (ex: 43 = build_00043)"
type: string
required: true
dry-run-enabled:
description: "Perform Dry Run"
type: boolean
required: false
default: false
defaults:
run:
shell: bash
permissions:
id-token: write
contents: read
actions: read
jobs:
create-new-release:
name: Create New Release
runs-on: network-node-linux-medium
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit
- name: Process, Validate, and Pad Build Input
id: validate
run: |
echo "The input is ${{ inputs.build_number }}"
if ! [[ "${{ inputs.build_number }}" =~ ^[0-9]+$ ]]; then
echo "Input is not a valid integer"
exit 1
fi
echo "Input is a valid integer: $(( ${{ inputs.build_number }} ))"
# 5-digit padding
padded_number=$(printf "%05d" ${{ inputs.build_number }})
echo "Padded number is: $padded_number"
# Add "build_" prefix to the padded number
build_tag="build-$padded_number"
echo "Prefixed number is: $build_tag"
# Export to Github output and Github summary
echo "BUILD_TAG=$build_tag" >> ${GITHUB_OUTPUT}
printf "Build Tag to Release: ${BUILD_TAG}" >> ${GITHUB_STEP_SUMMARY}
- name: Checkout Code
id: checkout_code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: "0"
ref: ${{ steps.validate.outputs.BUILD_TAG }}
token: ${{ secrets.GH_ACCESS_TOKEN }}
- name: Display Current Branch or Tag
run: |
# Check if it's a tag
if git describe --exact-match --tags >/dev/null 2>&1; then
echo "Checked out tag: $(git describe --exact-match --tags)"
else
echo "Checked out branch: $(git symbolic-ref --short HEAD)"
fi
- name: Import GPG Key
uses: step-security/ghaction-import-gpg@6c8fe4d0126a59d57c21f87c9ae5dd3451fa3cca # v6.1.0
with:
git_commit_gpgsign: true
git_tag_gpgsign: true
git_user_signingkey: true
gpg_private_key: ${{ secrets.SVCS_GPG_KEY_CONTENTS }}
passphrase: ${{ secrets.SVCS_GPG_KEY_PASSPHRASE }}
- name: Setup Node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20
- name: Calculate Temporary Semantic Release Branch Name
id: branch_name
run: |
echo "BRANCH_NAME=temp/${{ steps.validate.outputs.BUILD_TAG }}" >> ${GITHUB_OUTPUT}
echo "The temp branch name is: ${BRANCH_NAME}"
printf "The temp branch name for release is: ${{ BRANCH_NAME }}" >> ${GITHUB_STEP_SUMMARY}
- name: Create a Temporary Semantic Release Branch
run: |
echo "Going to run the following command:"
echo "git checkout -b ${{ steps.branch_name.outputs.BRANCH_NAME }}"
git checkout -b ${{ steps.branch_name.outputs.BRANCH_NAME }}
- name: Echo Current Branch Name
run: |
current_branch=$(git symbolic-ref --short HEAD)
echo "Currently on branch: $current_branch"
- name: Push Temporary Branch to Origin
run: |
echo "Pushing branch to origin:"
git push --set-upstream origin ${{ steps.branch_name.outputs.BRANCH_NAME }}
- name: Git-Semver Setup Action
uses: DJ-BBot/setup-git-semver@7ede9a8b0c0f4cfff14e9b0a8771dbc546f2b76b # v1.0.1
- name: Identify Current Version Number
run: |
echo "Find the current version number"
current_version=$(git-semver latest)
echo "Current version is: ${current_version}"
# IF HIERO/HEDERA TRANSITIONS TO A MAJOR RELEASE NUMBER (1.0.0+)
# stable = false WILL NO LONGER BE VALID
- name: Compute Next Version Number
id: next_version
run: |
echo "Compute next version number using git-semver"
echo "next_release=$(git-semver next --stable=false)" >> ${GITHUB_OUTPUT}
echo "Next release version is: ${next_release}"
#printf "Next Release Version Number: ${next_release}" >> ${GITHUB_STEP_SUMMARY}
- name: Apply Tag with Calculated Next Version
run: |
echo "Applying computed version tag"
git tag -a v${{ steps.next_version.outputs.next_release }} -m "v${{ steps.next_version.outputs.next_release }}"
echo "Applied tag v${{ steps.next_version.outputs.next_release }}"
printf "Version Tag Applied: v${{ steps.next_version.outputs.next_release }}" >> ${GITHUB_STEP_SUMMARY}
- name: Identify Current Version Number After Tagging
run: |
echo "Find the current version number after we applied the new tag"
current_version=$(git-semver latest)
echo "Current version is: ${current_version}"
echo "Should match version we just applied: ${{ steps.next_version.outputs.next_release }}"
- name: Create Release Notes with Conventional Commits
run: |
echo git-semver log --conventional-commits ${{ steps.next_version.outputs.next_release }}
git-semver log --conventional-commits ${{ steps.next_version.outputs.next_release }}
- name: Create Release Notes with Markdown
run: |
echo git-semver log --markdown ${{ steps.next_version.outputs.next_release }}
git-semver log --markdown ${{ steps.next_version.outputs.next_release }}
- name: Clean Up git-semver
run: |
echo "Deleting git-semver directory"
rm -rf git-semver
echo "Successfully removed git-semver directory"
- name: View Status After Running Semantic Release
run: git status
# TODO: Remove this delete step before merging to mainline
- name: Delete Created Tag
if: always()
run: |
git tag --delete v${{ steps.next_version.outputs.next_release }}
- name: Ensure Branch Not in Use and Delete Worktree
if: always()
run: |
# Switch to main
git checkout main
# Check if the branch is associated with a worktree and remove the worktree if it exists
worktree_path=$(git worktree list | grep ${{ steps.branch_name.outputs.BRANCH_NAME }} || true)
if [ -n "$worktree_path" ]; then
echo "Removing worktree at $worktree_path"
git worktree remove "$worktree_path"
else
echo "No worktree found for branch ${{ steps.branch_name.outputs.BRANCH_NAME }}"
fi
- name: Delete the Temporary Semantic Release Branch
if: always()
run: |
echo "Deleting the temporary semantic release branch"
echo "Deleting local branch now:"
git branch -d ${{ steps.branch_name.outputs.BRANCH_NAME }}
printf "Deleted Temporary Branch from Local Runner\n" >> ${GITHUB_STEP_SUMMARY}
echo "Deleting remote branch now:"
git push -d origin ${{ steps.branch_name.outputs.BRANCH_NAME }}
printf "Deleted Temporary Branch from Remote" >> ${GITHUB_STEP_SUMMARY}