Skip to content

Commit 25acc21

Browse files
authored
Updates to build & test workflow (#366)
Updates to the build & Test workflow, following #364. Changes: - All Blob I/O is now handled through the new blob-copy action - References to GITHUB_ENV have been removed, using GITHUB_OUTPUT instead. (Reduces chances of overwriting a variable)
1 parent e47e031 commit 25acc21

File tree

1 file changed

+43
-59
lines changed

1 file changed

+43
-59
lines changed

.github/workflows/build-push-private.yml

Lines changed: 43 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ jobs:
209209
run: |
210210
DOCKERFILE_LABELS="$(grep "^LABEL" workflow.transition.monitor/Dockerfile | sed 's/^LABEL[[:space:]]*//')"
211211
echo "$DOCKERFILE_LABELS"
212-
echo "DOCKERFILE_LABELS<<EOF" >> $GITHUB_ENV
213-
echo "$DOCKERFILE_LABELS" >> $GITHUB_ENV
214-
echo 'EOF' >> $GITHUB_ENV
215212
echo 'dockerfile-labels<<EOF' >> $GITHUB_OUTPUT
216213
echo "$DOCKERFILE_LABELS" >> $GITHUB_OUTPUT
217214
echo 'EOF' >> $GITHUB_OUTPUT
@@ -226,9 +223,9 @@ jobs:
226223
with:
227224
images: ${{ needs.read-config.outputs.registry-image }}
228225
annotations:
229-
${{ env.DOCKERFILE_LABELS }}
226+
${{ steps.custom-labels.outputs.DOCKERFILE_LABELS }}
230227
labels:
231-
${{ env.DOCKERFILE_LABELS }}
228+
${{ steps.custom-labels.outputs.DOCKERFILE_LABELS }}
232229
tags: |
233230
type=schedule,enable=true,pattern={{date 'YYYYMMDD[T]HHmmss[Z]' tz='UTC'}}
234231
type=schedule,enable=true,pattern=nightly,priority=950
@@ -253,25 +250,27 @@ jobs:
253250

254251
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-masking-a-generated-output-within-a-single-job
255252
- name: Get credentials for docker registry
253+
id: docker-credentials
256254
uses: azure/CLI@v2
257255
env:
258256
registry: ${{ inputs.registry }}
259257
with:
260258
# azcliversion: 2.30.0
261259
inlineScript: |
262260
# Username is not a placeholder. See https://stackoverflow.com/a/73250630
263-
DOCKER_USER="00000000-0000-0000-0000-000000000000" >> "$GITHUB_ENV"
264-
DOCKER_TOKEN="$(az acr login -n $registry --expose-token --query 'accessToken' --output tsv)" >> "$GITHUB_ENV"
265-
# echo "::add-mask::$DOCKER_USER"
261+
DOCKER_USER="00000000-0000-0000-0000-000000000000" >> "$GITHUB_OUTPUT"
262+
DOCKER_TOKEN="$(az acr login -n $registry --expose-token --query 'accessToken' --output tsv)" >> "$GITHUB_OUTPUT"
266263
echo "::add-mask::$DOCKER_TOKEN"
267-
echo "DOCKER_USER=$DOCKER_USER" >> "$GITHUB_ENV"
268-
echo "DOCKER_TOKEN=$DOCKER_TOKEN" >> "$GITHUB_ENV"
264+
echo "docker-user=$DOCKER_USER" >> "$GITHUB_OUTPUT"
265+
echo "docker-token=$DOCKER_TOKEN" >> "$GITHUB_OUTPUT"
269266
270267
- name: Login to Registry
271268
env:
272-
registry: ${{ inputs.registry }}
269+
REGISTRY: ${{ inputs.registry }}
270+
DOCKER_TOKEN: ${{ steps.docker-credentials.outputs.docker-token }}
271+
DOCKER_USER: ${{ steps.docker-credentials.outputs.docker-user }}
273272
run: |
274-
echo "$DOCKER_TOKEN" | docker login $registry --username "$DOCKER_USER" --password-stdin
273+
echo "$DOCKER_TOKEN" | docker login $REGISTRY --username "$DOCKER_USER" --password-stdin
275274
276275
# Actually build the image (for a single architecture)!
277276
- name: Build
@@ -312,22 +311,12 @@ jobs:
312311
313312
314313
- name: Export inputs archive
315-
uses: azure/CLI@v2
316-
env:
317-
full_image_name: ${{ steps.export-outputs.outputs.full-image-name }}
318-
tarfile: ${{ steps.prepare-inputs-archive.outputs.input-tar }}
314+
id: upload-report
315+
uses: RMI-PACTA/actions/actions/azure/blob-copy@main
319316
with:
320-
inlineScript: |
321-
upload_container="https://pactadatadev.blob.core.windows.net/ghactions-workflow-transition-monitor-input-pacta-data"
322-
destination_path="$upload_container/$tarfile"
323-
echo "$destination_path"
324-
325-
az storage copy \
326-
--source "$tarfile" \
327-
--destination "$destination_path" \
328-
--recursive
329-
330-
echo "Archive available at: $destination_path"
317+
source: ${{ steps.prepare-inputs-archive.outputs.input-tar }}
318+
destination: https://pactadatadev.blob.core.windows.net/ghactions-workflow-transition-monitor-input-pacta-data
319+
overwrite: false
331320

332321
test:
333322
runs-on: ubuntu-latest
@@ -360,6 +349,7 @@ jobs:
360349
uses: actions/checkout@v4
361350

362351
- name: Prepare User and results directories
352+
id: prepare-results-dir
363353
env:
364354
full_image_name: ${{ needs.docker-build.outputs.full-image-name }}
365355
image_name: ${{ inputs.image-name }}
@@ -373,13 +363,13 @@ jobs:
373363
test_dir_parent_name="$(echo $full_image_name | sed 's:.*/::' | tr ":" "-")"
374364
TEST_DIR_PARENT="$test_dir_parent_name"
375365
echo "TEST_DIR_PARENT=$TEST_DIR_PARENT"
376-
echo "TEST_DIR_PARENT=$TEST_DIR_PARENT" >> "$GITHUB_ENV"
366+
echo "test-dir-parent=$TEST_DIR_PARENT" >> "$GITHUB_OUTPUT"
377367
378368
TEST_DIR="$TEST_DIR_PARENT/$language/$peer_group/$run_attempt"
379369
mkdir -p "$TEST_DIR"
380370
chmod -R 777 "$TEST_DIR"
381371
echo "TEST_DIR=$TEST_DIR"
382-
echo "TEST_DIR=$TEST_DIR" >> "$GITHUB_ENV"
372+
echo "test-dir=$TEST_DIR" >> "$GITHUB_OUTPUT"
383373
384374
mkdir -p $TEST_DIR/user_dir
385375
cp -R working_dir $TEST_DIR
@@ -408,7 +398,7 @@ jobs:
408398
uses: azure/CLI@v2
409399
env:
410400
user_results: ${{ matrix.user_results }}
411-
test_dir: ${{ env.TEST_DIR }}
401+
test_dir: ${{ steps.prepare-results-dir.outputs.test-dir }}
412402
project_code: ${{ needs.read-config.outputs.project-code }}
413403
with:
414404
inlineScript: |
@@ -423,32 +413,35 @@ jobs:
423413
echo "No User Results defined in config"
424414
fi
425415
416+
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-masking-a-generated-output-within-a-single-job
426417
- name: Get credentials for docker registry
418+
id: docker-credentials
427419
uses: azure/CLI@v2
428420
env:
429421
registry: ${{ inputs.registry }}
430422
with:
431423
# azcliversion: 2.30.0
432424
inlineScript: |
433425
# Username is not a placeholder. See https://stackoverflow.com/a/73250630
434-
DOCKER_USER="00000000-0000-0000-0000-000000000000" >> "$GITHUB_ENV"
435-
DOCKER_TOKEN="$(az acr login -n $registry --expose-token --query 'accessToken' --output tsv)" >> "$GITHUB_ENV"
436-
# echo "::add-mask::$DOCKER_USER"
426+
DOCKER_USER="00000000-0000-0000-0000-000000000000" >> "$GITHUB_OUTPUT"
427+
DOCKER_TOKEN="$(az acr login -n $registry --expose-token --query 'accessToken' --output tsv)" >> "$GITHUB_OUTPUT"
437428
echo "::add-mask::$DOCKER_TOKEN"
438-
echo "DOCKER_USER=$DOCKER_USER" >> "$GITHUB_ENV"
439-
echo "DOCKER_TOKEN=$DOCKER_TOKEN" >> "$GITHUB_ENV"
429+
echo "docker-user=$DOCKER_USER" >> "$GITHUB_OUTPUT"
430+
echo "docker-token=$DOCKER_TOKEN" >> "$GITHUB_OUTPUT"
440431
441432
- name: Login to Registry
442433
env:
443-
registry: ${{ inputs.registry }}
434+
REGISTRY: ${{ inputs.registry }}
435+
DOCKER_TOKEN: ${{ steps.docker-credentials.outputs.docker-token }}
436+
DOCKER_USER: ${{ steps.docker-credentials.outputs.docker-user }}
444437
run: |
445-
echo "$DOCKER_TOKEN" | docker login $registry --username "$DOCKER_USER" --password-stdin
438+
echo "$DOCKER_TOKEN" | docker login $REGISTRY --username "$DOCKER_USER" --password-stdin
446439
447440
- name: Test
448441
env:
449442
full_image_name: ${{ needs.docker-build.outputs.full-image-name }}
450443
image_name: ${{ inputs.image-name }}
451-
test_dir: ${{ env.TEST_DIR }}
444+
test_dir: ${{ steps.prepare-results-dir.outputs.test-dir }}
452445
workspace: ${{ github.workspace }}
453446
run: |
454447
chmod -R 777 "$test_dir/working_dir"
@@ -472,49 +465,44 @@ jobs:
472465
id: upload-results
473466
uses: RMI-PACTA/actions/actions/azure/blob-copy@main
474467
with:
475-
source: ${{ env.TEST_DIR_PARENT }}
468+
source: ${{ steps.prepare-results-dir.outputs.test-dir-parent }}
476469
destination: https://pactadatadev.blob.core.windows.net/ghactions-workflow-transition-monitor-results-full
477470
overwrite: false
478-
log_level: debug
479471

480472
- name: Upload report to Blob store
481473
id: upload-report
482474
uses: RMI-PACTA/actions/actions/azure/blob-copy@main
483475
with:
484-
source: ${{ env.TEST_DIR_PARENT }}/${{ matrix.language }}/${{ matrix.peer_group }}/${{ github.run_attempt }}/working_dir/50_Outputs
476+
source: ${{ steps.prepare-results-dir.outputs.test-dir-parent }}/${{ matrix.language }}/${{ matrix.peer_group }}/${{ github.run_attempt }}/working_dir/50_Outputs
485477
destination: https://pactadatadev.blob.core.windows.net/ghactions-workflow-transition-monitor-results-reports
486478
overwrite: false
487-
log_level: debug
488479

489480
- name: Export Outputs
490481
id: export-outputs
491482
env:
492-
REPORTS_DESTINATION_URL: ${{ needs.read-config.outputs.reports-destination-url }}
483+
REPORT_UPLOADED_FILES: ${{ steps.upload-report.outputs.destination-files }}
493484
image_name: ${{ inputs.image-name }}
494-
test_dir: ${{ env.TEST_DIR }}
485+
test_dir: ${{ steps.prepare-results-dir.outputs.test-dir }}
495486
run: |
496-
BLOB_DIR="$REPORTS_DESTINATION_URL/$test_dir/working_dir/50_Outputs/$image_name"
497-
echo "blob-dir=$BLOB_DIR"
498-
echo "blob-dir=$BLOB_DIR" >> "$GITHUB_OUTPUT"
499-
echo "blob-dir=$BLOB_DIR" >> "$GITHUB_ENV"
500487
501-
REPORT_URL="$BLOB_DIR/report/index.html"
488+
REPORT_URL="$(
489+
echo "$REPORT_UPLOADED_FILES" | jq -rc '. [] | match(".*index.html$") | .string'
490+
)"
502491
echo "report-url=$REPORT_URL"
503492
echo "report-url=$REPORT_URL" >> "$GITHUB_OUTPUT"
504-
echo "report-url=$REPORT_URL" >> "$GITHUB_ENV"
505493
506494
SUMMARY_PATH="${test_dir}/working_dir/50_Outputs/$image_name/executive_summary/template.pdf"
507495
if [ -f "$SUMMARY_PATH" ]; then
508-
SUMMARY_URL="$BLOB_DIR/executive_summary/template.pdf"
496+
SUMMARY_URL="$(
497+
echo "$REPORT_UPLOADED_FILES" | jq -rc '. [] | match(".*template.pdf$") | .string'
498+
)"
509499
echo "summary-url=$SUMMARY_URL"
510500
echo "summary-url=$SUMMARY_URL" >> "$GITHUB_OUTPUT"
511-
echo "summary-url=$SUMMARY_URL" >> "$GITHUB_ENV"
512501
fi
513502
514503
- name: Prepare comment artifact
515504
id: prepare-artifact
516505
env:
517-
blob_dir: ${{ steps.export-outputs.outputs.blob-dir }}
518506
commit_time: ${{ github.event.pull_request.updated_at }}
519507
full_image_name: ${{ needs.docker-build.outputs.full-image-name }}
520508
git_sha: ${{ github.event.pull_request.head.sha }},
@@ -534,8 +522,7 @@ jobs:
534522
echo "comment-json-merge-$image_name-$registry-$language-$peer_group.json" | \
535523
tr '/' '-' \
536524
)
537-
echo "json-filename=$json_filename" >> "$GITHUB_ENV"
538-
blob_dest="$(basename $blob_dir)-$language-$peer_group"
525+
echo "json-filename=$json_filename" >> "$GITHUB_OUTPUT"
539526
json_file="/tmp/comment-json/$json_filename"
540527
jq \
541528
-n \
@@ -548,8 +535,6 @@ jobs:
548535
--arg report_url "$report_url" \
549536
--arg summary_url "$summary_url" \
550537
--arg full_image_name "$full_image_name" \
551-
--arg blob_dir "$blob_dir" \
552-
--arg blob_dest "$blob_dest" \
553538
'{
554539
"commit_time": $commit_time,
555540
"git_sha": $git_sha,
@@ -559,7 +544,6 @@ jobs:
559544
"peer_group": $peer_group,
560545
"report": (if (("" + $report_url) == "") then null else "[Report](" + $report_url + ")" end),
561546
"summary": (if (("" + $summary_url) == "") then null else "[Summary](" + $summary_url + ")" end),
562-
"download_command": ("`az storage copy --recursive --source " + $blob_dir + " --destination " + $blob_dest + "`"),
563547
"image": ("`" + $full_image_name + "`")
564548
}' \
565549
>> $json_file
@@ -568,7 +552,7 @@ jobs:
568552
- name: Upload comment JSON
569553
uses: actions/upload-artifact@v4
570554
with:
571-
name: ${{ env.json-filename }}
555+
name: ${{ steps.prepare-artifact.outputs.json-filename }}
572556
path: /tmp/comment-json/*
573557
if-no-files-found: error
574558
retention-days: 1

0 commit comments

Comments
 (0)