-
Notifications
You must be signed in to change notification settings - Fork 8
287 lines (252 loc) · 10.8 KB
/
release-cli-assets.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
name: Release CLI Assets
on:
workflow_call:
inputs:
publishedPackages:
description: 'Published packages'
required: true
type: string
commitSha:
description: 'Commit SHA'
required: true
type: string
workflow_dispatch:
inputs:
publishedPackages:
description: 'Published packages'
required: true
default: '[{"name": "@xata.io/cli", "version": "1.2.0"}]'
type: string
commitSha:
description: 'Commit SHA'
required: true
type: string
permissions:
id-token: write
contents: write
packages: write
pages: write
pull-requests: write
jobs:
release-cli-assets:
name: Release CLI assets
outputs:
version: ${{ steps.capture-version.outputs.version }}
mac_intel_sha: ${{steps.sha-macos.outputs.sha-macos-intel}}
mac_arm_sha: ${{ steps.sha-macos.outputs.sha-macos-arm }}
linux_sha: ${{ steps.sha-ubuntu.outputs.sha-linux }}
linux_arm_sha: ${{ steps.sha-ubuntu.outputs.sha-linux-arm }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
# This makes the PR pushed to use GITHUB_TOKEN and trigger the checks
persist-credentials: false
- name: Configure
run: |
echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT
id: config
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Use Node.js ${{ steps.config.outputs.NVMRC }}
uses: actions/setup-node@v3
with:
node-version: ${{ steps.config.outputs.NVMRC }}
cache: 'pnpm'
- name: Install the Apple certificate
if: matrix.os == 'macos-latest'
env:
BUILD_CERTIFICATE_BASE64: ${{ secrets.APPLE_DEVELOPER_ID_CERT_P12 }}
P12_PASSWORD: ${{ secrets.APPLE_DEVELOPER_ID_CERT_SECRET }}
KEYCHAIN_PASSWORD: ${{ secrets.APPLE_DEVELOPER_ID_CERT_SECRET }}
run: |
# create variables
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
# import certificate from secrets
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH
# create temporary keychain
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
# import certificate to keychain
security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
security set-key-partition-list -S apple-tool:,apple: -k "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
security list-keychain -d user -s $KEYCHAIN_PATH
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm build
- name: Install windows dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y nsis
sudo apt-get install -y p7zip
- name: Write windows certificate to file
env:
XATA_WINDOWS_CERTIFICATE_KEY: ${{ secrets.WINDOWS_CERTIFICATE_KEY }}
if: matrix.os == 'ubuntu-latest'
run: |
echo -n `$XATA_WINDOWS_CERTIFICATE_KEY` >> ~/xata.key
- name: Configure AWS Credentials for production
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.CLI_ASSETS_UPLOAD_ROLE }}
aws-region: us-east-1
mask-aws-account-id: 'no'
- name: Pack
run: pnpm run release:cli:pack
env:
PUBLISHED_PACKAGES: ${{ inputs.publishedPackages }}
MATRIX_OS: ${{ matrix.os }}
- name: Upload CLI Assets to GitHub Releases
run: pnpm run release:cli:upload:gh
env:
MATRIX_OS: ${{ matrix.os }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
XATA_WINDOWS_SIGNING_PASS: ${{ secrets.WINDOWS_CERTIFICATE_SECRET }}
- name: Debian cert
if: matrix.os == 'ubuntu-latest'
working-directory: /home/runner/work/client-ts/client-ts/cli/dist/deb
run: |
echo "$DEBIAN_GPG_KEY_PRIVATE" | gpg --import --batch --passphrase "$DEBIAN_GPG_KEY_PASS"
gpg --digest-algo SHA512 --clearsign --pinentry-mode loopback --passphrase "$DEBIAN_GPG_KEY_PASS" -u $DEBIAN_GPG_KEY_ID -o InRelease Release
gpg --digest-algo SHA512 -abs --pinentry-mode loopback --passphrase "$DEBIAN_GPG_KEY_PASS" -u $DEBIAN_GPG_KEY_ID -o Release.gpg Release
echo "Signed debian packages successfully"
echo "sha256 sums:"
sha256sum *Release*
mkdir -p /home/runner/work/client-ts/client-ts/cli/dist/apt
echo "$DEBIAN_GPG_KEY_PUBLIC" > /home/runner/work/client-ts/client-ts/cli/dist/apt/release.key
env:
DEBIAN_GPG_KEY_PRIVATE: ${{ secrets.DEBIAN_GPG_KEY_PRIVATE }}
DEBIAN_GPG_KEY_PASS: ${{ secrets.DEBIAN_GPG_KEY_PASS }}
DEBIAN_GPG_KEY_PUBLIC: ${{ secrets.DEBIAN_GPG_KEY_PUBLIC }}
DEBIAN_GPG_KEY_ID: ${{ secrets.DEBIAN_GPG_KEY_ID }}
- name: Capture version
id: capture-version
working-directory: ./cli
run: echo "version=$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT
- name: Create SHA outputs macos
if: matrix.os == 'macos-latest'
working-directory: ./cli/dist
id: sha-macos
run: |
ls -l
VER="${{steps.capture-version.outputs.version}}"
COMMITSHA="${{inputs.commitSha}}"
COM="$(echo $COMMITSHA | head -c8)"
echo "sha-macos-arm=$(shasum --algorithm 256 xata-v${VER}-${COM}-darwin-arm64.tar.xz | cut -d" " -f1)" >> "$GITHUB_OUTPUT"
echo "sha-macos-intel=$(shasum --algorithm 256 xata-v${VER}-${COM}-darwin-x64.tar.xz | cut -d" " -f1)" >> "$GITHUB_OUTPUT"
- name: Create SHA outputs ubuntu
if: matrix.os == 'ubuntu-latest'
working-directory: ./cli/dist
id: sha-ubuntu
run: |
ls -l
VER="${{steps.capture-version.outputs.version}}"
COMMITSHA="${{inputs.commitSha}}"
COM="$(echo $COMMITSHA | head -c8)"
echo "sha-linux=$(sha256sum xata-v${VER}-${COM}-linux-arm.tar.xz | cut -d " " -f1)" >> "$GITHUB_OUTPUT"
echo "sha-linux-arm=$(sha256sum xata-v${VER}-${COM}-linux-arm64.tar.xz | cut -d " " -f1)" >> "$GITHUB_OUTPUT"
- name: Upload and Promote CLI Assets to S3
run: pnpm run release:cli:upload:s3
env:
MATRIX_OS: ${{ matrix.os }}
COMMIT_SHA: ${{ inputs.commitSha }}
- name: Pack (Windows only)
if: matrix.os == 'ubuntu-latest'
run: pnpm run release:cli:pack
env:
PUBLISHED_PACKAGES: ${{ inputs.publishedPackages }}
MATRIX_OS: ${{ matrix.os }}
OS_OVERRIDE: windows-latest
- name: Upload CLI Assets to GitHub Releases (Windows only)
run: pnpm run release:cli:upload:gh
if: matrix.os == 'ubuntu-latest'
env:
MATRIX_OS: ${{ matrix.os }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OS_OVERRIDE: windows-latest
- name: Upload and Promote CLI Assets to S3 (Windows only)
if: matrix.os == 'ubuntu-latest'
run: pnpm run release:cli:upload:s3
env:
MATRIX_OS: ${{ matrix.os }}
COMMIT_SHA: ${{ inputs.commitSha }}
OS_OVERRIDE: windows-latest
- name: Clean up keychain
if: matrix.os == 'macos-latest'
run: |
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db
update-homebrew:
needs: [release-cli-assets]
name: Update Homebrew Formula
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
steps:
- uses: actions/checkout@v3
with:
repository: xataio/homebrew-brew
ref: 'main'
token: ${{ secrets.GIT_TOKEN }}
fetch-depth: 0
- name: setup git config
run: |
git config user.email "[email protected]"
git config user.name "Xata"
- name: Read template file
id: gettemplate
run: |
{
echo 'template<<EOF'
cat ./Template/xata.rb
echo
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Update Homebrew Formula using template variables
id: updateformula
env:
TEMPLATE_CONTENTS: ${{ steps.gettemplate.outputs.template }}
run: |
echo "$TEMPLATE_CONTENTS" > ./Formula/xata.rb
sed -i 's/__CLI_VERSION__/${{ needs.release-cli-assets.outputs.version }}/g' ./Formula/xata.rb
sed -i 's/__CLI_MAC_INTEL_SHA256__/${{ needs.release-cli-assets.outputs.mac_intel_sha }}/g' ./Formula/xata.rb
sed -i 's/__CLI_MAC_ARM_SHA256__/${{ needs.release-cli-assets.outputs.mac_arm_sha }}/g' ./Formula/xata.rb
sed -i 's/__CLI_LINUX_SHA256__/${{ needs.release-cli-assets.outputs.linux_sha }}/g' ./Formula/xata.rb
sed -i 's/__CLI_LINUX_ARM_SHA256__/${{ needs.release-cli-assets.outputs.linux_arm_sha }}/g' ./Formula/xata.rb
VER="${{needs.release-cli-assets.outputs.version}}"
COMMITSHA="${{inputs.commitSha}}"
COM="$(echo $COMMITSHA | head -c8)"
BASE_URL="https://xata-cli-assets.s3.us-east-1.amazonaws.com/versions/${VER}/${COM}/xata-v${VER}-${COM}"
CLI_MAC_INTEL_DOWNLOAD_URL="${BASE_URL}-darwin-x64.tar.xz"
CLI_MAC_ARM_DOWNLOAD_URL="${BASE_URL}-darwin-arm64.tar.xz"
CLI_LINUX_DOWNLOAD_URL="${BASE_URL}-linux-x64.tar.xz"
CLI_LINUX_ARM_DOWNLOAD_URL="${BASE_URL}-linux-arm64.tar.xz"
sed -i "s|__CLI_MAC_INTEL_DOWNLOAD_URL__|${CLI_MAC_INTEL_DOWNLOAD_URL}|g" ./Formula/xata.rb
sed -i "s|__CLI_MAC_ARM_DOWNLOAD_URL__|${CLI_MAC_ARM_DOWNLOAD_URL}|g" ./Formula/xata.rb
sed -i "s|__CLI_LINUX_DOWNLOAD_URL__|${CLI_LINUX_DOWNLOAD_URL}|g" ./Formula/xata.rb
sed -i "s|__CLI_LINUX_ARM_DOWNLOAD_URL__|${CLI_LINUX_ARM_DOWNLOAD_URL}|g" ./Formula/xata.rb
- name: Read formula file
id: getformula
run: |
{
echo 'formula<<EOF'
cat ./Formula/xata.rb
echo
echo EOF
} >> "$GITHUB_OUTPUT"
- name: commit changes
run: git commit -a -m "Update dependencies to version ${{ needs.release-cli-assets.outputs.version }}"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GIT_TOKEN }}
branch: main
repository: xataio/homebrew-brew