|
1 | 1 | name: Publish Preview CLI Packages |
2 | 2 |
|
3 | 3 | on: |
4 | | - workflow_run: |
5 | | - workflows: |
6 | | - - Test |
| 4 | + pull_request: |
7 | 5 | types: |
8 | | - - completed |
| 6 | + - opened |
| 7 | + - synchronize |
| 8 | + - reopened |
| 9 | + - ready_for_review |
| 10 | + branches: |
| 11 | + - develop |
9 | 12 |
|
10 | 13 | permissions: |
11 | 14 | actions: read |
12 | 15 | contents: read |
13 | | - pull-requests: read |
14 | 16 |
|
15 | 17 | concurrency: |
16 | | - group: ${{ github.workflow }}-${{ github.event.workflow_run.head_sha || github.run_id }} |
| 18 | + group: ${{ github.workflow }}-${{ github.head_ref }} |
17 | 19 | cancel-in-progress: true |
18 | 20 |
|
19 | 21 | jobs: |
20 | | - resolve: |
21 | | - if: >- |
22 | | - github.event.workflow_run.event == 'pull_request' && |
23 | | - github.event.workflow_run.conclusion == 'success' |
24 | | - name: Resolve preview build context |
25 | | - runs-on: ubuntu-latest |
26 | | - env: |
27 | | - GH_TOKEN: ${{ github.token }} |
28 | | - REPOSITORY: ${{ github.repository }} |
29 | | - outputs: |
30 | | - should_build: ${{ steps.context.outputs.should_build }} |
31 | | - pr_number: ${{ steps.context.outputs.pr_number }} |
32 | | - pr_head_sha: ${{ steps.context.outputs.pr_head_sha }} |
33 | | - preview_version: ${{ steps.context.outputs.preview_version }} |
34 | | - steps: |
35 | | - - name: Resolve PR context |
36 | | - id: context |
37 | | - run: | |
38 | | - set -euo pipefail |
39 | | -
|
40 | | - should_build=false |
41 | | - pr_number="$(jq -r '.workflow_run.pull_requests[0].number // ""' "$GITHUB_EVENT_PATH")" |
42 | | - pr_head_sha="$(jq -r '.workflow_run.head_sha // ""' "$GITHUB_EVENT_PATH")" |
43 | | - pr_head_branch="$(jq -r '.workflow_run.head_branch // ""' "$GITHUB_EVENT_PATH")" |
44 | | -
|
45 | | - if [[ -z "${pr_head_sha}" ]]; then |
46 | | - echo "Workflow run has no head SHA; skipping." |
47 | | - echo "should_build=false" >> "$GITHUB_OUTPUT" |
48 | | - exit 0 |
49 | | - fi |
50 | | -
|
51 | | - if [[ -z "${pr_number}" && -n "${pr_head_branch}" ]]; then |
52 | | - pr_number="$( |
53 | | - gh pr list \ |
54 | | - --repo "${REPOSITORY}" \ |
55 | | - --head "${pr_head_branch}" \ |
56 | | - --state open \ |
57 | | - --json number,headRefOid \ |
58 | | - --jq 'map(select(.headRefOid == "'"${pr_head_sha}"'")) | .[0].number // ""' |
59 | | - )" |
60 | | - fi |
61 | | -
|
62 | | - if [[ -z "${pr_number}" ]]; then |
63 | | - echo "Test run is not associated with an open pull request; skipping." |
64 | | - echo "should_build=false" >> "$GITHUB_OUTPUT" |
65 | | - exit 0 |
66 | | - fi |
67 | | -
|
68 | | - pr_json="$(gh api "repos/${REPOSITORY}/pulls/${pr_number}")" |
69 | | - current_head_sha="$(jq -r '.head.sha' <<< "${pr_json}")" |
70 | | - state="$(jq -r '.state' <<< "${pr_json}")" |
71 | | - draft="$(jq -r '.draft' <<< "${pr_json}")" |
72 | | - head_repo="$(jq -r '.head.repo.full_name' <<< "${pr_json}")" |
73 | | - base_repo="$(jq -r '.base.repo.full_name' <<< "${pr_json}")" |
74 | | -
|
75 | | - if [[ "${state}" != "open" ]]; then |
76 | | - echo "PR #${pr_number} is ${state}; skipping." |
77 | | - echo "should_build=false" >> "$GITHUB_OUTPUT" |
78 | | - exit 0 |
79 | | - fi |
80 | | -
|
81 | | - if [[ "${draft}" == "true" ]]; then |
82 | | - echo "PR #${pr_number} is draft; skipping." |
83 | | - echo "should_build=false" >> "$GITHUB_OUTPUT" |
84 | | - exit 0 |
85 | | - fi |
86 | | -
|
87 | | - if [[ "${head_repo}" != "${base_repo}" ]]; then |
88 | | - echo "PR #${pr_number} comes from fork ${head_repo}; skipping." |
89 | | - echo "should_build=false" >> "$GITHUB_OUTPUT" |
90 | | - exit 0 |
91 | | - fi |
92 | | -
|
93 | | - if [[ "${pr_head_sha}" != "${current_head_sha}" ]]; then |
94 | | - echo "Test SHA ${pr_head_sha} is stale; current PR head is ${current_head_sha}. Skipping." |
95 | | - echo "should_build=false" >> "$GITHUB_OUTPUT" |
96 | | - exit 0 |
97 | | - fi |
98 | | -
|
99 | | - preview_version="0.0.0-pr.${pr_number}" |
100 | | - should_build=true |
101 | | -
|
102 | | - { |
103 | | - echo "should_build=${should_build}" |
104 | | - echo "pr_number=${pr_number}" |
105 | | - echo "pr_head_sha=${pr_head_sha}" |
106 | | - echo "preview_version=${preview_version}" |
107 | | - } >> "$GITHUB_OUTPUT" |
108 | | -
|
109 | 22 | build: |
110 | | - needs: resolve |
111 | | - if: needs.resolve.outputs.should_build == 'true' |
| 23 | + if: github.event.pull_request.draft == false |
112 | 24 | name: Build preview CLI packages |
113 | 25 | uses: ./.github/workflows/build-cli-artifacts.yml |
114 | 26 | with: |
115 | | - version: ${{ needs.resolve.outputs.preview_version }} |
| 27 | + version: 0.0.0-pr.${{ github.event.pull_request.number }} |
116 | 28 | shell: legacy |
117 | | - ref: ${{ needs.resolve.outputs.pr_head_sha }} |
118 | 29 |
|
119 | 30 | publish: |
120 | | - needs: [resolve, build] |
121 | | - if: needs.resolve.outputs.should_build == 'true' && needs.build.result == 'success' |
| 31 | + needs: build |
| 32 | + if: github.event.pull_request.draft == false && needs.build.result == 'success' |
122 | 33 | name: Publish preview package |
123 | 34 | runs-on: ubuntu-latest |
124 | | - permissions: |
125 | | - actions: read |
126 | | - contents: read |
127 | | - issues: write |
128 | | - pull-requests: read |
129 | 35 | env: |
130 | | - GH_TOKEN: ${{ github.token }} |
131 | | - PREVIEW_VERSION: ${{ needs.resolve.outputs.preview_version }} |
132 | | - PR_HEAD_SHA: ${{ needs.resolve.outputs.pr_head_sha }} |
133 | | - PR_NUMBER: ${{ needs.resolve.outputs.pr_number }} |
134 | | - REPOSITORY: ${{ github.repository }} |
| 36 | + PREVIEW_VERSION: 0.0.0-pr.${{ github.event.pull_request.number }} |
| 37 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
135 | 38 | steps: |
136 | 39 | - name: Checkout |
137 | 40 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
138 | 41 | with: |
139 | | - ref: ${{ needs.resolve.outputs.pr_head_sha }} |
140 | 42 | persist-credentials: false |
141 | 43 |
|
142 | 44 | - name: Setup |
|
145 | 47 | - name: Download preview build artifacts |
146 | 48 | uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 |
147 | 49 | with: |
148 | | - name: cli-build-legacy-${{ needs.resolve.outputs.preview_version }} |
| 50 | + name: cli-build-legacy-${{ env.PREVIEW_VERSION }} |
149 | 51 |
|
150 | 52 | - name: Prepare package files |
151 | 53 | run: | |
@@ -176,39 +78,5 @@ jobs: |
176 | 78 | run: | |
177 | 79 | set -euo pipefail |
178 | 80 | preview_url="https://pkg.pr.new/supabase@${PR_NUMBER}" |
| 81 | + echo "Preview command: npx ${preview_url}" |
179 | 82 | npx --yes "${preview_url}" --version |
180 | | -
|
181 | | - - name: Update PR comment |
182 | | - run: | |
183 | | - set -euo pipefail |
184 | | - preview_url="https://pkg.pr.new/supabase@${PR_NUMBER}" |
185 | | - short_sha="${PR_HEAD_SHA:0:7}" |
186 | | - marker="<!-- pkg-pr-new-preview -->" |
187 | | - cat > comment.md <<EOF |
188 | | - ${marker} |
189 | | - ## pkg.pr.new preview |
190 | | -
|
191 | | - Published version \`${PREVIEW_VERSION}\` from commit [\`${short_sha}\`](https://github.com/${REPOSITORY}/commit/${PR_HEAD_SHA}) after tests passed. |
192 | | -
|
193 | | - \`\`\`sh |
194 | | - npx ${preview_url} |
195 | | - \`\`\` |
196 | | -
|
197 | | - \`\`\`sh |
198 | | - npx ${preview_url} --version |
199 | | - \`\`\` |
200 | | - EOF |
201 | | -
|
202 | | - jq -n --rawfile body comment.md '{ body: $body }' > comment.json |
203 | | - comment_id="$( |
204 | | - gh api "repos/${REPOSITORY}/issues/${PR_NUMBER}/comments" \ |
205 | | - --paginate \ |
206 | | - --jq '.[] | select(.body | contains("'"${marker}"'")) | .id' \ |
207 | | - | head -n1 |
208 | | - )" |
209 | | -
|
210 | | - if [[ -n "${comment_id}" ]]; then |
211 | | - gh api --method PATCH "repos/${REPOSITORY}/issues/comments/${comment_id}" --input comment.json >/dev/null |
212 | | - else |
213 | | - gh api --method POST "repos/${REPOSITORY}/issues/${PR_NUMBER}/comments" --input comment.json >/dev/null |
214 | | - fi |
0 commit comments