Auto package, tag, release on PR workflow (BlueArchiveArisHelper/BAAH)
The Auto package, tag, release on PR workflow from BlueArchiveArisHelper/BAAH, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get run de-duplication, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Auto package, tag, release on PR workflow from the BlueArchiveArisHelper/BAAH repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Auto package, tag, release on PR
on:
push:
branches: [main]
paths-ignore:
- "README.md" # 忽略文档更新,避免不必要的运行
workflow_dispatch: # 允许手动触发
jobs:
build-and-release:
runs-on: windows-latest # 使用Windows环境[1](@ref)
env:
PYTHONIOENCODING: "utf-8"
PYTHONUTF8: "1" # 强制使用UTF-8编码[1,3](@ref)
permissions:
contents: write # 允许创建Tag和Release[2](@ref)
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main # 明确检出main分支[5](@ref)
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v4
with:
miniconda-version: "py310_24.7.1-0"
auto-update-conda: false
activate-environment: "base"
auto-activate: true
- name: Cache pip
uses: actions/cache@v4
if: startsWith(runner.os, 'Windows')
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Upgrade pip and install dependencies
shell: cmd /C CALL {0}
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Extract version number
id: get_version
shell: cmd /C CALL {0}
run: |
for /f "delims=" %%i in ('python package.py -v') do echo VERSION_NUMBER=%%i>>"%GITHUB_OUTPUT%"
# 新增的标签检查步骤
- name: Check for existing tag
id: check_tag
shell: cmd /C CALL {0}
run: |
set "tag=BAAH${{ steps.get_version.outputs.VERSION_NUMBER }}"
git ls-remote --exit-code --tags origin "refs/tags/%tag%" >nul 2>&1
if errorlevel 3 (
echo ::error::Failed to check tag: %tag%
exit /b 1
) else if errorlevel 1 (
echo Tag %tag% does not exist. Proceeding.
exit /b 0
) else (
echo ::error::Already has this tag: %tag%
exit /b 1
)
- name: Extract version change log
id: get_change_log
shell: cmd /C CALL {0}
run: |
rem 将日志输出到文件,PYTHONIOENCODING 会确保 UTF-8 编码
python package.py -c > changelog.md
- name: Build package
shell: cmd /C CALL {0}
run: python package.py # 执行打包脚本[8](@ref)
- name: Create Git Tag
shell: cmd /C CALL {0}
run: |
git tag "BAAH${{ steps.get_version.outputs.VERSION_NUMBER }}"
git push origin "BAAH${{ steps.get_version.outputs.VERSION_NUMBER }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 使用内置令牌[2](@ref)
- name: Create Release
uses: softprops/action-gh-release@v2 # 功能完整的Release Action[2,10](@ref)
with:
draft: false
prerelease: false
tag_name: BAAH${{ steps.get_version.outputs.VERSION_NUMBER }}
name: BAAH${{ steps.get_version.outputs.VERSION_NUMBER }}
body_path: changelog.md # 关键修改:从文件读取内容
files: ./dist/*.zip # 仅上传ZIP格式的制品[10](@ref)
MirrorChyanUploading:
runs-on: ubuntu-latest
needs: build-and-release
steps:
- name: Get latest tag
id: get_release_tag
shell: bash
run: |
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/latest)
tag=$(echo "$response" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
echo "TAG=$tag" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Trigger MirrorChyanUploading
shell: bash
run: |
gh workflow run --repo $GITHUB_REPOSITORY mirrorchyan.yml -f tag=${{ steps.get_release_tag.outputs.TAG }}
gh workflow run --repo $GITHUB_REPOSITORY mirrorchyan_release_note.yml -f tag=${{ steps.get_release_tag.outputs.TAG }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SyncCNBCool:
runs-on: ubuntu-latest
needs: build-and-release
steps:
- name: Sync cnb.cool repo
run: |
curl -X 'POST' \
'https://api.cnb.cool/BlockHaity/BAAH-releases/-/build/start' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer ${{ secrets.CNB_TOKEN }}' \
-d '{ "event": "api_trigger" }'
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Auto package, tag, release on PR on: push: branches: [main] paths-ignore: - "README.md" # 忽略文档更新,避免不必要的运行 workflow_dispatch: # 允许手动触发 concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build-and-release: timeout-minutes: 30 runs-on: windows-latest # 使用Windows环境[1](@ref) env: PYTHONIOENCODING: "utf-8" PYTHONUTF8: "1" # 强制使用UTF-8编码[1,3](@ref) permissions: contents: write # 允许创建Tag和Release[2](@ref) steps: - name: Checkout main branch uses: actions/checkout@v4 with: ref: main # 明确检出main分支[5](@ref) - name: Set up Miniconda uses: conda-incubator/setup-miniconda@v4 with: miniconda-version: "py310_24.7.1-0" auto-update-conda: false activate-environment: "base" auto-activate: true - name: Cache pip uses: actions/cache@v4 if: startsWith(runner.os, 'Windows') with: path: ~\AppData\Local\pip\Cache key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - name: Upgrade pip and install dependencies shell: cmd /C CALL {0} run: | python -m pip install --upgrade pip pip install -r requirements.txt - name: Extract version number id: get_version shell: cmd /C CALL {0} run: | for /f "delims=" %%i in ('python package.py -v') do echo VERSION_NUMBER=%%i>>"%GITHUB_OUTPUT%" # 新增的标签检查步骤 - name: Check for existing tag id: check_tag shell: cmd /C CALL {0} run: | set "tag=BAAH${{ steps.get_version.outputs.VERSION_NUMBER }}" git ls-remote --exit-code --tags origin "refs/tags/%tag%" >nul 2>&1 if errorlevel 3 ( echo ::error::Failed to check tag: %tag% exit /b 1 ) else if errorlevel 1 ( echo Tag %tag% does not exist. Proceeding. exit /b 0 ) else ( echo ::error::Already has this tag: %tag% exit /b 1 ) - name: Extract version change log id: get_change_log shell: cmd /C CALL {0} run: | rem 将日志输出到文件,PYTHONIOENCODING 会确保 UTF-8 编码 python package.py -c > changelog.md - name: Build package shell: cmd /C CALL {0} run: python package.py # 执行打包脚本[8](@ref) - name: Create Git Tag shell: cmd /C CALL {0} run: | git tag "BAAH${{ steps.get_version.outputs.VERSION_NUMBER }}" git push origin "BAAH${{ steps.get_version.outputs.VERSION_NUMBER }}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 使用内置令牌[2](@ref) - name: Create Release uses: softprops/action-gh-release@v2 # 功能完整的Release Action[2,10](@ref) with: draft: false prerelease: false tag_name: BAAH${{ steps.get_version.outputs.VERSION_NUMBER }} name: BAAH${{ steps.get_version.outputs.VERSION_NUMBER }} body_path: changelog.md # 关键修改:从文件读取内容 files: ./dist/*.zip # 仅上传ZIP格式的制品[10](@ref) MirrorChyanUploading: timeout-minutes: 30 runs-on: latchkey-small needs: build-and-release steps: - name: Get latest tag id: get_release_tag shell: bash run: | response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ https://api.github.com/repos/${{ github.repository }}/releases/latest) tag=$(echo "$response" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') echo "TAG=$tag" >> $GITHUB_OUTPUT env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Trigger MirrorChyanUploading shell: bash run: | gh workflow run --repo $GITHUB_REPOSITORY mirrorchyan.yml -f tag=${{ steps.get_release_tag.outputs.TAG }} gh workflow run --repo $GITHUB_REPOSITORY mirrorchyan_release_note.yml -f tag=${{ steps.get_release_tag.outputs.TAG }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} SyncCNBCool: timeout-minutes: 30 runs-on: latchkey-small needs: build-and-release steps: - name: Sync cnb.cool repo run: | curl -X 'POST' \ 'https://api.cnb.cool/BlockHaity/BAAH-releases/-/build/start' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer ${{ secrets.CNB_TOKEN }}' \ -d '{ "event": "api_trigger" }'
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Add a job timeout so a hung step cannot burn hours of runner time.
2 third-party actions are referenced by a movable tag. Pin them to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Dependency installs
- Network fetches
This workflow runs 3 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.