This commit is contained in:
Patrick Lehmann
2025-10-01 15:16:07 +02:00
committed by GitHub
2 changed files with 127 additions and 77 deletions

View File

@@ -62,9 +62,15 @@ on:
is_release_tag: is_release_tag:
description: "" description: ""
value: ${{ jobs.Prepare.outputs.is_release_tag }} value: ${{ jobs.Prepare.outputs.is_release_tag }}
has_submodules:
description: ""
value: ${{ jobs.Prepare.outputs.has_submodules }}
ref_kind: ref_kind:
description: "" description: ""
value: ${{ jobs.Prepare.outputs.ref_kind }} value: ${{ jobs.Prepare.outputs.ref_kind }}
default_branch:
description: ""
value: ${{ jobs.Prepare.outputs.default_branch }}
branch: branch:
description: "" description: ""
value: ${{ jobs.Prepare.outputs.branch }} value: ${{ jobs.Prepare.outputs.branch }}
@@ -86,6 +92,15 @@ on:
# pr_mergedat: # pr_mergedat:
# description: "" # description: ""
# value: ${{ jobs.Prepare.outputs.pr_mergedat }} # value: ${{ jobs.Prepare.outputs.pr_mergedat }}
git_submodule_count:
description: ""
value: ${{ jobs.Prepare.outputs.git_submodule_count }}
git_submodule_names:
description: ""
value: ${{ jobs.Prepare.outputs.git_submodule_names }}
git_submodule_paths:
description: ""
value: ${{ jobs.Prepare.outputs.git_submodule_paths }}
jobs: jobs:
Prepare: Prepare:
@@ -101,13 +116,18 @@ jobs:
is_release_commit: ${{ steps.Classify.outputs.is_release_commit }} is_release_commit: ${{ steps.Classify.outputs.is_release_commit }}
is_nightly_tag: ${{ steps.Classify.outputs.is_nightly_tag }} is_nightly_tag: ${{ steps.Classify.outputs.is_nightly_tag }}
is_release_tag: ${{ steps.Classify.outputs.is_release_tag }} is_release_tag: ${{ steps.Classify.outputs.is_release_tag }}
has_submodules: ${{ steps.Classify.outputs.has_submodules }}
ref_kind: ${{ steps.Classify.outputs.ref_kind }} ref_kind: ${{ steps.Classify.outputs.ref_kind }}
default_branch: ${{ steps.Classify.outputs.default_branch }}
branch: ${{ steps.Classify.outputs.branch }} branch: ${{ steps.Classify.outputs.branch }}
tag: ${{ steps.Classify.outputs.tag }} tag: ${{ steps.Classify.outputs.tag }}
version: ${{ steps.Classify.outputs.version || steps.FindPullRequest.outputs.pr_version }} version: ${{ steps.Classify.outputs.version || steps.FindPullRequest.outputs.pr_version }}
# release_version: ${{ steps.FindPullRequest.outputs.release_version }} # release_version: ${{ steps.FindPullRequest.outputs.release_version }}
pr_title: ${{ steps.FindPullRequest.outputs.pr_title }} pr_title: ${{ steps.FindPullRequest.outputs.pr_title }}
pr_number: ${{ steps.Classify.outputs.pr_number || steps.FindPullRequest.outputs.pr_number }} pr_number: ${{ steps.Classify.outputs.pr_number || steps.FindPullRequest.outputs.pr_number }}
git_submodule_count: ${{ steps.Classify.outputs.git_submodule_count }}
git_submodule_names: ${{ steps.Classify.outputs.git_submodule_names }}
git_submodule_paths: ${{ steps.Classify.outputs.git_submodule_paths }}
steps: steps:
- name: ⏬ Checkout repository - name: ⏬ Checkout repository
@@ -136,6 +156,8 @@ jobs:
ANSI_LIGHT_BLUE=$'\x1b[94m' ANSI_LIGHT_BLUE=$'\x1b[94m'
ANSI_NOCOLOR=$'\x1b[0m' ANSI_NOCOLOR=$'\x1b[0m'
export GH_TOKEN=${{ github.token }}
ref="${{ github.ref }}" ref="${{ github.ref }}"
on_default_branch="false" on_default_branch="false"
on_main_branch="false" on_main_branch="false"
@@ -146,84 +168,86 @@ jobs:
is_release_commit="false" is_release_commit="false"
is_nightly_tag="false" is_nightly_tag="false"
is_release_tag="false" is_release_tag="false"
has_submodules="false"
ref_kind="unknown" ref_kind="unknown"
default_branch="" default_branch=""
branch="" branch=""
tag="" tag=""
pr_number="" pr_number=""
version="" version=""
git_submodule_count="0"
git_submodule_names=""
git_submodule_paths=""
printf "Classify Git reference '%s' " "${ref}"
if [[ "${ref:0:11}" == "refs/heads/" ]]; then if [[ "${ref:0:11}" == "refs/heads/" ]]; then
printf "${ANSI_LIGHT_GREEN}[BRANCH]\n"
ref_kind="branch" ref_kind="branch"
branch="${ref:11}" branch="${ref:11}"
printf "Get default branch name ... " printf "Get default branch name ... "
defaultBranch=$(gh repo view "${{ github.repository }}" --json defaultBranchRef --jq '.defaultBranchRef.name') defaultBranch=$(gh repo view "${{ github.repository }}" --json defaultBranchRef --jq '.defaultBranchRef.name' 2>&1)
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
printf " ${ANSI_LIGHT_GREEN} [OK]\n" printf "${ANSI_LIGHT_GREEN} [OK]\n"
default_branch="${defaultBranch}"
printf " default_branch=%s\n" "${default_branch}"
else else
printf " ${ANSI_LIGHT_RED} [FAILED]\n" printf "${ANSI_LIGHT_RED} [FAILED]\n"
printf " %s\n" "${default_branch}"
fi fi
printf "Commit check:\n" printf "Commit checks:\n"
printf " Commit kind "
if [[ "${branch}" == "${defaultBranch}" ]]; then
on_default_branch="true"
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then
is_regular_commit="true" is_regular_commit="true"
printf " ${ANSI_LIGHT_YELLOW}regular " printf "${ANSI_LIGHT_YELLOW}[REGULAR]${ANSI_NOCOLOR}\n"
else else
is_merge_commit="true" is_merge_commit="true"
printf " ${ANSI_LIGHT_GREEN}merge " printf "${ANSI_LIGHT_GREEN}[MERGE]${ANSI_NOCOLOR}\n"
fi fi
printf "commit${ANSI_NOCOLOR} on default branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${defaultBranch}"
printf "Branch checks:\n"
if [[ "${branch}" == "${defaultBranch}" ]]; then
on_default_branch="true"
printf " Commit on default branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${defaultBranch}"
fi fi
if [[ "${branch}" == "${{ inputs.main_branch }}" ]]; then if [[ "${branch}" == "${{ inputs.main_branch }}" ]]; then
on_main_branch="true" on_main_branch="true"
printf " Commit on main branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${{ inputs.main_branch }}"
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then
is_regular_commit="true"
printf " ${ANSI_LIGHT_YELLOW}regular "
else
is_merge_commit="true"
printf " ${ANSI_LIGHT_GREEN}merge "
fi
printf "commit${ANSI_NOCOLOR} on main branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${{ inputs.main_branch }}"
fi fi
if [[ "${branch}" == "${{ inputs.release_branch }}" ]]; then if [[ "${branch}" == "${{ inputs.release_branch }}" ]]; then
on_release_branch="true" on_release_branch="true"
printf " Commit on release branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${{ inputs.release_branch }}"
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then
is_regular_commit="true"
printf " ${ANSI_LIGHT_YELLOW}regular "
else
is_release_commit="true"
printf " ${ANSI_LIGHT_GREEN}release "
fi
printf "commit${ANSI_NOCOLOR} on release branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${{ inputs.release_branch }}"
fi fi
if [[ "${branch}" == "${{ inputs.development_branch }}" ]]; then if [[ "${branch}" == "${{ inputs.development_branch }}" ]]; then
on_dev_branch="true" on_dev_branch="true"
printf " Commit on development branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${{ inputs.development_branch }}"
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then fi
is_regular_commit="true"
printf " ${ANSI_LIGHT_YELLOW}regular " if [[ "${is_merge_commit}" == "true" ]]; then
else printf "Release checks:\n"
is_merge_commit="true" printf " Release kind "
printf " ${ANSI_LIGHT_GREEN}merge " if [[ "${on_main_branch}" == "true" ]]; then
is_release_commit="true"
printf "${ANSI_LIGHT_GREEN}[RELEASE]${ANSI_NOCOLOR}\n"
elif [[ "${on_version_branch}" == "true" ]]; then
is_release_commit="true"
printf "${ANSI_LIGHT_GREEN}[RELEASE]${ANSI_NOCOLOR}\n"
elif [[ "${on_release_branch}" == "true" ]]; then
is_prerelease_commit="true"
printf "${ANSI_LIGHT_YELLOW}[PRERELEASE]${ANSI_NOCOLOR}\n"
fi fi
printf "commit${ANSI_NOCOLOR} on development branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${{ inputs.development_branch }}"
fi fi
elif [[ "${ref:0:10}" == "refs/tags/" ]]; then elif [[ "${ref:0:10}" == "refs/tags/" ]]; then
printf "${ANSI_LIGHT_GREEN}[TAG]\n"
ref_kind="tag" ref_kind="tag"
tag="${ref:10}" tag="${ref:10}"
printf "Tag check:\n" printf "Tag checks:\n"
printf " Check if tag is on main branch '%s' ... " "${{ inputs.main_branch }}" printf " Check if tag is on main branch '%s' ... " "${{ inputs.main_branch }}"
git branch --remotes --contains $(git rev-parse --verify "tags/${tag}~0") | grep "origin/${{ inputs.main_branch }}" > /dev/null git branch --remotes --contains $(git rev-parse --verify "tags/${tag}~0") | grep "origin/${{ inputs.main_branch }}" > /dev/null
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
@@ -254,18 +278,30 @@ jobs:
exit 1 exit 1
fi fi
elif [[ "${ref:0:10}" == "refs/pull/" ]]; then elif [[ "${ref:0:10}" == "refs/pull/" ]]; then
printf "${ANSI_LIGHT_YELLOW}[PULL REQUEST]\n"
ref_kind="pullrequest" ref_kind="pullrequest"
pr_number=${ref:11} pr_number=${ref:11}
pr_number=${pr_number%%/*} pr_number=${pr_number%%/*}
printf "Pull Request check:\n" printf "Pull Request checks:\n"
printf " Number: %s\n" "${pr_number}" printf " Number: %s\n" "${pr_number}"
else else
printf "${ANSI_LIGHT_RED}[UNKNOWN]\n"
printf "${ANSI_LIGHT_RED}Unknown Git reference '%s'.${ANSI_NOCOLOR}\n" "${{ github.ref }}" printf "${ANSI_LIGHT_RED}Unknown Git reference '%s'.${ANSI_NOCOLOR}\n" "${{ github.ref }}"
printf "::error title=Classify Commit::Unknown Git reference '%s'.\n" "${{ github.ref }}" printf "::error title=Classify Commit::Unknown Git reference '%s'.\n" "${{ github.ref }}"
exit 1 exit 1
fi fi
# Submodules
if [[ -f .gitsubmodules ]]; then
has_submodules="true"
git_modules_file=.gitmodules # $(git rev-parse --show-toplevel)/.gitmodules
git_submodule_count="$(grep -Po '(?<=\[submodule \")(.*)(?=\"\])' "${git_modules_file}" | wc -l)"
git_submodule_names="$(grep -Po '(?<=\[submodule \")(.*)(?=\"\])' "${git_modules_file}" | paste -sd ':' -)"
git_submodule_paths="$(git config --file "${git_modules_file}" --null --name-only --get-regexp '\.path$' | xargs -0 -n1 git config --file "${git_modules_file}" --get | paste -sd ':' -)"
fi
printf "\nWriting output variables ...\n"
tee --append "${GITHUB_OUTPUT}" <<EOF tee --append "${GITHUB_OUTPUT}" <<EOF
on_default_branch=${on_default_branch} on_default_branch=${on_default_branch}
on_main_branch=${on_main_branch} on_main_branch=${on_main_branch}
@@ -276,11 +312,16 @@ jobs:
is_release_commit=${is_release_commit} is_release_commit=${is_release_commit}
is_nightly_tag=${is_nightly_tag} is_nightly_tag=${is_nightly_tag}
is_release_tag=${is_release_tag} is_release_tag=${is_release_tag}
has_submodules=${has_submodules}
ref_kind=${ref_kind} ref_kind=${ref_kind}
default_branch=${default_branch}
branch=${branch} branch=${branch}
tag=${tag} tag=${tag}
pr_number=${pr_number} pr_number=${pr_number}
version=${version} version=${version}
git_submodule_count=${git_submodule_count}
git_submodule_names=${git_submodule_names}
git_submodule_paths=${git_submodule_paths}
EOF EOF
# TODO: why not is_release_commit? # TODO: why not is_release_commit?
@@ -356,15 +397,18 @@ jobs:
- name: Debug - name: Debug
run: | run: |
printf "on_default_branch: %s\n" "${{ steps.Classify.outputs.on_default_branch }}"
printf "on_main_branch: %s\n" "${{ steps.Classify.outputs.on_main_branch }}" printf "on_main_branch: %s\n" "${{ steps.Classify.outputs.on_main_branch }}"
printf "on_dev_branch: %s\n" "${{ steps.Classify.outputs.on_dev_branch }}"
printf "on_release_branch: %s\n" "${{ steps.Classify.outputs.on_release_branch }}" printf "on_release_branch: %s\n" "${{ steps.Classify.outputs.on_release_branch }}"
printf "on_dev_branch: %s\n" "${{ steps.Classify.outputs.on_dev_branch }}"
printf "is_regular_commit: %s\n" "${{ steps.Classify.outputs.is_regular_commit }}" printf "is_regular_commit: %s\n" "${{ steps.Classify.outputs.is_regular_commit }}"
printf "is_merge_commit: %s\n" "${{ steps.Classify.outputs.is_merge_commit }}" printf "is_merge_commit: %s\n" "${{ steps.Classify.outputs.is_merge_commit }}"
printf "is_release_commit: %s\n" "${{ steps.Classify.outputs.is_release_commit }}" printf "is_release_commit: %s\n" "${{ steps.Classify.outputs.is_release_commit }}"
printf "is_nightly_tag: %s\n" "${{ steps.Classify.outputs.is_nightly_tag }}" printf "is_nightly_tag: %s\n" "${{ steps.Classify.outputs.is_nightly_tag }}"
printf "is_release_tag: %s\n" "${{ steps.Classify.outputs.is_release_tag }}" printf "is_release_tag: %s\n" "${{ steps.Classify.outputs.is_release_tag }}"
printf "has_submodules: %s\n" "${{ steps.Classify.outputs.has_submodules }}"
printf "ref_kind: %s\n" "${{ steps.Classify.outputs.ref_kind }}" printf "ref_kind: %s\n" "${{ steps.Classify.outputs.ref_kind }}"
printf "default_branch: %s\n" "${{ steps.Classify.outputs.default_branch }}"
printf "branch: %s\n" "${{ steps.Classify.outputs.branch }}" printf "branch: %s\n" "${{ steps.Classify.outputs.branch }}"
printf "tag: %s\n" "${{ steps.Classify.outputs.tag }}" printf "tag: %s\n" "${{ steps.Classify.outputs.tag }}"
printf "version: %s\n" "${{ steps.Classify.outputs.version || steps.FindPullRequest.outputs.pr_version }}" printf "version: %s\n" "${{ steps.Classify.outputs.version || steps.FindPullRequest.outputs.pr_version }}"
@@ -374,3 +418,7 @@ jobs:
printf "pr number: %s\n" "${{ steps.Classify.outputs.pr_number || steps.FindPullRequest.outputs.pr_number }}" printf "pr number: %s\n" "${{ steps.Classify.outputs.pr_number || steps.FindPullRequest.outputs.pr_number }}"
printf " from merge: %s\n" "${{ steps.Classify.outputs.pr_number }}" printf " from merge: %s\n" "${{ steps.Classify.outputs.pr_number }}"
printf " from pr: %s\n" "${{ steps.FindPullRequest.outputs.pr_number }}" printf " from pr: %s\n" "${{ steps.FindPullRequest.outputs.pr_number }}"
printf "git_submodule_*:\n"
printf " *_count_: %s\n" "${{ steps.FindPullRequest.outputs.git_submodule_count }}"
printf " *_names: %s\n" "${{ steps.FindPullRequest.outputs.git_submodule_names }}"
printf " *_paths: %s\n" "${{ steps.FindPullRequest.outputs.git_submodule_paths }}"

View File

@@ -505,9 +505,11 @@ jobs:
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
if [[ -z "${latestVersion}" ]]; then if [[ -z "${latestVersion}" ]]; then
printf "${ANSI_LIGHT_RED}[UNKNOWN]${ANSI_NOCOLOR}\n" printf "${ANSI_LIGHT_RED}[UNKNOWN]${ANSI_NOCOLOR}\n"
printf " latest=unknown\n"
latestVersion="unknown" latestVersion="unknown"
else else
printf "${ANSI_LIGHT_GREEN}[OK]${ANSI_NOCOLOR}\n" printf "${ANSI_LIGHT_GREEN}[OK]${ANSI_NOCOLOR}\n"
printf " latest=%s\n" "${latestVersion}"
fi fi
else else
printf "${ANSI_LIGHT_RED}[ERROR]${ANSI_NOCOLOR}\n" printf "${ANSI_LIGHT_RED}[ERROR]${ANSI_NOCOLOR}\n"
@@ -529,7 +531,7 @@ jobs:
jsonInventory=$(jq -c -n \ jsonInventory=$(jq -c -n \
--arg structVersion "${STRUCT_VERSION}" \ --arg structVersion "${STRUCT_VERSION}" \
--arg date "$(date +"%Y-%m-%dT%H-%M-%S%:z")" \ --arg date "$(date +"%Y-%m-%dT%H:%M:%S%:z")" \
--argjson jsonMeta "$(jq -c -n \ --argjson jsonMeta "$(jq -c -n \
--arg tag "${{ inputs.tag }}" \ --arg tag "${{ inputs.tag }}" \
--arg version "${{ inputs.inventory-version }}" \ --arg version "${{ inputs.inventory-version }}" \
@@ -547,7 +549,7 @@ jobs:
)" \ )" \
'{"tag": $tag, "version": $version, "git-hash": $hash, "repository-url": $repo, "release-url": $release, "categories": $categories, "latest": $jsonLatest}' \ '{"tag": $tag, "version": $version, "git-hash": $hash, "repository-url": $repo, "release-url": $release, "categories": $categories, "latest": $jsonLatest}' \
)" \ )" \
'{"version": $structVersion, "timestamp": $date, "meta": $jsonMeta, "files": {}}' '{"version": "$structVersion", "timestamp": $date, "meta": $jsonMeta, "files": {}}'
) )
fi fi