mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-17 23:13:03 +08:00
65cb951ada
对 ALVersionInfo.py 文件的更新逻辑进行差异化处理,分别为 commit-release 和 build 阶段生成不同的 artifact: * 针对 commit-release 阶段:将所有与构建(build)相关的字段值设置为 'local' 或 'null' * 针对 build 阶段:保留完整的版本信息字段 这种差异化处理确保其后续提交的 release commit 不会包含构建相关的版本信息。
163 lines
5.9 KiB
YAML
163 lines
5.9 KiB
YAML
name: Update Version
|
|
|
|
# This workflow updates version information in 'ALVersionInfo.py' with build metadata.
|
|
# In progress, it will generate two version files, the first one is locate in 'src/gui/ALVersionInfo.py',
|
|
# and the second one is locate in 'src/gui/temp/ALVersionInfo.py'. The first one is use
|
|
# in the release process, it only update the version and tag name. The commit and build infomation
|
|
# is 'local' or 'null'. All of them will finally archive as artifacts.
|
|
#
|
|
# It is triggered when called by the release workflow.
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
tag_name:
|
|
description: 'Tag name'
|
|
required: true
|
|
type: string
|
|
ref:
|
|
description: 'Git ref to checkout'
|
|
required: true
|
|
type: string
|
|
outputs:
|
|
tag_name:
|
|
description: 'The tag name'
|
|
value: ${{ jobs.update-version.outputs.tag_name }}
|
|
version:
|
|
description: 'The version number'
|
|
value: ${{ jobs.update-version.outputs.version }}
|
|
has_changes:
|
|
description: 'Whether ALVersionInfo.py was modified'
|
|
value: ${{ jobs.update-version.outputs.has_changes }}
|
|
|
|
jobs:
|
|
update-version:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
outputs:
|
|
tag_name: ${{ steps.get_version.outputs.TAG_NAME }}
|
|
version: ${{ steps.get_version.outputs.VERSION }}
|
|
has_changes: ${{ steps.check_changes.outputs.has_changes }}
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ inputs.ref }}
|
|
fetch-depth: 0
|
|
|
|
- name: Get tag name and version
|
|
id: get_version
|
|
env:
|
|
TZ: UTC
|
|
run: |
|
|
TAG_NAME="${{ inputs.tag_name }}"
|
|
VERSION="${TAG_NAME#v}"
|
|
COMMIT_SHA="${GITHUB_SHA:0:7}"
|
|
COMMIT_DATE=$(TZ=UTC git log -1 --format=%cd --date=format-local:'%Y-%m-%d %H:%M:%S UTC')
|
|
|
|
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
|
|
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
|
|
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_OUTPUT
|
|
echo "COMMIT_DATE=$COMMIT_DATE" >> $GITHUB_OUTPUT
|
|
|
|
echo "✓ Tag: $TAG_NAME"
|
|
echo "✓ Version: $VERSION"
|
|
echo "✓ Commit SHA: $COMMIT_SHA"
|
|
echo "✓ Commit Date: $COMMIT_DATE"
|
|
|
|
- name: Create 'temp' directory
|
|
run: |
|
|
echo "Creating temp directory..."
|
|
mkdir -p "src/gui/temp"
|
|
echo "✓ temp directory created successfully"
|
|
|
|
- name: Update ALVersionInfo.py with version info
|
|
run: |
|
|
VERSION="${{ steps.get_version.outputs.VERSION }}"
|
|
TAG_NAME="${{ steps.get_version.outputs.TAG_NAME }}"
|
|
COMMIT_SHA="${{ steps.get_version.outputs.COMMIT_SHA }}"
|
|
COMMIT_DATE="${{ steps.get_version.outputs.COMMIT_DATE }}"
|
|
VER_INFO_BUILDFILE="src/gui/temp/ALVersionInfo.py"
|
|
VER_INFO_COMMITFILE="src/gui/ALVersionInfo.py"
|
|
BUILD_DATE=$(date -u '+%Y-%m-%d %H:%M:%S UTC')
|
|
|
|
echo "Updating ALVersionInfo.py files with build information..."
|
|
{
|
|
echo '# -*- coding: utf-8 -*-'
|
|
echo ''
|
|
echo '"""'
|
|
echo ' The contents of this file will automatically be updated by the'
|
|
echo ' workflow process. Do not edit manually.'
|
|
echo ''
|
|
echo ' This file is auto-generated during the workflow process.'
|
|
echo " Last updated: ${BUILD_DATE}"
|
|
echo '"""'
|
|
echo ''
|
|
echo "AL_VERSION = \"${VERSION}\""
|
|
echo "AL_TAG = \"${TAG_NAME}\""
|
|
echo "AL_COMMIT_SHA = \"${COMMIT_SHA}\""
|
|
echo "AL_COMMIT_DATE = \"${COMMIT_DATE}\" # time zone : UTC"
|
|
echo "AL_BUILD_DATE = \"${BUILD_DATE}\" # time zone : UTC"
|
|
echo 'AL_VERSION_FULL = f"{AL_VERSION} ({AL_COMMIT_SHA})"'
|
|
} > "$VER_INFO_BUILDFILE"
|
|
|
|
echo "Updating ALVersionInfo.py for release commit..."
|
|
{
|
|
echo '# -*- coding: utf-8 -*-'
|
|
echo ''
|
|
echo '"""'
|
|
echo ' The contents of this file will automatically be updated by the'
|
|
echo ' workflow process. Do not edit manually.'
|
|
echo ''
|
|
echo ' This file is auto-generated during the workflow process.'
|
|
echo " Last updated: ${BUILD_DATE}"
|
|
echo '"""'
|
|
echo ''
|
|
echo "AL_VERSION = \"${VERSION}\""
|
|
echo "AL_TAG = \"${TAG_NAME}\""
|
|
echo "AL_COMMIT_SHA = \"local\""
|
|
echo "AL_COMMIT_DATE = \"null\" # time zone : UTC"
|
|
echo "AL_BUILD_DATE = \"null\" # time zone : UTC"
|
|
echo 'AL_VERSION_FULL = f"{AL_VERSION} ({AL_COMMIT_SHA})"'
|
|
} > "$VER_INFO_COMMITFILE"
|
|
|
|
echo "✓ ALVersionInfo.py files updated successfully"
|
|
echo ""
|
|
echo "Build version file location: $VER_INFO_BUILDFILE"
|
|
echo "Commit version file location: $VER_INFO_COMMITFILE"
|
|
echo ""
|
|
echo "Build version ALVersionInfo.py content ="
|
|
cat "$VER_INFO_BUILDFILE"
|
|
echo ""
|
|
echo "Commit version ALVersionInfo.py content "
|
|
cat "$VER_INFO_COMMITFILE"
|
|
echo "========================================"
|
|
|
|
- name: Check if ALVersionInfo.py was modified
|
|
id: check_changes
|
|
run: |
|
|
if git diff --quiet src/gui/ALVersionInfo.py; then
|
|
echo "has_changes=false" >> $GITHUB_OUTPUT
|
|
echo "! No changes detected in ALVersionInfo.py"
|
|
else
|
|
echo "has_changes=true" >> $GITHUB_OUTPUT
|
|
echo "✓ ALVersionInfo.py has been modified"
|
|
fi
|
|
|
|
- name: Upload modified ALVersionInfo.py ready for build
|
|
if: steps.check_changes.outputs.has_changes == 'true'
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: updated-version-info-for-build
|
|
path: src/gui/temp/ALVersionInfo.py
|
|
retention-days: 1
|
|
|
|
- name: Upload modified ALVersionInfo.py ready for commit
|
|
if: steps.check_changes.outputs.has_changes == 'true'
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: updated-version-info-for-commit
|
|
path: src/gui/ALVersionInfo.py
|
|
retention-days: 1 |