Skip to content

Commit 626d64e

Browse files
committed
Updated classification outputs.
1 parent fe4c913 commit 626d64e

File tree

1 file changed

+66
-57
lines changed

1 file changed

+66
-57
lines changed

.github/workflows/PrepareJob.yml

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ on:
6565
ref_kind:
6666
description: ""
6767
value: ${{ jobs.Prepare.outputs.ref_kind }}
68+
default_branch:
69+
description: ""
70+
value: ${{ jobs.Prepare.outputs.default_branch }}
6871
branch:
6972
description: ""
7073
value: ${{ jobs.Prepare.outputs.branch }}
@@ -102,6 +105,7 @@ jobs:
102105
is_nightly_tag: ${{ steps.Classify.outputs.is_nightly_tag }}
103106
is_release_tag: ${{ steps.Classify.outputs.is_release_tag }}
104107
ref_kind: ${{ steps.Classify.outputs.ref_kind }}
108+
default_branch: ${{ steps.Classify.outputs.default_branch }}
105109
branch: ${{ steps.Classify.outputs.branch }}
106110
tag: ${{ steps.Classify.outputs.tag }}
107111
version: ${{ steps.Classify.outputs.version || steps.FindPullRequest.outputs.pr_version }}
@@ -136,6 +140,8 @@ jobs:
136140
ANSI_LIGHT_BLUE=$'\x1b[94m'
137141
ANSI_NOCOLOR=$'\x1b[0m'
138142
143+
export GH_TOKEN=${{ github.token }}
144+
139145
ref="${{ github.ref }}"
140146
on_default_branch="false"
141147
on_main_branch="false"
@@ -159,74 +165,73 @@ jobs:
159165
ref_kind="branch"
160166
branch="${ref:11}"
161167
162-
printf "Get default branch name ... "
163-
defaultBranch=$(gh repo view "${{ github.repository }}" --json defaultBranchRef --jq '.defaultBranchRef.name')
168+
printf " Get default branch name ... "
169+
defaultBranch=$(gh repo view "${{ github.repository }}" --json defaultBranchRef --jq '.defaultBranchRef.name' 2>&1)
164170
if [[ $? -eq 0 ]]; then
165-
printf " ${ANSI_LIGHT_GREEN} [OK]\n"
171+
printf "${ANSI_LIGHT_GREEN} [OK]\n"
172+
173+
default_branch="${defaultBranch}"
174+
printf " default_branch=%s\n" "${default_branch}"
166175
else
167-
printf " ${ANSI_LIGHT_RED} [FAILED]\n"
176+
printf "${ANSI_LIGHT_RED} [FAILED]\n"
177+
printf " %s\n" "${default_branch}"
168178
fi
169179
170-
printf "Commit check:\n"
180+
printf "Commit checks:\n"
171181
172182
if [[ "${branch}" == "${defaultBranch}" ]]; then
173183
on_default_branch="true"
174184
175-
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then
176-
is_regular_commit="true"
177-
printf " ${ANSI_LIGHT_YELLOW}regular "
178-
else
179-
is_merge_commit="true"
180-
printf " ${ANSI_LIGHT_GREEN}merge "
181-
fi
182-
printf "commit${ANSI_NOCOLOR} on default branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${defaultBranch}"
185+
printMessage="default branch"
186+
printBranch="${defaultBranch}"
183187
fi
184188
185189
if [[ "${branch}" == "${{ inputs.main_branch }}" ]]; then
186190
on_main_branch="true"
187191
188-
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then
189-
is_regular_commit="true"
190-
printf " ${ANSI_LIGHT_YELLOW}regular "
191-
else
192-
is_merge_commit="true"
193-
printf " ${ANSI_LIGHT_GREEN}merge "
194-
fi
195-
printf "commit${ANSI_NOCOLOR} on main branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${{ inputs.main_branch }}"
192+
printMessage="main branch"
193+
printBranch="${{ inputs.main_branch }}"
196194
fi
197195
198196
if [[ "${branch}" == "${{ inputs.release_branch }}" ]]; then
199197
on_release_branch="true"
200198
201-
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then
202-
is_regular_commit="true"
203-
printf " ${ANSI_LIGHT_YELLOW}regular "
204-
else
205-
is_release_commit="true"
206-
printf " ${ANSI_LIGHT_GREEN}release "
207-
fi
208-
printf "commit${ANSI_NOCOLOR} on release branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${{ inputs.release_branch }}"
199+
printMessage="release branch"
200+
printBranch="${{ inputs.release_branch }}"
209201
fi
210202
211203
if [[ "${branch}" == "${{ inputs.development_branch }}" ]]; then
212204
on_dev_branch="true"
213205
214-
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then
215-
is_regular_commit="true"
216-
printf " ${ANSI_LIGHT_YELLOW}regular "
217-
else
218-
is_merge_commit="true"
219-
printf " ${ANSI_LIGHT_GREEN}merge "
206+
printMessage="development branch"
207+
printBranch="${{ inputs.development_branch }}"
208+
fi
209+
210+
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then
211+
is_regular_commit="true"
212+
printf " ${ANSI_LIGHT_YELLOW}regular commit${ANSI_NOCOLOR} on ${printMessage} ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${printBranch}"
213+
else
214+
is_merge_commit="true"
215+
printf " ${ANSI_LIGHT_GREEN}merge commit${ANSI_NOCOLOR} on ${printMessage} ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${printBranch}"
216+
217+
printf " Merge kind "
218+
if [[ "${on_main_branch}" == "true" ]]; then
219+
is_release_commit="true"
220+
printf "${ANSI_LIGHT_GREEN}[RELEASE]${ANSI_NOCOLOR}\n"
221+
elif [[ "${on_version_branch}" == "true" ]]; then
222+
is_release_commit="true"
223+
printf "${ANSI_LIGHT_GREEN}[RELEASE]${ANSI_NOCOLOR}\n"
224+
elif [[ "${on_release_branch}" == "true" ]]; then
225+
is_prerelease_commit="true"
226+
printf "${ANSI_LIGHT_YELLOW}[PRERELEASE]${ANSI_NOCOLOR}\n"
220227
fi
221-
printf "commit${ANSI_NOCOLOR} on development branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${{ inputs.development_branch }}"
222228
fi
223229
elif [[ "${ref:0:10}" == "refs/tags/" ]]; then
224230
printf "${ANSI_LIGHT_GREEN}[TAG]\n"
225231
ref_kind="tag"
226232
tag="${ref:10}"
227233
228-
printf "Tag check:\n"
229-
234+
printf "Tag checks:\n"
230235
printf " Check if tag is on main branch '%s' ... " "${{ inputs.main_branch }}"
231236
git branch --remotes --contains $(git rev-parse --verify "tags/${tag}~0") | grep "origin/${{ inputs.main_branch }}" > /dev/null
232237
if [[ $? -eq 0 ]]; then
@@ -262,7 +267,7 @@ jobs:
262267
pr_number=${ref:11}
263268
pr_number=${pr_number%%/*}
264269
265-
printf "Pull Request check:\n"
270+
printf "Pull Request checks:\n"
266271
printf " Number: %s\n" "${pr_number}"
267272
else
268273
printf "${ANSI_LIGHT_RED}[UNKNOWN]\n"
@@ -271,6 +276,7 @@ jobs:
271276
exit 1
272277
fi
273278
279+
printf "\nWriting output variables ...\n"
274280
tee --append "${GITHUB_OUTPUT}" <<EOF
275281
on_default_branch=${on_default_branch}
276282
on_main_branch=${on_main_branch}
@@ -282,6 +288,7 @@ jobs:
282288
is_nightly_tag=${is_nightly_tag}
283289
is_release_tag=${is_release_tag}
284290
ref_kind=${ref_kind}
291+
default_branch=${default_branch}
285292
branch=${branch}
286293
tag=${tag}
287294
pr_number=${pr_number}
@@ -361,21 +368,23 @@ jobs:
361368
362369
- name: Debug
363370
run: |
364-
printf "on_main_branch: %s\n" "${{ steps.Classify.outputs.on_main_branch }}"
365-
printf "on_dev_branch: %s\n" "${{ steps.Classify.outputs.on_dev_branch }}"
366-
printf "on_release_branch: %s\n" "${{ steps.Classify.outputs.on_release_branch }}"
367-
printf "is_regular_commit: %s\n" "${{ steps.Classify.outputs.is_regular_commit }}"
368-
printf "is_merge_commit: %s\n" "${{ steps.Classify.outputs.is_merge_commit }}"
369-
printf "is_release_commit: %s\n" "${{ steps.Classify.outputs.is_release_commit }}"
370-
printf "is_nightly_tag: %s\n" "${{ steps.Classify.outputs.is_nightly_tag }}"
371-
printf "is_release_tag: %s\n" "${{ steps.Classify.outputs.is_release_tag }}"
372-
printf "ref_kind: %s\n" "${{ steps.Classify.outputs.ref_kind }}"
373-
printf "branch: %s\n" "${{ steps.Classify.outputs.branch }}"
374-
printf "tag: %s\n" "${{ steps.Classify.outputs.tag }}"
375-
printf "version: %s\n" "${{ steps.Classify.outputs.version || steps.FindPullRequest.outputs.pr_version }}"
376-
printf " from tag: %s\n" "${{ steps.Classify.outputs.version }}"
377-
printf " from pr: %s\n" "${{ steps.FindPullRequest.outputs.pr_version }}"
378-
printf "pr title: %s\n" "${{ steps.FindPullRequest.outputs.pr_title }}"
379-
printf "pr number: %s\n" "${{ steps.Classify.outputs.pr_number || steps.FindPullRequest.outputs.pr_number }}"
380-
printf " from merge: %s\n" "${{ steps.Classify.outputs.pr_number }}"
381-
printf " from pr: %s\n" "${{ steps.FindPullRequest.outputs.pr_number }}"
371+
printf "on_default_branch: %s\n" "${{ steps.Classify.outputs.on_default_branch }}"
372+
printf "on_main_branch: %s\n" "${{ steps.Classify.outputs.on_main_branch }}"
373+
printf "on_release_branch: %s\n" "${{ steps.Classify.outputs.on_release_branch }}"
374+
printf "on_dev_branch: %s\n" "${{ steps.Classify.outputs.on_dev_branch }}"
375+
printf "is_regular_commit: %s\n" "${{ steps.Classify.outputs.is_regular_commit }}"
376+
printf "is_merge_commit: %s\n" "${{ steps.Classify.outputs.is_merge_commit }}"
377+
printf "is_release_commit: %s\n" "${{ steps.Classify.outputs.is_release_commit }}"
378+
printf "is_nightly_tag: %s\n" "${{ steps.Classify.outputs.is_nightly_tag }}"
379+
printf "is_release_tag: %s\n" "${{ steps.Classify.outputs.is_release_tag }}"
380+
printf "ref_kind: %s\n" "${{ steps.Classify.outputs.ref_kind }}"
381+
printf "default_branch: %s\n" "${{ steps.Classify.outputs.default_branch }}"
382+
printf "branch: %s\n" "${{ steps.Classify.outputs.branch }}"
383+
printf "tag: %s\n" "${{ steps.Classify.outputs.tag }}"
384+
printf "version: %s\n" "${{ steps.Classify.outputs.version || steps.FindPullRequest.outputs.pr_version }}"
385+
printf " from tag: %s\n" "${{ steps.Classify.outputs.version }}"
386+
printf " from pr: %s\n" "${{ steps.FindPullRequest.outputs.pr_version }}"
387+
printf "pr title: %s\n" "${{ steps.FindPullRequest.outputs.pr_title }}"
388+
printf "pr number: %s\n" "${{ steps.Classify.outputs.pr_number || steps.FindPullRequest.outputs.pr_number }}"
389+
printf " from merge: %s\n" "${{ steps.Classify.outputs.pr_number }}"
390+
printf " from pr: %s\n" "${{ steps.FindPullRequest.outputs.pr_number }}"

0 commit comments

Comments
 (0)