|
| 1 | +name: Validate Power Advantage release tag |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '*.*.*.*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + actions: read |
| 10 | + contents: read |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: poweradvantage-release-tag-${{ github.ref_name }} |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + validate-release-tag: |
| 18 | + name: Validate tag for manual release confirmation |
| 19 | + if: github.repository == 'MinecraftModDevelopmentMods/PowerAdvantage' |
| 20 | + runs-on: ubuntu-latest |
| 21 | + timeout-minutes: 10 |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Check out tagged source |
| 25 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Validate release tag, target metadata, and prior CI |
| 30 | + env: |
| 31 | + GH_TOKEN: ${{ github.token }} |
| 32 | + run: | |
| 33 | + set -euo pipefail |
| 34 | +
|
| 35 | + value() { sed -n "s/^$1=//p" gradle.properties; } |
| 36 | + release_version="$(value mod_version)" |
| 37 | + minecraft_version="$(value minecraft_version)" |
| 38 | + loader_name="$(value loader_name)" |
| 39 | + loader_code="$(value loader_code)" |
| 40 | +
|
| 41 | + IFS=. read -r mc_major mc_minor mc_patch extra <<<"$minecraft_version" |
| 42 | + if [[ -n "${extra:-}" || -z "${mc_major:-}" || -z "${mc_minor:-}" ]]; then |
| 43 | + echo "Invalid minecraft_version=$minecraft_version" >&2 |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + mc_patch="${mc_patch:-0}" |
| 47 | + if [[ ! "$mc_major" =~ ^[0-9]+$ || ! "$mc_minor" =~ ^[0-9]+$ || ! "$mc_patch" =~ ^[0-9]+$ ]]; then |
| 48 | + echo "Invalid minecraft_version=$minecraft_version" >&2 |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + case "$loader_name:$loader_code" in |
| 52 | + forge:1|neoforge:2) ;; |
| 53 | + *) echo "Invalid loader metadata $loader_name/$loader_code" >&2; exit 1 ;; |
| 54 | + esac |
| 55 | + printf -v minor_padded '%02d' "$((10#$mc_minor))" |
| 56 | + printf -v patch_padded '%02d' "$((10#$mc_patch))" |
| 57 | + target_suffix="${mc_major}${minor_padded}${patch_padded}${loader_code}" |
| 58 | +
|
| 59 | + if [[ ! "$release_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.${target_suffix}$ ]]; then |
| 60 | + echo "mod_version $release_version does not match $minecraft_version $loader_name target $target_suffix" >&2 |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + if [[ "$GITHUB_REF_NAME" != "$release_version" ]]; then |
| 64 | + echo "Release tag must equal mod_version $release_version; found $GITHUB_REF_NAME" >&2 |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +
|
| 68 | + successful_ci="$(gh api \ |
| 69 | + "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/check-runs?per_page=100" \ |
| 70 | + --jq '[.check_runs[] | select(.name == "Build, test, and audit" and .conclusion == "success")] | length')" |
| 71 | + if [[ "$successful_ci" -lt 1 ]]; then |
| 72 | + echo "The tagged commit has no successful Build, test, and audit check" >&2 |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | +
|
| 76 | + - name: Record the required manual publication step |
| 77 | + env: |
| 78 | + RELEASE_WORKFLOW_URL: https://github.com/${{ github.repository }}/actions/workflows/deploy-release.yml |
| 79 | + run: | |
| 80 | + { |
| 81 | + echo "## Release candidate validated" |
| 82 | + echo |
| 83 | + echo "Tag \`$GITHUB_REF_NAME\` matches this target and has a successful Build, test, and audit check." |
| 84 | + echo |
| 85 | + echo "**Nothing has been published.**" |
| 86 | + echo |
| 87 | + echo "Live publication requires \`deploy-release.yml\` on the repository default branch." |
| 88 | + echo "Once that guarded dispatcher is installed, continue at: $RELEASE_WORKFLOW_URL" |
| 89 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments