File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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" \
You can’t perform that action at this time.
0 commit comments