2323 description : Tag version in Go release format, e.g. v1.2.3
2424 required : true
2525 type : string
26- target_ref :
26+ target_sha :
2727 description : Full 40-character commit SHA to tag
2828 required : true
2929 type : string
4141 runs-on : ubuntu-latest
4242 outputs :
4343 target_sha : ${{ steps.validate.outputs.target_sha }}
44- target_ref : ${{ steps.validate.outputs.target_ref }}
4544 full_tag : ${{ steps.validate.outputs.full_tag }}
4645 steps :
4746 - name : Checkout
5554 env :
5655 TAG_PREFIX : ${{ inputs.tag_prefix }}
5756 TAG_NAME : ${{ inputs.tag_name }}
58- TARGET_REF : ${{ inputs.target_ref }}
57+ TARGET_SHA_INPUT : ${{ inputs.target_sha }}
5958 run : |
6059 set -euo pipefail
6160
7170 exit 1
7271 fi
7372
74- if ! echo "$TARGET_REF " | grep -Eq '^[0-9a-fA-F]{40}$'; then
75- echo "target_ref must be a full 40-character commit SHA: $TARGET_REF "
73+ if ! echo "$TARGET_SHA_INPUT " | grep -Eq '^[0-9a-fA-F]{40}$'; then
74+ echo "target_sha must be a full 40-character commit SHA: $TARGET_SHA_INPUT "
7675 exit 1
7776 fi
7877
@@ -83,37 +82,29 @@ jobs:
8382
8483 git fetch --quiet origin --tags
8584
86- if ! TARGET_SHA=$(git rev-parse "$TARGET_REF^{commit}" 2>/dev/null); then
87- echo "Unable to resolve target_ref to a commit: $TARGET_REF"
88- exit 1
89- fi
90-
91- if git show-ref --verify --quiet "refs/tags/$TARGET_REF"; then
92- echo "target_ref must be a commit SHA, not a tag: $TARGET_REF"
85+ if ! TARGET_SHA=$(git rev-parse "$TARGET_SHA_INPUT^{commit}" 2>/dev/null); then
86+ echo "Unable to resolve target_sha to a commit: $TARGET_SHA_INPUT"
9387 exit 1
9488 fi
9589
9690 echo "target_sha=$TARGET_SHA" >> "$GITHUB_OUTPUT"
97- echo "target_ref=$TARGET_REF" >> "$GITHUB_OUTPUT"
9891 echo "full_tag=$FULL_TAG" >> "$GITHUB_OUTPUT"
99- echo "Validated request for $FULL_TAG on $TARGET_REF ($ TARGET_SHA) "
92+ echo "Validated request for $FULL_TAG on $TARGET_SHA"
10093
10194 create_tag :
102- name : Create Tag (Approval Required)
95+ name : Create and Push Tag
10396 runs-on : ubuntu-latest
104- needs : validate
105- # Operational requirement:
106- # - This workflow expects a GitHub Environment named `tag-approval`.
107- # - Configure that environment with required reviewers / approval rules
108- # to gate release tag creation in this repository.
109- # - In forks or newly created repositories, create and maintain the
110- # `tag-approval` environment before using this workflow, or update this
111- # workflow to reference the repository's documented approval environment.
97+ # Requires a repository environment named tag-approval.
98+ # Configure that environment with the intended approval and ruleset settings,
99+ # or this job may block awaiting approval or fail where the environment does not exist.
112100 environment : tag-approval
113101 permissions :
114102 contents : write
103+ deployments : write
104+ needs :
105+ - validate
115106 concurrency :
116- group : release-tag-${{ inputs.tag_prefix }}-${{ inputs.tag_name }}
107+ group : create- release-tag-${{ needs.validate.outputs.full_tag }}
117108 cancel-in-progress : false
118109 steps :
119110 - name : Checkout target commit
@@ -133,11 +124,35 @@ jobs:
133124 exit 1
134125 fi
135126
127+ - name : Record successful tag-approval deployment for target SHA
128+ env :
129+ TARGET_SHA : ${{ needs.validate.outputs.target_sha }}
130+ GH_TOKEN : ${{ github.token }}
131+ run : |
132+ set -euo pipefail
133+
134+ DEPLOYMENT_ID=$(gh api \
135+ --method POST \
136+ -H "Accept: application/vnd.github+json" \
137+ "/repos/${GITHUB_REPOSITORY}/deployments" \
138+ -f ref="$TARGET_SHA" \
139+ -f environment="tag-approval" \
140+ -f required_contexts[] \
141+ -F auto_merge=false \
142+ --jq '.id')
143+
144+ gh api \
145+ --method POST \
146+ -H "Accept: application/vnd.github+json" \
147+ "/repos/${GITHUB_REPOSITORY}/deployments/${DEPLOYMENT_ID}/statuses" \
148+ -f state="success" \
149+ -f environment="tag-approval" \
150+ -f auto_inactive=false >/dev/null
151+
136152 - name : Create and push annotated tag
137153 env :
138154 FULL_TAG : ${{ needs.validate.outputs.full_tag }}
139155 TARGET_SHA : ${{ needs.validate.outputs.target_sha }}
140- TARGET_REF : ${{ needs.validate.outputs.target_ref }}
141156 REASON : ${{ inputs.reason }}
142157 GITHUB_TOKEN : ${{ github.token }}
143158 run : |
@@ -148,10 +163,9 @@ jobs:
148163
149164 RUN_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
150165 TAG_MESSAGE=$(cat <<EOF
151- Release $FULL_TAG
166+ $FULL_TAG
152167
153168 Target SHA: $TARGET_SHA
154- Target Ref: $TARGET_REF
155169 Requested By: $GITHUB_ACTOR
156170 Reason: $REASON
157171 Workflow Run: $RUN_URL
@@ -165,15 +179,13 @@ jobs:
165179 env :
166180 FULL_TAG : ${{ needs.validate.outputs.full_tag }}
167181 TARGET_SHA : ${{ needs.validate.outputs.target_sha }}
168- TARGET_REF : ${{ needs.validate.outputs.target_ref }}
169182 REASON : ${{ inputs.reason }}
170183 run : |
171184 {
172185 echo "## Release Tag Created"
173186 echo ""
174187 echo "- Tag: $FULL_TAG"
175188 echo "- Target SHA: $TARGET_SHA"
176- echo "- Target Ref: $TARGET_REF"
177189 echo "- Requested By: $GITHUB_ACTOR"
178190 echo "- Reason: $REASON"
179191 echo "- Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
0 commit comments