mirror of
https://github.com/pyTooling/Actions.git
synced 2026-02-12 02:56:56 +08:00
Provide is_nightly_tag and is_release_tag.
This commit is contained in:
94
.github/workflows/PrepareJob.yml
vendored
94
.github/workflows/PrepareJob.yml
vendored
@@ -19,12 +19,17 @@ on:
|
||||
default: 'dev'
|
||||
type: string
|
||||
release_branch:
|
||||
description: 'Name of the branch containing releases.'
|
||||
description: 'Name of the branch containing releases and nightly builds.'
|
||||
required: false
|
||||
default: 'main'
|
||||
type: string
|
||||
tag_pattern:
|
||||
description: 'Name of the branch containing releases.'
|
||||
nightly_tag_pattern:
|
||||
description: 'Pattern for nightly tags on the release branch.'
|
||||
required: false
|
||||
default: 'nightly'
|
||||
type: string
|
||||
release_tag_pattern:
|
||||
description: 'Pattern for release tags on the release branch. Usually: vXX.YY.ZZ'
|
||||
required: false
|
||||
default: '(v|r)?[0-9]+(\.[0-9]+){0,2}(-(dev|alpha|beta|rc)([0-9]*))?'
|
||||
type: string
|
||||
@@ -48,6 +53,12 @@ on:
|
||||
is_release_commit:
|
||||
description: ""
|
||||
value: ${{ jobs.Prepare.outputs.is_release_commit }}
|
||||
is_nightly_tag:
|
||||
description: ""
|
||||
value: ${{ jobs.Prepare.outputs.is_nightly_tag }}
|
||||
is_release_tag:
|
||||
description: ""
|
||||
value: ${{ jobs.Prepare.outputs.is_release_tag }}
|
||||
ref_kind:
|
||||
description: ""
|
||||
value: ${{ jobs.Prepare.outputs.ref_kind }}
|
||||
@@ -84,6 +95,8 @@ jobs:
|
||||
is_regular_commit: ${{ steps.Classify.outputs.is_regular_commit }}
|
||||
is_merge_commit: ${{ steps.Classify.outputs.is_merge_commit }}
|
||||
is_release_commit: ${{ steps.Classify.outputs.is_release_commit }}
|
||||
is_nightly_tag: ${{ steps.Classify.outputs.is_nightly_tag }}
|
||||
is_release_tag: ${{ steps.Classify.outputs.is_release_tag }}
|
||||
ref_kind: ${{ steps.Classify.outputs.ref_kind }}
|
||||
branch: ${{ steps.Classify.outputs.branch }}
|
||||
tag: ${{ steps.Classify.outputs.tag }}
|
||||
@@ -118,7 +131,7 @@ jobs:
|
||||
ANSI_LIGHT_YELLOW=$'\x1b[93m'
|
||||
ANSI_LIGHT_BLUE=$'\x1b[94m'
|
||||
ANSI_NOCOLOR=$'\x1b[0m'
|
||||
|
||||
|
||||
ref="${{ github.ref }}"
|
||||
on_main_branch="false"
|
||||
on_dev_branch="false"
|
||||
@@ -126,20 +139,22 @@ jobs:
|
||||
is_regular_commit="false"
|
||||
is_merge_commit="false"
|
||||
is_release_commit="false"
|
||||
is_nightly_tag="false"
|
||||
is_release_tag="false"
|
||||
ref_kind="unknown"
|
||||
branch=""
|
||||
tag=""
|
||||
version=""
|
||||
|
||||
|
||||
if [[ "${ref:0:11}" == "refs/heads/" ]]; then
|
||||
ref_kind="branch"
|
||||
branch="${ref:11}"
|
||||
|
||||
|
||||
printf "Commit check:\n"
|
||||
|
||||
|
||||
if [[ "${branch}" == "${{ inputs.main_branch }}" ]]; then
|
||||
on_main_branch="true"
|
||||
|
||||
|
||||
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then
|
||||
is_regular_commit="true"
|
||||
printf " ${ANSI_LIGHT_YELLOW}regular "
|
||||
@@ -149,10 +164,10 @@ jobs:
|
||||
fi
|
||||
printf "commit${ANSI_NOCOLOR} on main branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${{ inputs.main_branch }}"
|
||||
fi
|
||||
|
||||
|
||||
if [[ "${branch}" == "${{ inputs.development_branch }}" ]]; then
|
||||
on_dev_branch="true"
|
||||
|
||||
|
||||
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then
|
||||
is_regular_commit="true"
|
||||
printf " ${ANSI_LIGHT_YELLOW}regular "
|
||||
@@ -162,10 +177,10 @@ jobs:
|
||||
fi
|
||||
printf "commit${ANSI_NOCOLOR} on development branch ${ANSI_LIGHT_BLUE}'%s'${ANSI_NOCOLOR}\n" "${{ inputs.development_branch }}"
|
||||
fi
|
||||
|
||||
|
||||
if [[ "${branch}" == "${{ inputs.release_branch }}" ]]; then
|
||||
on_release_branch="true"
|
||||
|
||||
|
||||
if [[ -z "$(git rev-list -1 --merges ${{ github.sha }}~1..${{ github.sha }})" ]]; then
|
||||
is_regular_commit="true"
|
||||
printf " ${ANSI_LIGHT_YELLOW}regular "
|
||||
@@ -178,9 +193,9 @@ jobs:
|
||||
elif [[ "${ref:0:10}" == "refs/tags/" ]]; then
|
||||
ref_kind="tag"
|
||||
tag="${ref:10}"
|
||||
|
||||
|
||||
printf "Tag check:\n"
|
||||
|
||||
|
||||
printf " Check if tag is on release branch '%s' ... " "${{ inputs.release_branch }}"
|
||||
git branch --remotes --contains $(git rev-parse --verify "tags/${tag}~0") | grep "origin/${{ inputs.release_branch }}" > /dev/null
|
||||
if [[ $? -eq 0 ]]; then
|
||||
@@ -191,16 +206,23 @@ jobs:
|
||||
printf "::error title=TagCheck::Tag '%s' isn't on branch '%s'.\n" "${tag}" "${{ inputs.release_branch }}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TAG_PATTERN='^${{ inputs.tag_pattern }}$'
|
||||
printf " Check tag name against regexp '%s' ... " "${TAG_PATTERN}"
|
||||
if [[ "${tag}" =~ $TAG_PATTERN ]]; then
|
||||
printf "${ANSI_LIGHT_GREEN}[OK]${ANSI_NOCOLOR}\n"
|
||||
|
||||
NIGHTLY_TAG_PATTERN='^${{ inputs.nightly_tag_pattern }}$'
|
||||
RELEASE_TAG_PATTERN='^${{ inputs.release_tag_pattern }}$'
|
||||
printf " Check tag name against regexp '%s' ... " "${RELEASE_TAG_PATTERN}"
|
||||
if [[ "${tag}" =~ NIGHTLY_TAG_PATTERN ]]; then
|
||||
printf "${ANSI_LIGHT_GREEN}[NIGHTLY]${ANSI_NOCOLOR}\n"
|
||||
is_nightly_tag=true
|
||||
elif [[ "${tag}" =~ $RELEASE_TAG_PATTERN ]]; then
|
||||
printf "${ANSI_LIGHT_GREEN}[RELEASE]${ANSI_NOCOLOR}\n"
|
||||
version="${tag}"
|
||||
is_release_tag=true
|
||||
else
|
||||
printf "${ANSI_LIGHT_RED}[FAILED]${ANSI_NOCOLOR}\n"
|
||||
printf "${ANSI_LIGHT_RED}Tag name '%s' doesn't conform to regexp '%s'.${ANSI_NOCOLOR}\n" "${tag}" "${TAG_PATTERN}"
|
||||
printf "::error title=RexExpCheck::Tag name '%s' doesn't conform to regexp '%s'.\n" "${tag}" "${TAG_PATTERN}"
|
||||
printf "${ANSI_LIGHT_RED}Tag name '%s' doesn't conform to regexp${ANSI_NOCOLOR}\n" "${tag}"
|
||||
printf " ${ANSI_LIGHT_RED}nightly tag: %s${ANSI_NOCOLOR}\n" "${NIGHTLY_TAG_PATTERN}"
|
||||
printf " ${ANSI_LIGHT_RED}release tag: %s${ANSI_NOCOLOR}\n" "${RELEASE_TAG_PATTERN}"
|
||||
printf "::error title=RexExpCheck::Tag name '%s' doesn't conform to regexp '%s' nor '%s'.\n" "${tag}" "${NIGHTLY_TAG_PATTERN}" "${RELEASE_TAG_PATTERN}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
@@ -208,7 +230,7 @@ jobs:
|
||||
printf "::error title=Classify Commit::Unknown Git reference '%s'.\n" "${{ github.ref }}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
tee --append "${GITHUB_OUTPUT}" <<EOF
|
||||
on_main_branch=${on_main_branch}
|
||||
on_dev_branch=${on_dev_branch}
|
||||
@@ -216,6 +238,8 @@ jobs:
|
||||
is_regular_commit=${is_regular_commit}
|
||||
is_merge_commit=${is_merge_commit}
|
||||
is_release_commit=${is_release_commit}
|
||||
is_nightly_tag=${is_nightly_tag}
|
||||
is_release_tag=${is_release_tag}
|
||||
ref_kind=${ref_kind}
|
||||
branch=${branch}
|
||||
tag=${tag}
|
||||
@@ -233,9 +257,9 @@ jobs:
|
||||
ANSI_LIGHT_YELLOW=$'\x1b[93m'
|
||||
ANSI_LIGHT_BLUE=$'\x1b[94m'
|
||||
ANSI_NOCOLOR=$'\x1b[0m'
|
||||
|
||||
|
||||
export GH_TOKEN=${{ github.token }}
|
||||
|
||||
|
||||
printf "Read second parent of current SHA (%s) ... " "${{ github.ref }}"
|
||||
FATHER_SHA=$(git rev-parse ${{ github.ref }}^2)
|
||||
if [[ $? -ne 0 || "{FATHER_SHA}" == "" ]]; then
|
||||
@@ -246,7 +270,7 @@ jobs:
|
||||
else
|
||||
printf "${ANSI_LIGHT_GREEN}[OK]${ANSI_NOCOLOR}\n"
|
||||
fi
|
||||
|
||||
|
||||
printf "Search Pull Request to '%s' and branch containing SHA %s ... " "${{ inputs.release_branch }}" "${FATHER_SHA}"
|
||||
PULL_REQUESTS=$(gh pr list --base "${{ inputs.release_branch }}" --search "${FATHER_SHA}" --state "merged" --json "title,number,mergedBy,mergedAt")
|
||||
if [[ $? -ne 0 || "${PULL_REQUESTS}" == "" ]]; then
|
||||
@@ -256,31 +280,31 @@ jobs:
|
||||
exit 1
|
||||
else
|
||||
printf "${ANSI_LIGHT_GREEN}[OK]${ANSI_NOCOLOR}\n"
|
||||
|
||||
|
||||
PR_TITLE="$( printf "%s\n" "${PULL_REQUESTS}" | jq --raw-output ".[0].title")"
|
||||
PR_NUMBER="$( printf "%s\n" "${PULL_REQUESTS}" | jq --raw-output ".[0].number")"
|
||||
PR_MERGED_BY="$(printf "%s\n" "${PULL_REQUESTS}" | jq --raw-output ".[0].mergedBy.login")"
|
||||
PR_MERGED_AT="$(printf "%s\n" "${PULL_REQUESTS}" | jq --raw-output ".[0].mergedAt")"
|
||||
|
||||
|
||||
printf "${ANSI_LIGHT_BLUE}Found Pull Request:${ANSI_NOCOLOR}\n"
|
||||
printf " %s\n" "Title: ${PR_TITLE}"
|
||||
printf " %s\n" "Number: ${PR_NUMBER}"
|
||||
printf " %s\n" "MergedBy: ${PR_MERGED_BY}"
|
||||
printf " %s\n" "MergedAt: ${PR_MERGED_AT} ($(date -d"${PR_MERGED_AT}" '+%d.%m.%Y - %H:%M:%S'))"
|
||||
fi
|
||||
|
||||
TAG_PATTERN='^${{ inputs.tag_pattern }}$'
|
||||
printf "Check Pull Request title against regexp '%s' ... " "${TAG_PATTERN}"
|
||||
if [[ "${PR_TITLE}" =~ $TAG_PATTERN ]]; then
|
||||
|
||||
RELEASE_TAG_PATTERN='^${{ inputs.release_tag_pattern }}$'
|
||||
printf "Check Pull Request title against regexp '%s' ... " "${RELEASE_TAG_PATTERN}"
|
||||
if [[ "${PR_TITLE}" =~ $RELEASE_TAG_PATTERN ]]; then
|
||||
printf "${ANSI_LIGHT_GREEN}[OK]${ANSI_NOCOLOR}\n"
|
||||
RELEASE_VERSION="${PR_TITLE}"
|
||||
else
|
||||
printf "${ANSI_LIGHT_RED}[FAILED]${ANSI_NOCOLOR}\n"
|
||||
printf "${ANSI_LIGHT_RED}Pull Request title '%s' doesn't conform to regexp '%s'.${ANSI_NOCOLOR}\n" "${PR_TITLE}" "${TAG_PATTERN}"
|
||||
printf "::error title=RexExpCheck::Pull Request title '%s' doesn't conform to regexp '%s'.\n" "${PR_TITLE}" "${TAG_PATTERN}"
|
||||
printf "${ANSI_LIGHT_RED}Pull Request title '%s' doesn't conform to regexp '%s'.${ANSI_NOCOLOR}\n" "${PR_TITLE}" "${RELEASE_TAG_PATTERN}"
|
||||
printf "::error title=RexExpCheck::Pull Request title '%s' doesn't conform to regexp '%s'.\n" "${PR_TITLE}" "${RELEASE_TAG_PATTERN}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
printf "Release tag: ${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "${RELEASE_VERSION}"
|
||||
tee --append "${GITHUB_OUTPUT}" <<EOF
|
||||
pr_version=${RELEASE_VERSION}
|
||||
@@ -298,6 +322,8 @@ jobs:
|
||||
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_release_commit: %s\n" "${{ steps.Classify.outputs.is_release_commit }}"
|
||||
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 "ref_kind: %s\n" "${{ steps.Classify.outputs.ref_kind }}"
|
||||
printf "branch: %s\n" "${{ steps.Classify.outputs.branch }}"
|
||||
printf "tag: %s\n" "${{ steps.Classify.outputs.tag }}"
|
||||
|
||||
Reference in New Issue
Block a user