-
Notifications
You must be signed in to change notification settings - Fork 8
217 lines (173 loc) · 7.03 KB
/
build-pr.yml
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: Build PR
on:
pull_request:
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
- name: Create git branch
run: |
# Create a git branch from the detached HEAD.
# We need this for some integration tests.
# This branch is not pushed, it's just local to the workflow environment.
git checkout -b test-branch-${{ github.sha }}
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Setup node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Set build version
run: echo "TAG=0.0.0-${{ github.ref_name == 'changeset-release/main' && 'beta' || 'alpha' }}.v$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
id: version
- name: Check secrets exist
run: echo "exist=${{ secrets.GITHUB_TOKEN != '' && 'true' || 'false' }}" >> $GITHUB_OUTPUT
id: secrets
- name: Find Comment
uses: peter-evans/find-comment@v1
if: ${{ github.repository == 'xataio/client-ts' && github.event_name == 'pull_request' }}
id: find-comment-1
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Your pull request has been published to npm
- name: Update existing comment with stale state of npm release
uses: peter-evans/create-or-update-comment@v1
id: update-existing
if: ${{ github.repository == 'xataio/client-ts' && github.event_name == 'pull_request' && steps.find-comment-1.outputs.comment-id != '' }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
comment-id: ${{ steps.find-comment-1.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
Your pull request has been published to npm.
You can install @xata.io/client by running:
```
npm install @xata.io/client@${{ steps.version.outputs.TAG }}
```
Other packages are published like this:
```
npm install @xata.io/mypackage@${{ steps.version.outputs.TAG }}
```
To test the CLI, run:
```
npx @xata.io/cli@${{ steps.version.outputs.TAG }}
```
[Pull request has been updated, please wait for latest changes to be pushed to npm...]
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Compile
run: pnpm build
- name: Configure npm registry token
if: ${{ steps.secrets.outputs.exist == 'true' }}
run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Exit pre-mode if set
continue-on-error: true
run: npx changeset pre exit
- name: Publish build
if: ${{ steps.secrets.outputs.exist == 'true' && github.event_name == 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
run: |
cat << EOF > .changeset/force-canary-build.md
---
'@xata.io/plugin-client-opentelemetry': patch
'@xata.io/plugin-client-cloudflare': patch
'@xata.io/plugin-client-cache': patch
'@xata.io/drizzle': patch
'@xata.io/kysely': patch
'@xata.io/pgroll': patch
'@xata.io/importer': patch
'@xata.io/codegen': patch
'@xata.io/client': patch
'@xata.io/cli': patch
---
Force canary build
EOF
npx changeset version --snapshot ${{ github.ref_name == 'changeset-release/main' && 'beta' || 'alpha' }}
npx changeset publish --tag ${{ github.ref_name == 'changeset-release/main' && 'dev' || 'canary' }} --no-git-tag
- name: Find Comment
uses: peter-evans/find-comment@v1
if: ${{ steps.secrets.outputs.exist == 'true' && github.event_name == 'pull_request' }}
id: find-comment-2
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Your pull request has been published to npm
- name: Create or update comment of npm release
uses: peter-evans/create-or-update-comment@v1
if: ${{ steps.secrets.outputs.exist == 'true' && github.event_name == 'pull_request' }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
comment-id: ${{ steps.find-comment-2.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
Your pull request has been published to npm.
You can install @xata.io/client by running:
```
npm install @xata.io/client@${{ steps.version.outputs.TAG }}
```
Other packages are published like this:
```
npm install @xata.io/mypackage@${{ steps.version.outputs.TAG }}
```
To test the CLI, run:
```
npx @xata.io/cli@${{ steps.version.outputs.TAG }}
```
- name: Canary build E2E test
if: ${{ steps.secrets.outputs.exist == 'true' && github.event_name == 'pull_request' }}
run: pnpm run test:canary
env:
XATA_API_KEY: ${{ secrets.INTEGRATION_TEST_API_KEY }}
XATA_WORKSPACE: ${{ secrets.INTEGRATION_TEST_WORKSPACE }}
CANARY_VERSION: ${{ steps.version.outputs.TAG }}
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Create git branch
run: |
# Create a git branch from the detached HEAD.
# We need this for some integration tests.
# This branch is not pushed, it's just local to the workflow environment.
git checkout -b test-branch-${{ github.sha }}
- name: Read .nvmrc
run: echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT
id: nvm
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Use Node.js ${{ steps.nvm.outputs.NVMRC }}
uses: actions/setup-node@v3
with:
node-version: ${{ steps.nvm.outputs.NVMRC }}
cache: 'pnpm'
- name: Check secrets exist
run: echo "exist=${{ secrets.GITHUB_TOKEN != '' && 'true' || 'false' }}" >> $GITHUB_OUTPUT
id: secrets
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Compile
run: pnpm build
- name: Lint
run: pnpm lint
- name: Test
if: ${{ steps.secrets.outputs.exist == 'true' }}
run: |
pnpm test
env:
XATA_API_KEY: ${{ secrets.INTEGRATION_TEST_API_KEY }}
XATA_WORKSPACE: ${{ secrets.INTEGRATION_TEST_WORKSPACE }}