refactor: update version extraction logic to include build ID and streamline version fetching

This commit is contained in:
XargonWan 2025-03-29 10:17:49 +09:00
parent 8be9782ff7
commit 1cdf81aab0
3 changed files with 21 additions and 13 deletions

View file

@ -106,20 +106,20 @@ jobs:
- name: Generate Version Tag
id: version-tag
run: |
# Source the version extractor script and fetch the manifest version
# Source the version extractor script and fetch the actual version, including the build ID
source automation_tools/version_extractor.sh
MANIFEST_VERSION="$(fetch_manifest_version)"
VERSION="$(fetch_actual_version)"
# Ensure the manifest version was successfully extracted
if [[ -z "$MANIFEST_VERSION" ]]; then
echo "[ERROR] Failed to extract the manifest version."
# Ensure the actual version was successfully extracted
if [[ -z "$VERSION" ]]; then
echo "[ERROR] Failed to extract the actual version."
exit 1
fi
# Determine the tag based on the GitHub event context
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
# Main branch tag
TAG="$MANIFEST_VERSION"
TAG="$VERSION"
MAKE_LATEST=true
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" || "$GITHUB_EVENT_NAME" == "pull_request_target" ]]; then
# Pull request tag, sanitize the source branch
@ -128,7 +128,7 @@ jobs:
MAKE_LATEST=false
else
# Other branches (cooker branches)
TAG="$MANIFEST_VERSION-${{ env.BUILD_ID }}"
TAG="$VERSION-${{ env.BUILD_ID }}"
MAKE_LATEST=true
fi

View file

@ -22,4 +22,16 @@ fetch_metainfo_version(){
echo "$VERSION"
}
# TODO: cooker_build_id logic can be moved here
fetch_actual_version(){
# If the current Git branch is not 'main', append 'cooker-' to the version number
if [[ "${GITHUB_REF_NAME}" != "main" ]]; then
VERSION="cooker-$(cat ./version)-$(cat buildid)"
else # Otherwise, if we're on main, use the version number as is
VERSION=$(cat ./version)
fi
echo "$VERSION"
}
echo "Version extractor functions loaded"

View file

@ -83,12 +83,8 @@ modules:
- |
# VERSION INITIALIZATION
# If the current Git branch is not 'main', append 'cooker-' to the version number
if [[ "${GITHUB_REF_NAME}" != "main" ]]; then
VERSION="cooker-$(cat ./version)-$(cat buildid)"
else # Otherwise, if we're on main, use the version number as is
VERSION=$(cat ./version)
fi
source "automation_tools/version_extractor.sh"
VERSION=$(fetch_actual_version)
# Check out the current Git branch
git checkout ${GITHUB_REF_NAME}