-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathaction.yml
More file actions
569 lines (531 loc) · 24.8 KB
/
action.yml
File metadata and controls
569 lines (531 loc) · 24.8 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
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
name: 'Gallery Standard Validation'
description: 'Validate the standard of the gallery'
inputs:
workingDirectory:
description: 'The path of target template to validate'
required: true
default: '.'
validatePaths:
description: 'Comma-separated list of paths to validate'
required: false
topics:
description: 'Comma-separated list of topics to check'
required: false
validateAzd:
description: 'Run azd up and azd down for validation'
required: true
default: 'true'
useDevContainer:
description: 'Use dev container for validation'
required: true
default: 'true'
securityAction:
description: 'Run security action validation'
required: true
default: 'PSRule'
options:
- 'PSRule'
validateTests:
description: 'Run tests for validation'
required: false
default: 'Playwright'
options:
- 'Playwright'
validationEnvs:
description: 'Additional environment variables for validation, in KEY=VALUE format, separated by commas'
required: false
default: ''
outputs:
resultFile:
description: "A file path to a results file."
value: ${{ steps.set_output.outputs.resultFile }}
runs:
using: "composite"
steps:
- name: Check for .devcontainer config
id: check_devcontainer
if : ${{ inputs.useDevContainer == 'true' }}
run: |
if [ ! -f "${{ inputs.workingDirectory }}/.devcontainer/devcontainer.json" ]; then
echo "Error: devcontainer config does not exist but useDevContainer is set to true."
exit 1
fi
shell: bash
- name: Check for environment variables
id: check_env
run: |
if [ -z "${{ env.AZURE_CLIENT_ID }}" ]; then
echo "Error: AZURE_CLIENT_ID is not set. Please run azd pipeline config for setup."
exit 1
fi
if [ -z "${{ env.AZURE_TENANT_ID }}" ]; then
echo "Error: AZURE_TENANT_ID is not set. Please run azd pipeline config for setup."
exit 1
fi
if [ -z "${{ env.AZURE_SUBSCRIPTION_ID }}" ]; then
echo "Error: AZURE_SUBSCRIPTION_ID is not set. Please run azd pipeline config for setup."
exit 1
fi
shell: bash
- name: Extract topics
id: extract_repo_info
if: ${{ inputs.topics != '""' }}
run: |
repository_name=${{ env.REPOSITORY_NAME || github.repository }}
topics_list=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" repos/$repository_name/topics | jq -r '.names | join(",")')
echo "TOPICS=\"$topics_list\"" >> $GITHUB_ENV
shell: bash
env:
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
- name: Reform path for compatability
id: reform_path
run: |
if [[ "$RUNNER_OS" == "Windows" ]]; then
working_directory=$(cygpath $(echo "${{ inputs.workingDirectory }}" | tr '\\' '/'))
action_path=$(cygpath $(echo "${{ github.action_path }}" | tr '\\' '/'))
workspace=$(cygpath $(echo "$GITHUB_WORKSPACE" | tr '\\' '/'))
echo "workingDirectory=$working_directory" >> $GITHUB_OUTPUT
echo "actionPath=$action_path" >> $GITHUB_OUTPUT
echo "workspace=$workspace" >> $GITHUB_OUTPUT
else
echo "workingDirectory=${{ inputs.workingDirectory }}" >> $GITHUB_OUTPUT
echo "actionPath=${{ github.action_path }}" >> $GITHUB_OUTPUT
echo "workspace=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Calculate relative paths for PSRule
if: ${{ inputs.securityAction == 'PSRule' }}
id: calculate_relative_paths
run: |
relative_working_directory=$(realpath --relative-to=${{ steps.reform_path.outputs.workspace }} ${{ steps.reform_path.outputs.workingDirectory }})
if [[ $relative_working_directory == ..* ]]; then
rm -rf ${{ github.run_id }}/template
mkdir -p ${{ github.run_id }}/template
cp -a ${{ steps.reform_path.outputs.workingDirectory }}/. ${{ github.run_id }}/template
echo "relative_working_directory=${{ github.run_id }}/template" >> $GITHUB_ENV
else
echo "relative_working_directory=$relative_working_directory" >> $GITHUB_ENV
fi
shell: bash
- name: Prepare PSRule for Azure
if: ${{ inputs.securityAction == 'PSRule' }}
id: prepare_psrule
run: |
rm -rf ${{ env.relative_working_directory }}/.ps-rule
mkdir -p ${{ env.relative_working_directory }}/.ps-rule
cp ${{ steps.reform_path.outputs.actionPath }}/.ps-rule/templateCustom.Rule.yaml ${{ env.relative_working_directory }}/.ps-rule/templateCustom.Rule.yaml
cp ${{ steps.reform_path.outputs.actionPath}}/ps-rule.yaml ${{ env.relative_working_directory }}
cd ${{ env.relative_working_directory }}
python3 ${{ steps.reform_path.outputs.actionPath }}/scripts/generate-bicep-test.py
shell: bash
# Analyze templates for MI compliance with PSRule for Azure
- name: Analyze templates for MI compliance
uses: microsoft/ps-rule@v2.9.0
if: ${{ inputs.securityAction == 'PSRule' && env.relative_working_directory != '.' }}
with:
path: ${{ env.relative_working_directory }}
modules: 'PSRule.Rules.Azure'
baseline: 'TemplateValidation.MI_2024_10'
outputFormat: "json"
outputPath: 'psrule-output.json'
summary: false
continue-on-error: true
# Analyze templates for MI compliance with PSRule for Azure
- name: Analyze templates for MI compliance
uses: microsoft/ps-rule@v2.9.0
if: ${{ inputs.securityAction == 'PSRule' && env.relative_working_directory == '.' }}
with:
modules: 'PSRule.Rules.Azure'
baseline: 'TemplateValidation.MI_2024_10'
outputFormat: "json"
outputPath: 'psrule-output.json'
summary: false
continue-on-error: true
- name: Copy back psrule-output
if: ${{ inputs.securityAction == 'PSRule' && steps.reform_path.outputs.workingDirectory != env.relative_working_directory }}
id: copy-back-psrule-output
run: |
cp ${{ env.relative_working_directory }}/psrule-output.json ${{ steps.reform_path.outputs.workingDirectory}}
shell: bash
continue-on-error: true
# - name: Set environment name with timestamp
# id: set_env_name
# if: ${{ inputs.validateAzd == 'true' }}
# run: |
# current_time=$(date +%m%d%H%M)
# azure_env_name="${{ env.AZURE_ENV_NAME }}-$current_time"
# echo "AZURE_ENV_NAME=$azure_env_name" >> $GITHUB_ENV
# echo "azure_env_name is $azure_env_name"
# shell: bash
# env:
# AZURE_ENV_NAME: ${{ env.AZURE_ENV_NAME }}
- name: Check parameters in main.bicep
id: check_parameters
#if: ${{ inputs.validateAzd == 'true' }}
run: |
set +e # Don't exit on errors
# Wrap the entire logic in a try-catch equivalent
{
echo "Starting parameter check process..."
if [ -f "${{ steps.reform_path.outputs.workingDirectory }}/infra/main.bicep" ]; then
# Get parameter names that don't have a default value (no equals sign in the line)
parameters=$(grep -P "^param\s+\w+\s+\w+$" "${{ steps.reform_path.outputs.workingDirectory }}/infra/main.bicep" | grep -oP "^param\s+\K\w+" || echo "")
echo "parameters from main.bicep without default value: $parameters"
# remove if parameters are set default values in /infra/main.parameters.json.
# The following the sample (no default value) in main.parameters.json: "location": { "value": "${AZURE_LOCATION}" }
# The following the sample (with default value) in main.parameters.json: "location": { "value": "${AZURE_LOCATION}=eastus2" }
if [ -f "${{ steps.reform_path.outputs.workingDirectory }}/infra/main.parameters.json" ]; then
required_env=""
for param in $parameters; do
echo "Checking parameter: $param"
# Check if parameter exists and has no default value
param_value=$(jq -r ".parameters."$param".value // empty" "${{ steps.reform_path.outputs.workingDirectory }}/infra/main.parameters.json" || echo "")
echo "$param value in parameter json file: $param_value"
if [ ! -z "$param_value" ] && [[ "$param_value" =~ ^\$\{[A-Za-z_]+\}$ ]]; then
# parse param_value to get the value. e.g get AZURE_LOCATION from "value": "${AZURE_LOCATION}"
env_key=$(echo "$param_value" | grep -oP '\$\{([^}]+)\}' | sed 's/\${//;s/}//g' || echo "")
echo "$param env_key: $env_key"
if [[ $env_key == 'AZURE_LOCATION' || $env_key == 'AZURE_ENV_NAME' || $env_key == 'AZURE_PRINCIPAL_ID' || $env_key == 'AZURE_PRINCIPAL_TYPE' || ${env_key,,} == *"location"* ]]; then
echo "Ignoring parameter: $param"
continue
else
# Set env_value with random value (15 characters and starts with a letter)
env_value=$(echo -n $(printf "%c" $(($RANDOM % 26 + 65)))$(for i in {1..14}; do echo -n $(($RANDOM % 36 + 48)) | awk '{printf "%c", ($1 > 57 ? $1 + 39 : $1)}'; done))
# If $env_key contains Capacity (ignore case), set env_value to "10"
if [[ ${env_key,,} == *"capacity"* ]]; then
env_value="10"
elif [[ ${env_key,,} == *"enabled"* ]]; then
env_value="false"
fi
echo "env_value: $env_value"
# Find the nearest @allowed annotation before this parameter
allowed_value=""
# Get the parameter line and check previous lines for @allowed
param_line_num=$(grep -n "^param $param " "${{ steps.reform_path.outputs.workingDirectory }}/infra/main.bicep" | cut -d: -f1 | head -1)
if [ -n "$param_line_num" ]; then
# Look backwards from the parameter line to find the nearest @allowed
start_line=$((param_line_num-1))
end_line=$((param_line_num-10))
if [ $end_line -lt 1 ]; then
end_line=1
fi
i=$start_line
while [ $i -ge $end_line ]; do
line=$(sed -n "${i}p" "${{ steps.reform_path.outputs.workingDirectory }}/infra/main.bicep")
if echo "$line" | grep -q "@allowed"; then
allowed_value=$(echo "$line" | grep -oP "@allowed\(\[\K[^\]]+" || echo "")
break
elif echo "$line" | grep -q "^param "; then
# Hit another parameter, stop searching
break
fi
i=$((i-1))
done
fi
if [ -n "$allowed_value" ]; then
echo "Parameter $param has allowed value: $allowed_value"
# Select first element in the allowed list
env_value=$(echo "$allowed_value" | tr -d "'" | tr -d '"' | awk -F, '{print $1}' | xargs)
echo "Using allowed value for $param: $env_value"
fi
echo "Adding to required_env: $env_key=$env_value"
required_env+="$env_key=$env_value "
echo "$env_key=$env_value" >> $GITHUB_ENV
fi
fi
done
echo "required_env from json: $required_env"
fi
else
echo "main.bicep not found, skipping parameter check"
fi
} || {
echo "Error occurred during parameter check process: $?"
echo "Continuing with validation despite parameter check failure..."
exit_code=$?
}
echo "Parameter check process completed"
exit 0 # Always exit successfully
shell: bash
continue-on-error: true
- name: Set additional validation environment variables
id: set_additional_envs
if: ${{ inputs.validateAzd == 'true' && inputs.validationEnvs != '' }}
run: |
IFS=',' read -ra ADDR <<< "${{ inputs.validationEnvs }}"
for env_pair in "${ADDR[@]}"; do
echo "$env_pair" >> $GITHUB_ENV
done
shell: bash
- name: Check and Set targetScope in main.bicep
id: check_targetScope
if: ${{ inputs.validateAzd == 'true' }}
run: |
if [ -f "${{ steps.reform_path.outputs.workingDirectory }}/infra/main.bicep" ]; then
# Check if targetScope is set to 'subscription' or 'resourceGroup'. The sample sentence in bicep is: targetScope = 'subscription'
targetScope=$(grep -oP "targetScope\s*=\s*['\"]\K[^'\"]+" "${{ steps.reform_path.outputs.workingDirectory }}/infra/main.bicep" 2>/dev/null || echo "")
echo "targetScope: $targetScope"
echo "targetScope=$targetScope" >> $GITHUB_ENV
if [ "$targetScope" == "subscription" ]; then
echo "targetScope is set to 'subscription' in main.bicep"
# Add the targetScope to the env variables
elif [ "$targetScope" == "resourceGroup" ]; then
echo "targetScope is set to 'resourceGroup' in main.bicep"
else
echo "targetScope is not set to 'subscription' or 'resourceGroup' in main.bicep, set to 'resourceGroup' by default"
targetScope="resourceGroup"
echo "targetScope=$targetScope" >> $GITHUB_ENV
fi
fi
shell: bash
continue-on-error: true
- name: Set azure resource group name in env
id: set_resource_group
if: ${{ inputs.validateAzd == 'true' && env.targetScope == 'resourceGroup' }}
run: |
azure_resource_group="rg-${{ env.AZURE_ENV_NAME }}"
echo "AZURE_RESOURCE_GROUP=$azure_resource_group" >> $GITHUB_ENV
echo "AZURE_RESOURCE_GROUP is $azure_resource_group"
shell: bash
env:
AZURE_ENV_NAME: ${{ env.AZURE_ENV_NAME }}
- name: Azure login
uses: azure/login@v2
if : ${{ inputs.validateAzd == 'true' && env.targetScope == 'resourceGroup' }}
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
- name: Azure CLI script
id: create_resource_group
if : ${{ inputs.validateAzd == 'true' && env.targetScope == 'resourceGroup' }}
run: |
az group create --resource-group ${{ env.AZURE_RESOURCE_GROUP }} --location ${{ env.AZURE_LOCATION }}
shell: bash
- name: Copy validator into devcontainer
if: ${{ inputs.useDevContainer == 'true' }}
run: |
mkdir -p ${{ steps.reform_path.outputs.workingDirectory }}/tva_${{ github.run_id }}
cp -r ${{ steps.reform_path.outputs.actionPath }}/src ${{ steps.reform_path.outputs.workingDirectory }}/tva_${{ github.run_id }}/src
cp ${{ steps.reform_path.outputs.actionPath }}/requirements.txt ${{ steps.reform_path.outputs.workingDirectory }}/tva_${{ github.run_id }}/requirements.txt
if [ -f "${{ steps.reform_path.outputs.workingDirectory }}/psrule-output.json" ]; then
cp ${{ steps.reform_path.outputs.workingDirectory }}/psrule-output.json ${{ inputs.workingDirectory }}/tva_${{ github.run_id }};
fi
env > ${{ steps.reform_path.outputs.workingDirectory }}/tva_${{ github.run_id }}/env_variables.txt
shell: bash
- uses: actions/github-script@v6
id: script
if: ${{ inputs.useDevContainer == 'true' && inputs.validateAzd == 'true' }}
with:
debug: true
script: |
const token = process.env['ACTIONS_RUNTIME_TOKEN']
const runtimeUrl = process.env['ACTIONS_ID_TOKEN_REQUEST_URL']
const aadToken = await core.getIDToken('api://AzureADTokenExchange');
core.setOutput('TOKEN', token.trim())
core.setOutput('AAD_TOKEN', aadToken.trim())
core.setOutput('ID_TOKEN_URL', runtimeUrl.trim())
# A workaround to those template that using Docker
- name: Start Docker
if: ${{ inputs.useDevContainer == 'true' && inputs.validateAzd == 'true' }}
uses: devcontainers/ci@v0.3
with:
runCmd: |
if find . -type f -iname 'dockerfile' | grep -q .; then
sudo service docker start > /dev/null
fi
subFolder: ${{ steps.reform_path.outputs.workingDirectory }}
continue-on-error: true
- name: Login azd in devcontainer
id: azd-login
if: ${{ inputs.useDevContainer == 'true' && inputs.validateAzd == 'true' }}
uses: devcontainers/ci@v0.3
with:
runCmd: |
azd auth login --client-id "${{ env.AZURE_CLIENT_ID }}" --federated-credential-provider "github" --tenant-id "${{ env.AZURE_TENANT_ID }}"
az login --service-principal -u "${{ env.AZURE_CLIENT_ID }}" --federated-token $AZURE_AD_TOKEN --tenant "${{ env.AZURE_TENANT_ID }}"
subFolder: ${{ steps.reform_path.outputs.workingDirectory }}
env: |
ACTIONS_ID_TOKEN_REQUEST_URL=${{ steps.script.outputs.ID_TOKEN_URL }}
ACTIONS_ID_TOKEN_REQUEST_TOKEN=${{ steps.script.outputs.TOKEN }}
AZURE_AD_TOKEN=${{ steps.script.outputs.AAD_TOKEN }}
continue-on-error: true
- name: Setup Python in devcontainer
id: setup-python
if: ${{ inputs.useDevContainer == 'true' }}
uses: devcontainers/ci@v0.3
with:
runCmd: |
if ! command -v python &> /dev/null; then
echo "python not found, installing python..."
sudo apt-get update && sudo apt-get install -y python3 python3-pip python3-venv
fi
python3 -m venv .venv --system-site-packages
source .venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install jupyter --force-reinstall
python3 -m pip install -r tva_${{ github.run_id }}/requirements.txt;
subFolder: ${{ steps.reform_path.outputs.workingDirectory }}
- name: Setup Node in devcontainer
id: setup-node
if: ${{ inputs.useDevContainer == 'true' && inputs.validateTests == 'Playwright' }}
uses: devcontainers/ci@v0.3
with:
runCmd: |
if ! command -v node &> /dev/null; then
echo "node not found, installing lts. node..."
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
fi
echo "Install playwright node..."
npm install @playwright/test
echo "Install playwright browsers..."
# Clean up package cache to free space
sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*
# Check available disk space
echo "Available disk space:"
df -h /
# Install playwright browsers first
npx playwright install
# Install required system dependencies for Playwright
echo "Installing Playwright system dependencies..."
sudo apt-get update || true
sudo apt-get install -y \
libdbus-1-3 \
libatk1.0-0t64 \
libatk-bridge2.0-0t64 \
libcups2t64 \
libxkbcommon0 \
libatspi2.0-0t64 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2t64 || echo "Some system dependencies could not be installed, but browsers should still work"
echo "Playwright browsers and dependencies installed successfully"
subFolder: ${{ steps.reform_path.outputs.workingDirectory }}
- name: Remove spaces from inputs
id: remove_spaces
run: |
inputs_validatePaths="${{ inputs.validatePaths }}"
inputs_topics="${{ inputs.topics }}"
inputs_validatePaths=$(echo "$inputs_validatePaths" | sed 's/ //g')
inputs_topics=$(echo "$inputs_topics" | sed 's/ //g')
echo "validatePaths=$inputs_validatePaths" >> $GITHUB_ENV
echo "expected_topics=$inputs_topics" >> $GITHUB_ENV
shell: bash
- name: Prepare arguments
id: prepare_arguments
run: |
arguments='--topics ${{ env.TOPICS }}'
if [ -n "${{ env.expected_topics }}" ]; then
arguments+=" --expected_topics ${{ env.expected_topics }}"
fi
if [ "${{ inputs.validateAzd }}" = "true" ]; then
arguments+=" --validate_azd"
fi
if [ -n "${{ env.validatePaths }}" ]; then
arguments+=" --validate_paths ${{ env.validatePaths }}"
fi
if [ ${{ inputs.securityAction }} == "PSRule" ]; then
arguments+=" --psrule_result ./psrule-output.json"
fi
if [ ${{ inputs.validateTests }} == "Playwright" ]; then
arguments+=" --validate_playwright_test"
fi
echo "arguments=$arguments" >> $GITHUB_OUTPUT
shell: bash
- name: Run validation
id: validation
if: ${{ inputs.useDevContainer == 'true' }}
uses: devcontainers/ci@v0.3
with:
runCmd: |
source .venv/bin/activate
if [ -f tva_${{ github.run_id }}/env_variables.txt ]; then
while IFS= read -r line; do
var_name=$(echo "$line" | cut -d'=' -f1)
if [ -z "${!var_name}" ]; then
export "$line"
fi
done < tva_${{ github.run_id }}/env_variables.txt
fi
python3 tva_${{ github.run_id }}/src/gallery_validate.py . --output tva_${{ github.run_id }}/output.log ${{ steps.prepare_arguments.outputs.arguments }}
subFolder: ${{ inputs.workingDirectory }}
env: |
ACTIONS_ID_TOKEN_REQUEST_URL=${{ steps.script.outputs.ID_TOKEN_URL }}
ACTIONS_ID_TOKEN_REQUEST_TOKEN=${{ steps.script.outputs.TOKEN }}
CREATE_ROLE_FOR_USER=false
AZURE_PRINCIPAL_TYPE=ServicePrincipal
FORCE_TERRAFORM_REMOTE_STATE_CREATION=false
- name: Send output to main workflow
id: send_output
if: ${{ inputs.useDevContainer == 'true' }}
uses: devcontainers/ci@v0.3
with:
runCmd: |
cat tva_${{ github.run_id }}/output.log
subFolder: ${{ steps.reform_path.outputs.workingDirectory }}
- name: Install AZD
if: ${{ inputs.useDevContainer == 'false' }}
uses: Azure/setup-azd@v2
- uses: actions/setup-node@v4
if: ${{ inputs.useDevContainer == 'false' && inputs.validateTests == 'Playwright' }}
with:
node-version: lts/*
- name: Install playwright
if: ${{ inputs.useDevContainer == 'false' && inputs.validateTests == 'Playwright' }}
working-directory: ${{ inputs.workingDirectory }}
run: |
echo "Install playwright node..."
npm install @playwright/test
echo "Install playwright browsers..."
npx playwright install --with-deps
shell: bash
- name: Log in with Azure (Federated Credentials)
if: ${{ inputs.validateAzd == 'true' && inputs.useDevContainer == 'false' }}
run: |
azd auth login --client-id "${{ env.AZURE_CLIENT_ID }}" --federated-credential-provider "github" --tenant-id "${{ env.AZURE_TENANT_ID }}"
shell: bash
env:
AZURE_CLIENT_ID: ${{ env.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ env.AZURE_TENANT_ID }}
- name: Run validation
id: run_validation
if: ${{ inputs.useDevContainer == 'false' }}
working-directory: ${{ inputs.workingDirectory }}
run: |
pip install -r ${{ steps.reform_path.outputs.actionPath }}/requirements.txt
python3 ${{ steps.reform_path.outputs.actionPath }}/src/gallery_validate.py . --output ${{ github.run_id }}-output.log ${{ steps.prepare_arguments.outputs.arguments }}
shell: bash
env:
CREATE_ROLE_FOR_USER: false
AZURE_PRINCIPAL_TYPE: "ServicePrincipal"
- name: Azure CLI script
id: delete_resource_group
if : ${{ inputs.validateAzd == 'true' && env.targetScope == 'resourceGroup' }}
run: |
az group delete --resource-group ${{ env.AZURE_RESOURCE_GROUP }} -y || echo "Warning: Failed to delete resource group ${AZURE_RESOURCE_GROUP}, continuing..."
shell: bash
continue-on-error: true
- id: set_output
run: |
if [[ ${{ inputs.useDevContainer }} == 'true' ]]; then
# Use here-document to safely handle special characters and long content
cat << 'VALIDATION_OUTPUT_EOF' >> ${{ github.run_id }}-output.log
${{ steps.send_output.outputs.runCmdOutput }}
VALIDATION_OUTPUT_EOF
fi
output_link=$(realpath ${{ github.run_id }}-output.log)
echo "resultFile is $output_link"
echo "resultFile=$output_link" >> $GITHUB_OUTPUT
working-directory: ${{ inputs.workingDirectory }}
shell: bash
- name: Write to workflow job summary
run: |
SUMMARY=$(cat ${{ steps.set_output.outputs.resultFile }})
echo "$SUMMARY" >> $GITHUB_STEP_SUMMARY
shell: bash
continue-on-error: true