-
Notifications
You must be signed in to change notification settings - Fork 200
237 lines (219 loc) · 8.49 KB
/
sdk-spec-test.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
name: SDK Spec Tests
run-name: SDK Spec Tests (${{ inputs.repo || github.repository }}/${{inputs.ref || github.ref}}) for ${{inputs.target || 'all'}}
on:
release:
types:
- published # runs only unstable targets
workflow_call: {}
workflow_dispatch:
inputs:
repo:
type: string
default: winglang/wing
description: "Full repo name (owner/name)"
ref:
type: string
default: main
description: "Ref to checkout. Must be present in the repo input."
target:
type: choice
default: all
description: "target to run at, can be one or all of them"
options:
- all-stable # tf-aws and sim
- all-unstable # tf-azure and soon tf-gcp
- all
- tf-aws
- tf-azure
- sim
- tf-gcp
permissions:
contents: read
id-token: write
env:
AWS_REGION: "us-east-1"
NODE_VERSION: "20.11.1"
# this variable indicates wheater to use wing cli from a local version (using the current repo code)
# or use the latest remote npm version
LOCAL_BUILD: ${{ github.workflow == 'build' }}
# indicates if the action triggered from a workflow_dispatch
MANUAL: ${{ github.event_name == 'workflow_dispatch' }}
REPO: ${{ inputs.repo || github.repository }}
REF: ${{ inputs.ref || github.ref }}
TARGET: ${{ inputs.target || (github.workflow == 'build' && 'all-stable') || (github.event_name == 'release' && 'all-unstable') || 'all' }} #the build runs only stable targets, realease only unstable
PNPM_VERSION: "8.15.1"
AZURE_LOCATION: "East US"
CDK_STACK_NAME: "sdk-spec-tests"
GOOGLE_PROJECT_ID: "sdk-spec-tests"
GOOGLE_REGION: "us-central1"
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: test if is maintainer
uses: tspascoal/get-user-teams-membership@v3
id: testUserGroup
if: ${{ env.MANUAL == 'true' }}
with:
username: ${{ github.actor }}
team: "maintainers"
GITHUB_TOKEN: ${{ secrets.GH_GROUPS_READ_TOKEN }}
- name: cancel run if not allowed
if: ${{ env.MANUAL == 'true' && steps.testUserGroup.outputs.isTeamMember == 'false' }}
run: |
echo "User ${{github.actor}} is not allowed to dispatch this action."
exit 1
- name: Checkout Repository
uses: actions/checkout@v4
with:
repository: ${{env.REPO}}
ref: ${{env.REF}}
- name: Get list of directories and save them to the output
id: setdirs
shell: bash
run: | # TODO: skipping std, math and external folders, when https://github.com/winglang/wing/issues/3168 is resolve- we'll skip only the external folder.
dirs=$(ls -d tests/sdk_tests/*/ | sed 's/\/$//' | grep -v "external\|std\|math" | jq -R -s -c 'split("\n")[:-1]')
processed_dirs=$(echo "{ \"directory\": $dirs }" | jq -c '[ .directory[] | {directory: ., name: (split("/") | last)}]')
wrapped_dirs=$(echo $processed_dirs | jq -c .)
echo "dirs=$wrapped_dirs" >> $GITHUB_OUTPUT
- name: Get targets list
id: settargets
run: |
if [ "${{env.TARGET}}" = "all" ]; then
target='["tf-aws", "tf-azure", "tf-gcp"]'
elif [ "${{env.TARGET}}" = "all-stable" ]; then
target='["tf-aws", "sim"]'
elif [ "${{env.TARGET}}" = "all-unstable" ]; then
target='["tf-gcp", "tf-azure"]'
else
target='["${{env.TARGET}}"]'
fi
echo "targets=$target" >> $GITHUB_OUTPUT
outputs:
tests: ${{ steps.setdirs.outputs.dirs }}
targets: ${{ steps.settargets.outputs.targets }}
test:
needs: setup
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 10
matrix:
test: ${{ fromJson(needs.setup.outputs.tests) }}
target: ${{ fromJson(needs.setup.outputs.targets) }}
name: ${{ matrix.test.name }} - ${{ matrix.target }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
repository: ${{env.REPO}}
ref: ${{env.REF}}
- name: Setup pnpm
if: ${{ env.MANUAL == 'true' }}
uses: pnpm/action-setup@v3
with:
version: ${{ env.PNPM_VERSION }}
- name: Setup Node.js v18
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
##################### install a local wing version #########################
- name: Download Dist Artifacts
if: ${{ env.LOCAL_BUILD == 'true' }}
uses: actions/download-artifact@v4
with:
name: dist
path: dist
- name: Install Wing from Dist
if: ${{ env.LOCAL_BUILD == 'true' }}
run: |
mkdir localwing
cd localwing
npm init --yes
npm install ../dist/*-[0-9]*.[0-9]*.[0-9]*.tgz
./node_modules/.bin/wing --version
#################### install a remote wing version ########################
- name: Install winglang globally
if: ${{ env.LOCAL_BUILD == 'false' && env.MANUAL == 'false'}}
uses: nick-fields/retry@v3
with:
max_attempts: 3
retry_on: error
timeout_minutes: 5
command: npm install -g winglang
########################################################################
- name: Installing external js modules
run: |
cd tests/sdk_tests
npm install
- name: Configure AWS credentials
if: ${{ matrix.target == 'tf-aws' }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Configure azure credentials
if: ${{ matrix.target == 'tf-azure' }}
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Configure gcp credentials
id: gcp-auth
if: ${{ matrix.target == 'tf-gcp' }}
uses: google-github-actions/auth@v1
with:
workload_identity_provider: "projects/833985639028/locations/global/workloadIdentityPools/gh-action/providers/gh-action-provider"
service_account: "[email protected]"
- name: Set-up gcloud
if: ${{ matrix.target == 'tf-gcp' }}
uses: google-github-actions/setup-gcloud@v1
- name: export gcloud token
if: ${{ matrix.target == 'tf-gcp' }}
run: echo "GCP_ID_TOKEN=$(gcloud auth print-identity-token --impersonate-service-account=gh-action@sdk-spec-tests.iam.gserviceaccount.com)" >> $GITHUB_ENV
- name: Installing local dependencies
if: ${{ env.MANUAL == 'true' }}
uses: nick-fields/retry@v3
env:
TF_LOG: info
TF_LOG_PATH: ${{ runner.workspace }}/terraform.log
with:
max_attempts: 3
retry_on: error
timeout_minutes: 30
command: |
pnpm install
pnpm turbo compile -F=winglang
- name: Execute wing test in matrix directory
env:
TF_LOG: info
TF_LOG_PATH: ${{ runner.workspace }}/terraform.log
run: |
if ${{ env.MANUAL == 'true' }}
then
WING_CLI=$(realpath packages/winglang/bin/wing)
elif ${{ env.LOCAL_BUILD == 'false'}}
then
WING_CLI=$(which wing)
# COMPATIBILITY="-t @winglang/compatibility-spy" //TODO: will be handled in a following PR
else
WING_CLI=$(realpath localwing/node_modules/.bin/wing)
COMPATIBILITY="-t ../../../localwing/node_modules/@winglang/compatibility-spy/lib"
echo $COMPATIBILITY
fi
cd ${{ matrix.test.directory }}
$WING_CLI test --snapshots=deploy -t ${{ matrix.target }} -p ${{ (matrix.target == 'tf-azure' && 2 ) || (matrix.target == 'tf-gcp' && 5) || 10 }} --retry 3 $COMPATIBILITY *.test.w -o ../../../out/${{ matrix.test.name }}-${{ matrix.target }}.json
- name: Upload Artifacts
if: ${{ env.LOCAL_BUILD == 'true' }}
uses: actions/upload-artifact@v4
with:
name: out-${{ matrix.test.name }}-${{ matrix.target }}
path: out/*
- name: Output Terraform log
if: failure()
run: cat ${{ runner.workspace }}/terraform.log
update-matrix:
needs: test
if: ${{ github.workflow == 'build' }}
uses: ./.github/workflows/matrix-update.yml
secrets: inherit