Skip to content

Commit 5376bbd

Browse files
committed
Add validated release tag action
1 parent a794d66 commit 5376bbd

1 file changed

Lines changed: 143 additions & 0 deletions

File tree

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: Create OreSpawn release tag
2+
run-name: Create OreSpawn tag from ${{ inputs.release_ref }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
release_ref:
8+
description: MMD target branch or commit to tag, for example master-1.10.2.
9+
required: true
10+
default: master-1.10.2
11+
type: string
12+
confirm_version:
13+
description: Exact four-component version declared by the target, for example 4.0.8.110021.
14+
required: true
15+
type: string
16+
17+
permissions:
18+
actions: read
19+
contents: write
20+
21+
concurrency:
22+
group: orespawn-create-tag-${{ inputs.confirm_version }}
23+
cancel-in-progress: false
24+
25+
jobs:
26+
create-release-tag:
27+
name: Validate candidate and create tag
28+
if: github.repository == 'MinecraftModDevelopmentMods/OreSpawn'
29+
runs-on: ubuntu-latest
30+
timeout-minutes: 10
31+
32+
steps:
33+
- name: Check out selected release candidate
34+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
35+
with:
36+
ref: ${{ inputs.release_ref }}
37+
fetch-depth: 0
38+
39+
- name: Validate target, version, and prior CI
40+
id: validate
41+
env:
42+
GH_TOKEN: ${{ github.token }}
43+
CONFIRM_VERSION: ${{ inputs.confirm_version }}
44+
run: |
45+
set -euo pipefail
46+
47+
value() { sed -n "s/^$1=//p" gradle.properties; }
48+
release_version="$(value mod_version)"
49+
minecraft_version="$(value minecraft_version)"
50+
loader_name="$(value loader_name)"
51+
loader_code="$(value loader_code)"
52+
53+
for required in release_version minecraft_version loader_name loader_code; do
54+
if [[ -z "${!required}" ]]; then
55+
echo "Selected ref is missing required release metadata: $required" >&2
56+
exit 1
57+
fi
58+
done
59+
60+
IFS=. read -r mc_major mc_minor mc_patch extra <<<"$minecraft_version"
61+
if [[ -n "${extra:-}" || -z "${mc_major:-}" || -z "${mc_minor:-}" ]]; then
62+
echo "Invalid minecraft_version=$minecraft_version" >&2
63+
exit 1
64+
fi
65+
mc_patch="${mc_patch:-0}"
66+
if [[ ! "$mc_major" =~ ^[0-9]+$ || ! "$mc_minor" =~ ^[0-9]+$ || ! "$mc_patch" =~ ^[0-9]+$ ]]; then
67+
echo "Invalid minecraft_version=$minecraft_version" >&2
68+
exit 1
69+
fi
70+
case "$loader_name:$loader_code" in
71+
forge:1|neoforge:2) ;;
72+
*) echo "Invalid loader metadata $loader_name/$loader_code" >&2; exit 1 ;;
73+
esac
74+
75+
printf -v minor_padded '%02d' "$((10#$mc_minor))"
76+
printf -v patch_padded '%02d' "$((10#$mc_patch))"
77+
target_suffix="${mc_major}${minor_padded}${patch_padded}${loader_code}"
78+
if [[ ! "$release_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.${target_suffix}$ ]]; then
79+
echo "mod_version $release_version does not match $minecraft_version $loader_name target $target_suffix" >&2
80+
exit 1
81+
fi
82+
if [[ "$CONFIRM_VERSION" != "$release_version" ]]; then
83+
echo "confirm_version must equal $release_version" >&2
84+
exit 1
85+
fi
86+
if [[ ! -f .github/workflows/release-on-tag.yml ]]; then
87+
echo "Selected target has not adopted the validated tag workflow" >&2
88+
exit 1
89+
fi
90+
91+
release_sha="$(git rev-parse HEAD)"
92+
successful_ci="$(gh api \
93+
"repos/$GITHUB_REPOSITORY/commits/$release_sha/check-runs?per_page=100" \
94+
--jq '[.check_runs[] | select(.name == "Build, test, and audit" and .conclusion == "success")] | length')"
95+
if [[ "$successful_ci" -lt 1 ]]; then
96+
echo "The selected commit has no successful Build, test, and audit check" >&2
97+
exit 1
98+
fi
99+
if gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$release_version" >/dev/null 2>&1; then
100+
echo "Tag $release_version already exists" >&2
101+
exit 1
102+
fi
103+
104+
echo "release_version=$release_version" >> "$GITHUB_OUTPUT"
105+
echo "release_sha=$release_sha" >> "$GITHUB_OUTPUT"
106+
107+
- name: Create the validated release tag
108+
env:
109+
GH_TOKEN: ${{ github.token }}
110+
RELEASE_VERSION: ${{ steps.validate.outputs.release_version }}
111+
RELEASE_SHA: ${{ steps.validate.outputs.release_sha }}
112+
run: |
113+
set -euo pipefail
114+
gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" \
115+
-f ref="refs/tags/$RELEASE_VERSION" \
116+
-f sha="$RELEASE_SHA" >/dev/null
117+
118+
created_sha="$(gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$RELEASE_VERSION" --jq '.object.sha')"
119+
if [[ "$created_sha" != "$RELEASE_SHA" ]]; then
120+
echo "Created tag resolved to $created_sha instead of $RELEASE_SHA" >&2
121+
exit 1
122+
fi
123+
124+
- name: Show the manual publication step
125+
env:
126+
RELEASE_VERSION: ${{ steps.validate.outputs.release_version }}
127+
RELEASE_SHA: ${{ steps.validate.outputs.release_sha }}
128+
RELEASE_WORKFLOW_URL: https://github.com/${{ github.repository }}/actions/workflows/deploy-release.yml
129+
run: |
130+
{
131+
echo "## Release tag created"
132+
echo
133+
echo "Tag \`$RELEASE_VERSION\` now points to validated commit \`$RELEASE_SHA\`."
134+
echo
135+
echo "**Nothing has been published.**"
136+
echo
137+
echo "To continue, open [Deploy OreSpawn release]($RELEASE_WORKFLOW_URL), select **Run workflow**, and enter:"
138+
echo
139+
echo "- mode: \`publish\`"
140+
echo "- release_ref: \`$RELEASE_VERSION\`"
141+
echo "- curseforge_channel: \`release\`, \`beta\`, or \`alpha\`"
142+
echo "- confirm_version: \`$RELEASE_VERSION\`"
143+
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)