-
Notifications
You must be signed in to change notification settings - Fork 44
297 lines (265 loc) · 10.4 KB
/
tests-deployments.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
288
289
290
291
292
293
294
295
296
297
name: Tests and Deployments
on:
push:
pull_request:
schedule:
- cron: "0 8 * * *"
workflow_dispatch:
jobs:
functional-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node:
- "22"
- "20"
- "18"
java:
- "21"
- "17"
- "11"
include:
- node: "18"
java: "11"
ENABLE_CODE_COVERAGE: true
ENABLE_INTEGRATION_TESTS: true
env:
ENABLE_CODE_COVERAGE: ${{ matrix.ENABLE_CODE_COVERAGE }}
RUN_INTEGRATION_TESTS: ${{ matrix.ENABLE_INTEGRATION_TESTS && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags')) }}
name: Run tests on NodeJS ${{ matrix.node }} and Java ${{ matrix.java }}
steps:
- name: Checkout
uses: actions/checkout@v4.2.2
- name: Setup pnpm
uses: pnpm/action-setup@v4.0.0
- name: Setup Node.js
uses: actions/setup-node@v4.1.0
with:
node-version: ${{ matrix.node }}
cache: pnpm
- uses: actions/setup-java@v4.5.0
with:
distribution: temurin
java-version: ${{ matrix.java }}
cache: gradle
# Starting with Node 17, DNS is resolved by order that the resolver
# returns it. In Github Actions environment, there is a loopback IP
# for ::1 to localhost, which means our tests try to connect to the ipv6
# interface, which the Java program does not listen on.
- name: Remove ipv6 loopback
run: sudo sed -Ei '/(^::1)/d' /etc/hosts
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Test Apex AST Serializer
run: pnpm nx run apex-ast-serializer:test
- name: Upload Apex AST Serializer code coverage
if: matrix.ENABLE_CODE_COVERAGE
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: apex-ast-serializer
directory: packages/apex-ast-serializer
- name: Run Apex parsing server
run: pnpm nx run prettier-plugin-apex:start-server &
- name: Wait for Apex parsing server to be up
run: pnpm nx run prettier-plugin-apex:wait-server
- name: Run functional tests
run: AST_COMPARE=true pnpm nx run prettier-plugin-apex:test:parser:built-in
- name: Upload Prettier Plugin Apex code coverage
if: matrix.ENABLE_CODE_COVERAGE
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: prettier-plugin-apex
directory: packages/prettier-plugin-apex
- name: Install integration test suite dependencies
if: env.RUN_INTEGRATION_TESTS == 'true'
run: sudo apt-get install -y -qq parallel
# This step is needed because integration tests rely on the
# existence of the compiled JS, as they are run using Node
# instead of tsx
- name: Build the project
if: env.RUN_INTEGRATION_TESTS == 'true'
run: pnpm nx run prettier-plugin-apex:build:dev
- name: Run integration tests
if: env.RUN_INTEGRATION_TESTS == 'true'
run: ./packages/prettier-plugin-apex/tests_integration/format/run-integration-tests.sh
package-tests:
name: Test latest Prettier Apex package
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-14
- macos-13
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4.2.2
- name: Setup pnpm
uses: pnpm/action-setup@v4.0.0
- name: Setup Node.js
uses: actions/setup-node@v4.1.0
with:
node-version: "18"
cache: pnpm
- uses: actions/setup-java@v4.5.0
with:
distribution: temurin
java-version: "17"
cache: gradle
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run package tests
run: pnpm nx run prettier-plugin-apex:test:package
build-native-executables:
name: Build Native Executables
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags')
strategy:
matrix:
os:
- ubuntu-latest
- macos-14
- macos-13
- windows-latest
include:
- os: windows-latest
ASSET_NAME: apex-ast-serializer.exe
OUTPUT_NAME: apex-ast-serializer-win32-x64.exe
ARTIFACT_NAME: apex-ast-serializer-win32-x64.exe
- os: ubuntu-latest
ASSET_NAME: apex-ast-serializer
OUTPUT_NAME: apex-ast-serializer-linux-x64
ARTIFACT_NAME: apex-ast-serializer-linux-x64
# macOS 14 and above are ARM64 by default, see this link for more info:
# https://github.com/actions/runner-images?tab=readme-ov-file#available-images
- os: macos-14
ASSET_NAME: apex-ast-serializer
OUTPUT_NAME: apex-ast-serializer-darwin-arm64
ARTIFACT_NAME: apex-ast-serializer-darwin-arm64
- os: macos-13
ASSET_NAME: apex-ast-serializer
OUTPUT_NAME: apex-ast-serializer-darwin-x64
ARTIFACT_NAME: apex-ast-serializer-darwin-x64
env:
ASSET_NAME: ${{ matrix.ASSET_NAME }}
OUTPUT_NAME: ${{ matrix.OUTPUT_NAME }}
ARTIFACT_NAME: ${{ matrix.ARTIFACT_NAME }}
UPLOAD_ARTIFACTS: ${{ github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags') }}
OS: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: ./packages/apex-ast-serializer
steps:
- uses: actions/checkout@v4.2.2
- name: Setup pnpm
uses: pnpm/action-setup@v4.0.0
- name: Setup Node.js
uses: actions/setup-node@v4.1.0
with:
node-version: 18
cache: pnpm
- name: Set up JDK
uses: graalvm/setup-graalvm@v1.2.4.1
with:
java-version: "23"
distribution: "graalvm"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Restore NX cache
id: nx-cache-restore
uses: actions/cache/restore@v4.1.2
with:
path: |
.nx
key: ${{ matrix.os }}-nx-build-native-${{ hashFiles('packages/apex-ast-serializer/parser/**/*.java', 'packages/apex-ast-serializer/parser/**/*.properties', 'packages/apex-ast-serializer/parser/build.gradle', 'packages/apex-ast-serializer/libs/*.jar', 'packages/apex-ast-serializer/tools/build-native-binary.mjs') }}
- name: Build Linux musl toolchain
if: matrix.os == 'ubuntu-latest'
run: pnpm nx run apex-ast-serializer:build:musl
- name: Build native executable
env:
# https://nx.dev/troubleshooting/unknown-local-cache
NX_REJECT_UNKNOWN_LOCAL_CACHE: "false"
# We're using Legacy Cache for now, because there's no way to reject
# unknown local cache in the DB cache system as of now.
# The new DB Cache system uses machine-id as the SQLite DB name,
# and when run on different hosts, it will create a new DB, and forego
# using existing items in the cache.
# See this code here: https://github.com/nrwl/nx/blob/62f58ebfee37c6ef45422e5197a120d396d41922/packages/nx/src/native/machine_id/mod.rs#L3
# In the future we may be able to spoof machine-id to keep it consistent
# between runs. See this link on the Rust docs for the source of machine-id:
# https://docs.rs/machine-uid/latest/machine_uid/
NX_DB_CACHE: "false"
run: pnpm nx run apex-ast-serializer:build:native
- name: Save NX Cache
uses: actions/cache/save@v4.1.2
with:
path: |
.nx
key: ${{ steps.nx-cache-restore.outputs.cache-primary-key }}
- name: Rename executable
run: mv parser/build/native/nativeCompile/${{ env.ASSET_NAME }} parser/build/native/nativeCompile/${{ env.OUTPUT_NAME }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.OUTPUT_NAME }}
path: packages/apex-ast-serializer/parser/build/native/nativeCompile/${{ env.OUTPUT_NAME }}
release-to-registry:
runs-on: ubuntu-latest
name: Release to Registry
if: startsWith(github.ref, 'refs/tags')
needs:
- functional-tests
- build-native-executables
steps:
- name: Checkout
uses: actions/checkout@v4.2.2
- name: Setup pnpm
uses: pnpm/action-setup@v4.0.0
- name: Setup Node.js
uses: actions/setup-node@v4.1.0
with:
node-version: 22
cache: pnpm
- uses: actions/setup-java@v4.5.0
with:
distribution: temurin
java-version: 11
cache: gradle
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build the project
run: pnpm run build
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: /tmp/artifacts
pattern: apex-ast-serializer-*
merge-multiple: true
- name: Copy artifacts to correct packages
run: pnpm run install:native:ci /tmp/artifacts
- name: Set publishing config
run: pnpm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}"
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
- name: Check if prerelease
id: check_prerelease
continue-on-error: true
run: pnpm tsx scripts/check-prerelease.zx.mts
- name: Deploy packages
if: steps.check_prerelease.outcome == 'success'
run: pnpm --filter "prettier-plugin-apex" --filter "@prettier-apex/*" publish --no-git-checks --access public
- name: Deploy pre-release packages
if: steps.check_prerelease.outcome != 'success'
run: pnpm --filter "prettier-plugin-apex" --filter "@prettier-apex/*" publish --tag next --no-git-checks --access public
- name: Create GitHub Release
if: steps.check_prerelease.outcome == 'success'
uses: softprops/action-gh-release@v2