-
Notifications
You must be signed in to change notification settings - Fork 486
Expand file tree
/
Copy pathpublish-preview-cli-packages.yml
More file actions
154 lines (137 loc) · 4.85 KB
/
Copy pathpublish-preview-cli-packages.yml
File metadata and controls
154 lines (137 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: Publish Preview CLI Packages
# Release-notes PRs (head ref `release-notes/*`) are markdown-only and are not
# meant to produce installable preview packages.
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
branches:
- develop
permissions:
actions: read
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
jobs:
build:
if: |
!startsWith(github.head_ref, 'release-notes/') &&
github.event.pull_request.draft == false
name: Build preview CLI packages
uses: ./.github/workflows/build-cli-artifacts.yml
with:
version: 0.0.0-pr.${{ github.event.pull_request.number }}
shell: legacy
publish:
needs: build
if: |
!startsWith(github.head_ref, 'release-notes/') &&
github.event.pull_request.draft == false &&
needs.build.result == 'success'
name: Publish preview package
runs-on: ubuntu-latest
env:
PREVIEW_VERSION: 0.0.0-pr.${{ github.event.pull_request.number }}
PR_NUMBER: ${{ github.event.pull_request.number }}
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Setup
uses: ./.github/actions/setup
- name: Download preview build artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: cli-build-legacy-${{ env.PREVIEW_VERSION }}
- name: Prepare package files
run: |
set -euo pipefail
pnpm exec bun apps/cli/scripts/sync-versions.ts --version "${PREVIEW_VERSION}"
pnpm --dir apps/cli build:shim
find packages -path '*/bin/supabase*' -type f -exec chmod +x {} +
- name: Publish preview package
run: |
pnpm exec pkg-pr-new publish \
--pnpm \
--bin \
--comment=off \
--json pkg-pr-new.json \
--no-template \
'./packages/cli-darwin-arm64' \
'./packages/cli-darwin-x64' \
'./packages/cli-linux-arm64' \
'./packages/cli-linux-arm64-musl' \
'./packages/cli-linux-x64' \
'./packages/cli-linux-x64-musl' \
'./packages/cli-windows-arm64' \
'./packages/cli-windows-x64' \
'./apps/cli'
- name: Smoke test preview command
run: |
set -euo pipefail
preview_url="https://pkg.pr.new/supabase@${PR_NUMBER}"
echo "Preview command: npx ${preview_url}"
npx --yes "${preview_url}" --version
comment:
needs: publish
if: |
!startsWith(github.head_ref, 'release-notes/') &&
github.event.pull_request.draft == false &&
needs.publish.result == 'success'
name: Post preview command comment
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
GH_TOKEN: ${{ github.token }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_NUMBER: ${{ github.event.pull_request.number }}
steps:
- name: Post preview command comment
run: |
set -euo pipefail
marker="<!-- supabase-cli-preview-package -->"
preview_url="https://pkg.pr.new/supabase@${PR_NUMBER}"
short_sha="${HEAD_SHA:0:7}"
comment_file="$(mktemp)"
cat > "${comment_file}" <<EOF
${marker}
## Supabase CLI preview
\`\`\`sh
npx --yes ${preview_url}
\`\`\`
_Preview package for commit [\`${short_sha}\`](https://github.com/${GITHUB_REPOSITORY}/commit/${HEAD_SHA})._
EOF
if ! comment_id="$(
gh api \
"repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
--jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | contains(\"${marker}\"))) | .id" \
| head -n 1
)"; then
echo "::warning::Unable to list PR comments. The preview package was published, but this workflow token cannot update the PR comment."
exit 0
fi
if [ -n "${comment_id}" ]; then
if ! gh api \
--method PATCH \
"repos/${GITHUB_REPOSITORY}/issues/comments/${comment_id}" \
--field "body=@${comment_file}" \
>/dev/null; then
echo "::warning::Unable to update the preview package PR comment."
exit 0
fi
else
if ! gh api \
--method POST \
"repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" \
--field "body=@${comment_file}" \
>/dev/null; then
echo "::warning::Unable to create the preview package PR comment."
exit 0
fi
fi