Files
anki/.github/workflows/prepare-release.yml
Luc Mcgrady fc5103bc33 chore(ci):Use commit SHAs for github actions (#4916)
<!--
Title (for the Pull Request title field at the top):
Use a short prefix so the change type is obvious. You do not need to
repeat it in the body below.

Examples:
- fix: — bugfix
- feat: — feature
- refactor: — internal change without user-facing feature
- docs: — documentation only
- chore: — tooling, CI, deps, build housekeeping
- test: — tests only
-->

## Linked issue (required)

<!-- Fixes #123 / Closes #123 / Refs #123 -->
closes #4722

## Summary / motivation (required)

<!-- What this PR does and why. For larger changes, add enough context
for reviewers. -->
I used this nice script I found:
https://gist.github.com/onnimonni/3462f958c7d235417863651974514525

For the reasons behind this change see:
- #4722

## Steps to reproduce (required, use N/A if not applicable)

<!-- Steps to reproduce: how to trigger the bug in the broken state (the
"before").
 - Mainly for bugfixes;
    - For bugs: numbered steps before the fix. For non-bugs: write N/A.
 - use N/A for features, refactors, docs, chore, etc.
-->
(N/A)

## How to test (required)

<!--- How to test: how you verified the change (checks, unit tests,
manual steps, edge cases — the "after" or general validation). --->
See it run in my repo here:
https://github.com/Luc-Mcgrady/anki/actions/runs/26718877866

### Checklist (minimum)

- [X] I ran `./ninja check` or an equivalent relevant check locally.
- [ ] I added or updated tests when the change is non-trivial or
behavior changed.

### Details

<!-- Commands, manual steps, edge cases, and what you observed -->
## Before / after behavior (optional)

<!-- For bugfixes: behavior before vs after. For other types: N/A or a
short note. -->

## Risk / compatibility / migration (optional)

<!-- Breaking changes, rollout notes, or N/A for small / low-risk PRs
-->

## UI evidence (required for visual changes; otherwise N/A)

<!-- Screenshot or short video -->

## Scope

- [X] This PR is focused on one change (no unrelated edits).
2026-06-02 10:35:32 -03:00

107 lines
3.2 KiB
YAML

name: Prepare Release
run-name: "Prepare release ${{ inputs.version }}"
on:
workflow_dispatch:
inputs:
version:
description: "Version (e.g. 26.04 for stable, 26.04b1 or 26.04rc1 for pre-release)"
required: true
type: string
skip-ci-check:
description: "Skip the CI status check (for hotfix releases from non-main branches)"
default: false
required: false
type: boolean
permissions:
contents: write
actions: read
concurrency:
group: release
cancel-in-progress: false
env:
N2_OUTPUT_PROGRESS: "1"
N2_OUTPUT_SUCCESS: "1"
jobs:
prepare:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 #v4
with:
submodules: true
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN }}
- name: Validate version
run: |
pip install --break-system-packages 'packaging>=24,<26'
current_version=$(cat .version)
echo "Current .version: $current_version"
python3 .github/scripts/validate_version.py "$INPUT_VERSION" "$current_version"
echo "Version check passed"
env:
INPUT_VERSION: ${{ inputs.version }}
- name: Check CI passed
if: inputs.skip-ci-check != true
run: |
conclusion=$(gh run list \
--workflow=ci.yml \
--commit "$COMMIT_SHA" \
--limit 5 \
--json conclusion,event \
--jq '[.[] | select(.event == "push" or .event == "workflow_dispatch")][0].conclusion')
if [[ -z "$conclusion" ]]; then
echo "::error::Could not determine CI status for commit $COMMIT_SHA"
exit 1
elif [[ "$conclusion" != "success" ]]; then
echo "::error::CI for commit $COMMIT_SHA concluded with '$conclusion'"
exit 1
fi
env:
GH_TOKEN: ${{ github.token }}
COMMIT_SHA: ${{ github.sha }}
- name: Check for duplicate tag or release
run: |
git fetch --tags origin
if git rev-parse "refs/tags/$INPUT_VERSION" >/dev/null 2>&1; then
echo "::error::Tag '$INPUT_VERSION' already exists"
exit 1
fi
if gh release view "$INPUT_VERSION" >/dev/null 2>&1; then
echo "::error::GitHub release '$INPUT_VERSION' already exists"
exit 1
fi
env:
GH_TOKEN: ${{ github.token }}
INPUT_VERSION: ${{ inputs.version }}
- name: Sync translations
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
python3 .github/scripts/sync_translations.py
env:
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
ANKI_NO_GIT_PUSH: "1"
- name: Update .version and commit
run: |
printf '%s' "$INPUT_VERSION" > .version
git add .version
git commit -m "Prepare release $INPUT_VERSION"
env:
INPUT_VERSION: ${{ inputs.version }}
- name: Push to branch
run: git push origin HEAD:refs/heads/$BRANCH
env:
BRANCH: ${{ github.ref_name }}