1
+ name : Keyfactor Bootstrap Workflow
2
+
3
+ on :
4
+ workflow_dispatch :
5
+ pull_request :
6
+ types : [ opened, closed, synchronize, edited, reopened ]
7
+ push :
8
+ create :
9
+ branches :
10
+ - ' release-*.*'
11
+
12
+ jobs :
13
+ get-versions :
14
+ runs-on : ubuntu-latest
15
+ outputs :
16
+ PR_BASE_REF : ${{ steps.set-outputs.outputs.PR_BASE_REF }}
17
+ PR_COMMIT_SHA : ${{ steps.set-outputs.outputs.PR_COMMIT_SHA }}
18
+ GITHUB_SHA : ${{ steps.set-outputs.outputs.GITHUB_SHA }}
19
+ PR_BASE_TAG : ${{ steps.set-outputs.outputs.PR_BASE_TAG }}
20
+ IS_FULL_RELEASE : ${{ steps.set-outputs.outputs.IS_FULL_RELEASE }}
21
+ IS_PRE_RELEASE : ${{ steps.set-outputs.outputs.IS_PRE_RELEASE }}
22
+ INC_LEVEL : ${{ steps.set-outputs.outputs.INC_LEVEL }}
23
+ IS_RELEASE_BRANCH : ${{ steps.set-outputs.outputs.IS_RELEASE_BRANCH }}
24
+ IS_HOTFIX : ${{ steps.set-outputs.outputs.IS_HOTFIX }}
25
+ LATEST_TAG : ${{ steps.set-outputs.outputs.LATEST_TAG }}
26
+ NEXT_VERSION : ${{ steps.set-outputs.outputs.NEW_PKG_VERSION }}
27
+
28
+ steps :
29
+ - name : Check out the code
30
+ uses : actions/checkout@v3
31
+ with :
32
+ token : ${{ secrets.V2BUILDTOKEN}}
33
+
34
+ - name : Display base.ref from Pull Request
35
+ if : github.event_name == 'pull_request'
36
+ id : display-from-pr
37
+ run : |
38
+ echo "Event: ${{ github.event_name }}" | tee -a $GITHUB_STEP_SUMMARY
39
+ echo "Event Action: ${{ github.event.action }}" | tee -a $GITHUB_STEP_SUMMARY
40
+ echo "PR_BASE_REF=${{ github.event.pull_request.base.ref }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
41
+ echo "PR_STATE=${{ github.event.pull_request.state }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
42
+ echo "PR_MERGED=${{ github.event.pull_request.merged }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
43
+ echo "PR_COMMIT_SHA=${{ github.event.pull_request.merge_commit_sha }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
44
+ echo "GITHUB_SHA=${{ github.sha }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
45
+ baseref="${{ github.event.pull_request.base.ref }}"
46
+ basetag="${baseref#release-}"
47
+ echo "PR_BASE_TAG=$basetag" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
48
+
49
+ - name : Display base_ref from Push Event
50
+ if : github.event_name == 'push'
51
+ id : display-from-push
52
+ run : |
53
+ echo "Branch Ref: ${{ github.ref }}" | tee -a $GITHUB_STEP_SUMMARY
54
+ echo "Event: ${{ github.event_name }}" | tee -a $GITHUB_STEP_SUMMARY
55
+ echo "github.sha: ${{ github.sha }}" | tee -a $GITHUB_STEP_SUMMARY
56
+
57
+ - name : Find Latest Tag
58
+ if : github.event_name == 'pull_request'
59
+ id : find-latest-tag
60
+ run : |
61
+ prbasetag="${{env.PR_BASE_TAG}}"
62
+ git fetch --tags
63
+ if [[ -n `git tag` ]]; then
64
+ echo "Setting vars"
65
+ allBranchTags=`git tag --sort=-v:refname | grep "^$prbasetag" || echo ""`
66
+ allRepoTags=`git tag --sort=-v:refname`
67
+ branchTagBase=`git tag --sort=-v:refname | grep "^$prbasetag" | grep -o '^[0-9.]*' | head -n 1 || echo ""`
68
+ latestTagBase=`git tag --sort=-v:refname | grep -o '^[0-9.]*' | head -n 1`
69
+ latestBranchTag=`git tag --sort=-v:refname | grep "^$prbasetag" | grep "^$branchTagBase" | head -n 1 || echo ""`
70
+ latestReleasedTag=`git tag --sort=-v:refname | grep "^$prbasetag" | grep "^$branchTagBase$" | head -n 1 || echo ""`
71
+
72
+ # If the *TagBase values are not found in the list of tags, it means no final release was produced, and the latest*Tag vars will be empty
73
+ if [[ -z "$latestReleasedTag" ]]; then
74
+ latestTag="$latestBranchTag"
75
+ else
76
+ latestTag="$latestReleasedTag"
77
+ fi
78
+ echo "LATEST_TAG=${latestTag}" | tee -a "$GITHUB_ENV"
79
+
80
+ if [[ "$latestTagBase" == *"$branchTagBase" ]]; then
81
+ hf="False"
82
+ else
83
+ hf="True"
84
+ fi
85
+
86
+ # The intention is to use this to set the make_latest:false property when
87
+ # dispatching the create-release action, but it is not *yet* a configurable option
88
+ echo "IS_HOTFIX=$hf" | tee -a "$GITHUB_ENV"
89
+ else
90
+ echo "No tags exist in this repo"
91
+ echo "LATEST_TAG=" | tee -a "$GITHUB_ENV"
92
+ fi
93
+ - name : Set Outputs
94
+ id : set-outputs
95
+ run : |
96
+ echo "PR_BASE_REF=${{ env.PR_BASE_REF }}" | tee -a "$GITHUB_OUTPUT"
97
+ echo "PR_STATE=${{ env.PR_STATE }}"
98
+ echo "PR_MERGED=${{ env.PR_MERGED }}"
99
+ if [[ "${{ env.PR_STATE }}" == "closed" && "${{ env.PR_MERGED }}" == "true" && "${{ env.PR_COMMIT_SHA }}" == "${{ env.GITHUB_SHA }}" ]]; then
100
+ echo "IS_FULL_RELEASE=True" | tee -a "$GITHUB_OUTPUT"
101
+ echo "INC_LEVEL=patch" | tee -a "$GITHUB_OUTPUT"
102
+ fi
103
+ if [[ "${{ env.PR_STATE }}" == "open" ]]; then
104
+ echo "IS_PRE_RELEASE=True" | tee -a "$GITHUB_OUTPUT" | tee -a "$GITHUB_ENV"
105
+ echo "INC_LEVEL=prerelease" | tee -a "$GITHUB_OUTPUT"
106
+ fi
107
+ if [[ "${{ env.PR_BASE_REF }}" == "release-"* ]]; then
108
+ echo "IS_RELEASE_BRANCH=True" | tee -a "$GITHUB_OUTPUT" | tee -a "$GITHUB_ENV"
109
+ fi
110
+ echo "PR_COMMIT_SHA=${{ env.PR_COMMIT_SHA }}" | tee -a "$GITHUB_OUTPUT"
111
+ echo "GITHUB_SHA=${{ env.GITHUB_SHA }}" | tee -a "$GITHUB_OUTPUT"
112
+ echo "PR_BASE_TAG=${{ env.PR_BASE_TAG }}" | tee -a "$GITHUB_OUTPUT"
113
+ echo "IS_HOTFIX=${{ env.IS_HOTFIX }}" | tee -a "$GITHUB_OUTPUT"
114
+ echo "LATEST_TAG=${{ env.LATEST_TAG }}" | tee -a "$GITHUB_OUTPUT"
115
+
116
+ check-package-version :
117
+ needs : get-versions
118
+ if : github.event_name == 'pull_request' && needs.get-versions.outputs.IS_RELEASE_BRANCH == 'True'
119
+ outputs :
120
+ release_version : ${{ steps.create_release.outputs.current_tag }}
121
+ release_url : ${{ steps.create_release.outputs.upload_url }}
122
+ update_version : ${{ steps.check_version.outputs.update_version }}
123
+ next_version : ${{ steps.set-semver-info.outputs.new_version }}
124
+ runs-on : ubuntu-latest
125
+ steps :
126
+ - name : Check out the code
127
+ uses : actions/checkout@v3
128
+ - run : |
129
+ echo "INC_LEVEL=${{ needs.get-versions.outputs.INC_LEVEL}}"
130
+ - name : Check if initial release
131
+ if : needs.get-versions.outputs.LATEST_TAG == ''
132
+ run : |
133
+ echo "INITIAL_VERSION=${{needs.get-versions.outputs.PR_BASE_TAG}}.0-rc.0" | tee -a "$GITHUB_STEP_SUMMARY" | tee -a "$GITHUB_ENV"
134
+ echo "MANUAL_VERSION=${{needs.get-versions.outputs.PR_BASE_TAG}}.0-rc.0" | tee -a "$GITHUB_ENV"
135
+ - name : Set semver info
136
+ id : set-semver-info
137
+ if : needs.get-versions.outputs.LATEST_TAG != ''
138
+ uses : fiddlermikey/action-bump-semver@main
139
+ with :
140
+ current_version : ${{ needs.get-versions.outputs.LATEST_TAG}}
141
+ level : ${{ needs.get-versions.outputs.INC_LEVEL}}
142
+ preID : rc
143
+ - name : Show next sem-version
144
+ if : needs.get-versions.outputs.LATEST_TAG != ''
145
+ run : |
146
+ echo "MANUAL_VERSION=${{ steps.set-semver-info.outputs.new_version }}" > "$GITHUB_ENV"
147
+ - run : |
148
+ echo "Next version: ${{ env.MANUAL_VERSION }}" | tee -a "$GITHUB_STEP_SUMMARY"
149
+
150
+ - name : Get Package Version
151
+ id : get-pkg-version
152
+ run : |
153
+ pwd
154
+ ls -la
155
+ echo "CURRENT_PKG_VERSION=$(cat pkg/version/version.go | grep 'const VERSION' | awk '{print $NF}' | tr -d '"')" | tee -a "$GITHUB_ENV"
156
+ - name : Compare package version
157
+ id : check_version
158
+ run : |
159
+ if [ "${{ env.CURRENT_PKG_VERSION }}" != "${{ env.MANUAL_VERSION }}" ]; then
160
+ echo "Updating version in version.go"
161
+ echo "update_version=true" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
162
+ echo "update_version=true" | tee -a "$GITHUB_STEP_SUMMARY"
163
+ else
164
+ echo "Versions match, no update needed"
165
+ echo "update_version=false" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
166
+ echo "update_version=false" | tee -a $GITHUB_STEP_SUMMARY
167
+ fi
168
+ env :
169
+ UPDATE_VERSION : ${{ steps.check_version.outputs.update_version }}
170
+
171
+ - name : Set Outputs
172
+ id : set-outputs
173
+ if : needs.get-versions.outputs.LATEST_TAG != ''
174
+ run : |
175
+ echo "UPDATE_VERSION=${{ steps.check_version.outputs.update_version }}" | tee -a "$GITHUB_OUTPUT"
176
+ echo "CURRENT_PKG_VERSION=${{ env.CURRENT_PKG_VERSION }}" | tee -a "$GITHUB_OUTPUT"
177
+ echo "MANUAL_VERSION=${{ env.MANUAL_VERSION }}" | tee -a "$GITHUB_OUTPUT"
178
+ echo "NEW_PKG_VERSION=${{ env.MANUAL_VERSION }}" | tee -a "$GITHUB_OUTPUT"
179
+
180
+ update-pkg-version :
181
+ needs :
182
+ - check-package-version
183
+ runs-on : ubuntu-latest
184
+
185
+ steps :
186
+ - name : Checkout repository
187
+ uses : actions/checkout@v3
188
+ with :
189
+ token : ${{ secrets.V2BUILDTOKEN}}
190
+ - name : No Update
191
+ if : ${{ needs.check-package-version.outputs.update_version != 'true' }}
192
+ run : |
193
+ echo "Versions match, no update needed"
194
+ exit 0
195
+
196
+ - name : Commit to PR branch
197
+ id : commit-version
198
+ if : ${{ needs.check-package-version.outputs.update_version == 'true' }}
199
+ env :
200
+ AUTHOR_EMAIL : keyfactor@keyfactor.github.io
201
+ AUTHOR_NAME : Keyfactor Robot
202
+ GITHUB_TOKEN : ${{ secrets.V2BUILDTOKEN}}
203
+ run : |
204
+ git remote -v
205
+ echo "Checking out ${{ github.head_ref }}"
206
+ git fetch
207
+ echo "git checkout -b ${{ github.head_ref }}"
208
+ git checkout -b ${{ github.head_ref }}
209
+ git reset --hard origin/${{ github.head_ref }}
210
+ sed -i "s/const VERSION = .*/const VERSION = \"${{ needs.check-package-version.outputs.next_version }}\"/" pkg/version/version.go
211
+ git add pkg/version/version.go
212
+ git config --global user.email "${{ env.AUTHOR_EMAIL }}"
213
+ git config --global user.name "${{ env.AUTHOR_NAME }}"
214
+ git commit -m "Bump package version to ${{ needs.check-package-version.outputs.next_version }}"
215
+ git push --set-upstream origin ${{ github.head_ref }}
216
+ echo "Version mismatch! Please create a new pull request with the updated version."
217
+ exit 1
218
+
219
+ call-starter-workflow :
220
+ uses : keyfactor/actions/.github/workflows/starter.yml@v2
221
+ needs : update-pkg-version
222
+ secrets :
223
+ token : ${{ secrets.V2BUILDTOKEN}}
224
+ APPROVE_README_PUSH : ${{ secrets.APPROVE_README_PUSH}}
225
+ gpg_key : ${{ secrets.KF_GPG_PRIVATE_KEY }}
226
+ gpg_pass : ${{ secrets.KF_GPG_PASSPHRASE }}
0 commit comments