| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- name: Release APK
- on:
- workflow_dispatch:
- inputs:
- build_run_id:
- description: '成功的 Auto Build workflow run ID'
- required: true
- type: string
- permissions:
- actions: read
- contents: write
- jobs:
- release:
- # 与原自动发布权限保持一致;请在仓库 Settings 中按需改成你的 GitHub 用户名。
- if: github.actor == 'HapeLee'
- runs-on: ubuntu-latest
- steps:
- - name: Validate the selected build
- id: build
- env:
- GH_TOKEN: ${{ github.token }}
- RUN_ID: ${{ inputs.build_run_id }}
- run: |
- set -euo pipefail
- api="https://api.github.com/repos/${GITHUB_REPOSITORY}"
- run=$(curl --fail-with-body -sS \
- -H "Authorization: Bearer ${GH_TOKEN}" \
- -H "Accept: application/vnd.github+json" \
- "${api}/actions/runs/${RUN_ID}")
- test "$(jq -r '.name' <<<"${run}")" = "Auto Build"
- test "$(jq -r '.conclusion' <<<"${run}")" = success
- test "$(jq -r '.head_branch' <<<"${run}")" = main
- echo "sha=$(jq -r '.head_sha' <<<"${run}")" >> "$GITHUB_OUTPUT"
- - name: Check out the built commit
- uses: actions/checkout@v5
- with:
- ref: ${{ steps.build.outputs.sha }}
- fetch-depth: 0
- - name: Download artifacts from the selected build
- env:
- GH_TOKEN: ${{ github.token }}
- RUN_ID: ${{ inputs.build_run_id }}
- run: |
- set -euo pipefail
- api="https://api.github.com/repos/${GITHUB_REPOSITORY}"
- mkdir artifacts
- curl --fail-with-body -sS \
- -H "Authorization: Bearer ${GH_TOKEN}" \
- -H "Accept: application/vnd.github+json" \
- "${api}/actions/runs/${RUN_ID}/artifacts?per_page=100" > artifacts.json
- jq -r '.artifacts[] | select(.expired | not) | select(
- .name == "universal-apk-release" or
- .name == "arm64-v8a-apk-release" or
- .name == "armeabi-v7a-apk-release" or
- .name == "legado.app.release.mapping" or
- .name == "release-metadata"
- ) | .archive_download_url' artifacts.json | while read -r url; do
- curl --fail-with-body -sSL \
- -H "Authorization: Bearer ${GH_TOKEN}" \
- -H "Accept: application/vnd.github+json" \
- "$url" -o artifact.zip
- unzip -o artifact.zip -d artifacts
- done
- test -f artifacts/release-metadata.env
- - name: Prepare release files and notes
- id: release
- run: |
- set -euo pipefail
- source artifacts/release-metadata.env
- test -n "$VERSIONL"
- mkdir release
- for apk in artifacts/*.apk; do
- case "$apk" in
- *arm64-v8a*) suffix=-arm64-v8a ;;
- *armeabi-v7a*) suffix=-armeabi-v7a ;;
- *) suffix= ;;
- esac
- mv "$apk" "release/legado-${VERSIONL}${suffix}.apk"
- done
- if [ -f artifacts/mapping.txt ]; then mv artifacts/mapping.txt release/; fi
- if [ -n "$LATEST_TAG" ] && git rev-parse -q --verify "refs/tags/$LATEST_TAG" >/dev/null; then
- notes=$(git log "$LATEST_TAG"..HEAD --pretty=format:'* %s' --no-merges)
- else
- notes=$(git log -1 --pretty=format:'* %s')
- fi
- [ -n "$notes" ] || notes='- 没有新的 Commit 记录。'
- {
- echo 'custom_body<<EOF'
- if [ "$IS_RELEASE" != true ]; then
- echo '**此版本为测试版,会存在不稳定问题。**'
- echo '### [发布页](https://t.me/materado)'
- echo '### [反馈群组](https://t.me/+Yn1_v5PZqddmMjQ1)'
- echo
- fi
- echo '### 具体更新内容'
- echo
- echo "$notes"
- echo EOF
- } >> "$GITHUB_OUTPUT"
- echo "version=$VERSIONL" >> "$GITHUB_OUTPUT"
- echo "previous_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT"
- echo "prerelease=$([ "$IS_RELEASE" = true ] && echo false || echo true)" >> "$GITHUB_OUTPUT"
- - name: Create tag at the built commit
- env:
- VERSION: ${{ steps.release.outputs.version }}
- run: |
- if git rev-parse -q --verify "refs/tags/$VERSION" >/dev/null; then
- test "$(git rev-list -n 1 "$VERSION")" = "${{ steps.build.outputs.sha }}"
- else
- git tag "$VERSION" "${{ steps.build.outputs.sha }}"
- git push origin "$VERSION"
- fi
- - name: Generate GitHub release notes
- id: notes
- env:
- GH_TOKEN: ${{ github.token }}
- VERSION: ${{ steps.release.outputs.version }}
- SHA: ${{ steps.build.outputs.sha }}
- PREVIOUS_TAG: ${{ steps.release.outputs.previous_tag }}
- CUSTOM_BODY: ${{ steps.release.outputs.custom_body }}
- run: |
- set -euo pipefail
- payload=$(jq -n \
- --arg tag_name "$VERSION" \
- --arg target_commitish "$SHA" \
- --arg previous_tag_name "$PREVIOUS_TAG" \
- '{tag_name: $tag_name, target_commitish: $target_commitish} +
- (if $previous_tag_name == "" then {} else {previous_tag_name: $previous_tag_name} end)')
- generated=$(curl --fail-with-body -sS -X POST \
- -H "Authorization: Bearer ${GH_TOKEN}" \
- -H "Accept: application/vnd.github+json" \
- "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/generate-notes" \
- -d "$payload" | jq -r .body)
- {
- echo 'body<<EOF'
- echo "$generated"
- echo
- echo "$CUSTOM_BODY"
- echo EOF
- } >> "$GITHUB_OUTPUT"
- - name: Create GitHub release
- uses: softprops/action-gh-release@v2
- with:
- tag_name: ${{ steps.release.outputs.version }}
- name: ${{ steps.release.outputs.prerelease == 'true' && format('Pre-release {0}', steps.release.outputs.version) || format('Release {0}', steps.release.outputs.version) }}
- body: ${{ steps.notes.outputs.body }}
- prerelease: ${{ steps.release.outputs.prerelease }}
- files: release/*
|