Files
wehub-resource-sync f3d80b4628
Auto Release / auto-release (push) Failing after 1s
CI / lint (push) Failing after 0s
CI / screenshot-quality (push) Failing after 3s
CI / pr-policy (push) Has been skipped
CI / test (3.11) (push) Failing after 0s
CI / test (3.12) (push) Failing after 0s
CI / test (3.13) (push) Failing after 3s
CI / coverage (push) Failing after 1s
Legibility / legibility (push) Failing after 3s
chore: import upstream snapshot with attribution
2026-07-13 12:31:48 +08:00

143 lines
4.6 KiB
YAML

name: Auto Release
on:
push:
branches: [main]
jobs:
auto-release:
# Skip explicit non-release commits to avoid loops.
if: >
!startsWith(github.event.head_commit.message, 'chore: bump version') &&
!contains(github.event.head_commit.message, '[skip release]')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Validate release bot token
env:
RELEASE_BOT_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
run: |
if [ -z "$RELEASE_BOT_TOKEN" ]; then
echo "::error::RELEASE_BOT_TOKEN secret is required for release automation"
exit 1
fi
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_BOT_TOKEN }}
- name: Calculate next patch version
id: version
run: |
latest=$(git tag --list 'v*' --sort=-v:refname | head -1)
if [ -z "$latest" ]; then
next="v0.1.0"
else
ver="${latest#v}"
major=$(echo "$ver" | cut -d. -f1)
minor=$(echo "$ver" | cut -d. -f2)
patch=$(echo "$ver" | cut -d. -f3)
next="v${major}.${minor}.$((patch + 1))"
fi
echo "tag=$next" >> "$GITHUB_OUTPUT"
echo "Next version: $next"
- name: Update changelog for next version
id: changelog
env:
GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
run: |
tag="${{ steps.version.outputs.tag }}"
version="${tag#v}"
python scripts/update_changelog.py --version "$version"
if git diff --quiet CHANGELOG.md; then
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
branch="release/${tag}"
pr_body_file="$(mktemp)"
cat > "$pr_body_file" <<EOF
## Summary
- Update CHANGELOG.md for ${tag}.
- Continue the automated release after changelog bookkeeping.
## Validation
- Generated by the auto-release workflow.
- Release PR checks must pass before the workflow merges this changelog PR.
## Evidence
- Not required; changelog-only release PR.
EOF
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -c "$branch"
git add CHANGELOG.md
git commit -m "chore: update changelog for $tag"
release_commit="$(git rev-parse HEAD)"
pr_number="$(gh pr list --head "$branch" --state open --json number --jq '.[0].number // ""')"
if [ -n "$pr_number" ]; then
gh pr edit "$pr_number" --body-file "$pr_body_file"
fi
git push --force-with-lease origin "$branch"
if [ -n "$pr_number" ]; then
echo "Release changelog PR #$pr_number already exists"
else
pr_url="$(gh pr create \
--base main \
--head "$branch" \
--title "chore: update changelog for $tag" \
--body-file "$pr_body_file")"
pr_number="${pr_url##*/}"
fi
pr_head=""
for _ in $(seq 1 30); do
pr_head="$(gh pr view "$pr_number" --json headRefOid --jq '.headRefOid')"
if [ "$pr_head" = "$release_commit" ]; then
break
fi
echo "Waiting for release PR head to update to ${release_commit}..."
sleep 10
done
if [ "$pr_head" != "$release_commit" ]; then
echo "::error::Release PR #${pr_number} did not update to ${release_commit}"
exit 1
fi
check_count=0
for _ in $(seq 1 30); do
check_count="$(gh pr checks "$pr_number" --json name --jq 'length' 2>/dev/null || true)"
if [ "${check_count:-0}" -gt 0 ]; then
break
fi
echo "Waiting for release PR checks to start..."
sleep 10
done
if [ "${check_count:-0}" -eq 0 ]; then
echo "::error::No release PR checks started for #${pr_number}"
exit 1
fi
gh pr checks "$pr_number" --watch --fail-fast --interval 10
gh pr merge "$pr_number" --admin --squash --delete-branch
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Create and push tag
if: steps.changelog.outputs.changed == 'false'
run: |
tag="${{ steps.version.outputs.tag }}"
git tag "$tag"
git push origin "$tag"
echo "Created tag $tag"