Skip to content

Commit 1305ba9

Browse files
committed
Fix CI not attaching a "View deployment" button in PRs for build links
1 parent d3f36a9 commit 1305ba9

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

.github/workflows/build.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,21 @@ jobs:
157157
REF="master"
158158
ENVIRONMENT="graphite-dev (Production)"
159159
else
160-
REF="$(git rev-parse HEAD)"
160+
REF="${{ inputs.checkout_ref || github.head_ref || github.ref_name }}"
161161
ENVIRONMENT="graphite-dev (Preview)"
162162
fi
163-
DEPLOY_ID=$(gh api \
164-
-X POST \
165-
-H "Accept: application/vnd.github+json" \
166-
repos/${{ github.repository }}/deployments \
167-
--input - \
168-
--jq '.id' <<EOF
169-
{"ref":"$REF","environment":"$ENVIRONMENT","auto_merge":false,"required_contexts":[]}
163+
create_deployment() {
164+
gh api \
165+
-X POST \
166+
-H "Accept: application/vnd.github+json" \
167+
repos/${{ github.repository }}/deployments \
168+
--input - \
169+
--jq '.id' <<EOF
170+
{"ref":"$1","environment":"$ENVIRONMENT","auto_merge":false,"required_contexts":[]}
170171
EOF
171-
)
172+
}
173+
# Try branch name first (needed for GitHub's PR "View deployment" button), fall back to commit SHA if the branch was deleted
174+
DEPLOY_ID=$(create_deployment "$REF" 2>/dev/null) || DEPLOY_ID=$(create_deployment "$(git rev-parse HEAD)")
172175
gh api \
173176
-X POST \
174177
-H "Accept: application/vnd.github+json" \

0 commit comments

Comments
 (0)