Skip to content

Commit bf20cce

Browse files
committed
ci(cli): publish previews after tests pass
1 parent 963235e commit bf20cce

1 file changed

Lines changed: 38 additions & 79 deletions

File tree

.github/workflows/pkg-pr-new.yml

Lines changed: 38 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ on:
77
- Smoke Test (PR)
88
types:
99
- completed
10-
pull_request_review:
11-
types:
12-
- submitted
1310

1411
permissions:
1512
actions: read
@@ -19,32 +16,22 @@ permissions:
1916
pull-requests: read
2017

2118
concurrency:
22-
group: pkg-pr-new-${{ github.event.workflow_run.head_sha || github.event.pull_request.head.sha || github.run_id }}
19+
group: pkg-pr-new-${{ github.event.workflow_run.head_sha || github.run_id }}
2320
cancel-in-progress: false
2421

2522
jobs:
2623
publish:
2724
name: Publish preview package
2825
runs-on: ubuntu-latest
2926
if: >-
30-
(
31-
github.event_name == 'workflow_run' &&
32-
github.event.workflow_run.event == 'pull_request' &&
33-
github.event.workflow_run.conclusion == 'success'
34-
) ||
35-
(
36-
github.event_name == 'pull_request_review' &&
37-
github.event.review.state == 'approved' &&
38-
github.event.pull_request.draft == false &&
39-
github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
40-
)
27+
github.event.workflow_run.event == 'pull_request' &&
28+
github.event.workflow_run.conclusion == 'success'
4129
env:
4230
GH_TOKEN: ${{ github.token }}
4331
steps:
4432
- name: Resolve publish context
4533
id: context
4634
env:
47-
EVENT_NAME: ${{ github.event_name }}
4835
REPOSITORY: ${{ github.repository }}
4936
run: |
5037
set -euo pipefail
@@ -55,47 +42,42 @@ jobs:
5542
smoke_run_id=""
5643
test_run_id=""
5744
58-
if [[ "${EVENT_NAME}" == "workflow_run" ]]; then
59-
pr_number="$(jq -r '.workflow_run.pull_requests[0].number // ""' "$GITHUB_EVENT_PATH")"
60-
pr_head_sha="$(jq -r '.workflow_run.head_sha // ""' "$GITHUB_EVENT_PATH")"
61-
pr_head_branch="$(jq -r '.workflow_run.head_branch // ""' "$GITHUB_EVENT_PATH")"
62-
triggering_workflow="$(jq -r '.workflow_run.name // ""' "$GITHUB_EVENT_PATH")"
63-
64-
if [[ -z "${pr_head_sha}" ]]; then
65-
echo "Workflow run has no head SHA; skipping."
66-
echo "should_publish=false" >> "$GITHUB_OUTPUT"
67-
exit 0
68-
fi
69-
70-
if [[ -z "${pr_number}" && -n "${pr_head_branch}" ]]; then
71-
pr_number="$(
72-
gh pr list \
73-
--repo "${REPOSITORY}" \
74-
--head "${pr_head_branch}" \
75-
--state open \
76-
--json number,headRefOid \
77-
--jq 'map(select(.headRefOid == "'"${pr_head_sha}"'")) | .[0].number // ""'
78-
)"
79-
fi
80-
81-
if [[ -z "${pr_number}" ]]; then
82-
echo "Workflow run is not associated with an open pull request; skipping."
83-
echo "should_publish=false" >> "$GITHUB_OUTPUT"
84-
exit 0
85-
fi
86-
87-
if [[ "${triggering_workflow}" == "Smoke Test (PR)" ]]; then
88-
smoke_run_id="$(jq -r '.workflow_run.id' "$GITHUB_EVENT_PATH")"
89-
elif [[ "${triggering_workflow}" == "Test" ]]; then
90-
test_run_id="$(jq -r '.workflow_run.id' "$GITHUB_EVENT_PATH")"
91-
else
92-
echo "Unexpected triggering workflow: ${triggering_workflow}; skipping."
93-
echo "should_publish=false" >> "$GITHUB_OUTPUT"
94-
exit 0
95-
fi
45+
pr_number="$(jq -r '.workflow_run.pull_requests[0].number // ""' "$GITHUB_EVENT_PATH")"
46+
pr_head_sha="$(jq -r '.workflow_run.head_sha // ""' "$GITHUB_EVENT_PATH")"
47+
pr_head_branch="$(jq -r '.workflow_run.head_branch // ""' "$GITHUB_EVENT_PATH")"
48+
triggering_workflow="$(jq -r '.workflow_run.name // ""' "$GITHUB_EVENT_PATH")"
49+
50+
if [[ -z "${pr_head_sha}" ]]; then
51+
echo "Workflow run has no head SHA; skipping."
52+
echo "should_publish=false" >> "$GITHUB_OUTPUT"
53+
exit 0
54+
fi
55+
56+
if [[ -z "${pr_number}" && -n "${pr_head_branch}" ]]; then
57+
pr_number="$(
58+
gh pr list \
59+
--repo "${REPOSITORY}" \
60+
--head "${pr_head_branch}" \
61+
--state open \
62+
--json number,headRefOid \
63+
--jq 'map(select(.headRefOid == "'"${pr_head_sha}"'")) | .[0].number // ""'
64+
)"
65+
fi
66+
67+
if [[ -z "${pr_number}" ]]; then
68+
echo "Workflow run is not associated with an open pull request; skipping."
69+
echo "should_publish=false" >> "$GITHUB_OUTPUT"
70+
exit 0
71+
fi
72+
73+
if [[ "${triggering_workflow}" == "Smoke Test (PR)" ]]; then
74+
smoke_run_id="$(jq -r '.workflow_run.id' "$GITHUB_EVENT_PATH")"
75+
elif [[ "${triggering_workflow}" == "Test" ]]; then
76+
test_run_id="$(jq -r '.workflow_run.id' "$GITHUB_EVENT_PATH")"
9677
else
97-
pr_number="$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH")"
98-
pr_head_sha="$(jq -r '.pull_request.head.sha' "$GITHUB_EVENT_PATH")"
78+
echo "Unexpected triggering workflow: ${triggering_workflow}; skipping."
79+
echo "should_publish=false" >> "$GITHUB_OUTPUT"
80+
exit 0
9981
fi
10082
10183
pr_json="$(gh api "repos/${REPOSITORY}/pulls/${pr_number}")"
@@ -129,29 +111,6 @@ jobs:
129111
exit 0
130112
fi
131113
132-
review_decision="$(
133-
gh api graphql \
134-
-f owner="${REPOSITORY%/*}" \
135-
-f repo="${REPOSITORY#*/}" \
136-
-F number="${pr_number}" \
137-
-f query='
138-
query($owner: String!, $repo: String!, $number: Int!) {
139-
repository(owner: $owner, name: $repo) {
140-
pullRequest(number: $number) {
141-
reviewDecision
142-
}
143-
}
144-
}
145-
' \
146-
--jq '.data.repository.pullRequest.reviewDecision // ""'
147-
)"
148-
149-
if [[ "${review_decision}" != "APPROVED" ]]; then
150-
echo "PR #${pr_number} review decision is ${review_decision:-<none>}; skipping."
151-
echo "should_publish=false" >> "$GITHUB_OUTPUT"
152-
exit 0
153-
fi
154-
155114
if [[ -z "${smoke_run_id}" ]]; then
156115
smoke_run_id="$(
157116
gh run list \

0 commit comments

Comments
 (0)