ci: gate v3 release on version value changes (#7052)

Co-authored-by: DDSRem <1448139087@qq.com>
This commit is contained in:
DDSRem
2026-10-17 19:57:48 +08:00
committed by GitHub
parent 85b367527e
commit e33ae01aad
3 changed files with 90 additions and 0 deletions

View File

@@ -12,7 +12,49 @@ permissions:
packages: write
jobs:
release-gate:
runs-on: ubuntu-latest
outputs:
publish: ${{ steps.detect.outputs.publish }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Detect version change
id: detect
env:
EVENT_NAME: ${{ github.event_name }}
BEFORE_SHA: ${{ github.event.before }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" = workflow_dispatch ]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
exit 0
fi
versions() {
sed -nE "s/^(APP_VERSION|FRONTEND_VERSION)[[:space:]]*=[[:space:]]*'([^']+)'[[:space:]]*$/\1=\2/p" | sort
}
previous=$(git show "$BEFORE_SHA:version.py" | versions)
current=$(versions < version.py)
for value in APP_VERSION FRONTEND_VERSION; do
if ! printf '%s\n' "$previous" | grep -q "^${value}=" ||
! printf '%s\n' "$current" | grep -q "^${value}="; then
echo "版本声明缺失: $value" >&2
exit 1
fi
done
if [ "$previous" = "$current" ]; then
echo "publish=false" >> "$GITHUB_OUTPUT"
else
echo "publish=true" >> "$GITHUB_OUTPUT"
fi
Docker-build:
needs: release-gate
if: needs.release-gate.outputs.publish == 'true'
runs-on: ubuntu-latest
name: Build Docker Image
steps: