From 623ac2734a3b425a76fa95ed2e6676ed7d7fd72d Mon Sep 17 00:00:00 2001 From: Milosz Wasilewski Date: Thu, 16 Jan 2025 14:45:19 +0000 Subject: [PATCH 1/4] workflows: move base artifact URL to env variable This change allows to keep the base URL in one place and helps avoid mistakes when changing it. Signed-off-by: Milosz Wasilewski --- .github/workflows/build-yocto.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-yocto.yml b/.github/workflows/build-yocto.yml index ad044fb1..81ef622c 100644 --- a/.github/workflows/build-yocto.yml +++ b/.github/workflows/build-yocto.yml @@ -10,6 +10,7 @@ on: env: CACHE_DIR: /srv/gh-runners/quic-yocto KAS_REPO_REF_DIR: /srv/gh-runners/quic-yocto/kas-mirrors + BASE_ARTIFACT_URL: "https://quic-yocto-fileserver-1029608027416.us-central1.run.app/${{ github.run_id }}" jobs: kas-lock: @@ -107,7 +108,7 @@ jobs: mv ../kas/build/tmp/deploy/images/${{matrix.machine}} $img_dir # Instruct our file server to make these files available for download - url="https://quic-yocto-fileserver-1029608027416.us-central1.run.app/${GITHUB_RUN_ID}/${{ matrix.machine }}/" + url="${BASE_ARTIFACT_URL}/${{ matrix.machine }}/" retries=8 okay=0 @@ -142,5 +143,5 @@ jobs: - name: "Print output" id: print-output run: | - echo "Downloads URL: https://quic-yocto-fileserver-1029608027416.us-central1.run.app/${GITHUB_RUN_ID}/" - echo "url=\"https://quic-yocto-fileserver-1029608027416.us-central1.run.app/${GITHUB_RUN_ID}/\"" >> $GITHUB_OUTPUT + echo "Downloads URL: ${BASE_ARTIFACT_URL}" + echo "url=\"${BASE_ARTIFACT_URL}\"" >> $GITHUB_OUTPUT From db2b656a968d1e537aa4b7a1b337ebae22b07354 Mon Sep 17 00:00:00 2001 From: Milosz Wasilewski Date: Thu, 16 Jan 2025 14:46:22 +0000 Subject: [PATCH 2/4] workflows: save build URL as artifact This is required for running tests after PR builds. Tests triggered after PR build will use the artifact file to retrieve base download URL. Signed-off-by: Milosz Wasilewski --- .github/workflows/build-yocto.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build-yocto.yml b/.github/workflows/build-yocto.yml index 81ef622c..0468e332 100644 --- a/.github/workflows/build-yocto.yml +++ b/.github/workflows/build-yocto.yml @@ -145,3 +145,9 @@ jobs: run: | echo "Downloads URL: ${BASE_ARTIFACT_URL}" echo "url=\"${BASE_ARTIFACT_URL}\"" >> $GITHUB_OUTPUT + echo "${BASE_ARTIFACT_URL}" > build_url + - name: Upload build URL + uses: actions/upload-artifact@v4 + with: + name: build_url + path: build_url From 82828134065d8a8bfe6f49e5d1c88525e1746679 Mon Sep 17 00:00:00 2001 From: Milosz Wasilewski Date: Thu, 16 Jan 2025 14:49:51 +0000 Subject: [PATCH 3/4] workflows: Retrieve build URL from artifact Workflows triggered by "workflow_run" event don't receive any variables from triggering event. the only way to pass the variable is throught the uploaded artifact test-pr workflow is triggered by PR build completion. This patch allows test-pr to retrieve the build_url from saved artifact before triggering tests. Signed-off-by: Milosz Wasilewski --- .github/workflows/test-pr.yml | 44 +++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 00a5cabf..379ece60 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -7,10 +7,50 @@ on: - completed jobs: + retrieve-build-url: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + outputs: + url: ${{ steps.set-build-url.outputs.url }} + steps: + - name: 'Download build URL' + uses: actions/github-script@v6 + with: + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == "build_url" + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + const fs = require('fs'); + const path = require('path'); + const temp = '${{ runner.temp }}/artifacts'; + if (!fs.existsSync(temp)){ + fs.mkdirSync(temp); + } + fs.writeFileSync(path.join(temp, 'build_url.zip'), Buffer.from(download.data)); + + - name: 'Setup build URL' + id: set-build-url + run: | + unzip "${{ runner.temp }}/artifacts/build_url.zip" + BUILD_URL=$(cat build_url) + echo "Build URL: ${BUILD_URL}" + echo "url=${BUILD_URL}" >> $GITHUB_OUTPUT + test: uses: ./.github/workflows/test.yml secrets: inherit - if: ${{ github.event.workflow_run.conclusion == 'success' }} + needs: retrieve-build-url with: - url: ${{ github.event.workflow_run.outputs.artifacts_url }} + url: ${{ needs.retrieve-build-url.outputs.url }} From 6f7704336fc80eb2ee9280801d91034bc325c987 Mon Sep 17 00:00:00 2001 From: Milosz Wasilewski Date: Thu, 16 Jan 2025 14:51:51 +0000 Subject: [PATCH 4/4] workflows: update test-pr display title Display title is set to title of the PR that triggered original build Signed-off-by: Milosz Wasilewski --- .github/workflows/test-pr.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 379ece60..b2fb165d 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -1,5 +1,7 @@ name: Test PR build +run-name: "Tests triggered by PR: ${{ github.event.workflow_run.display_title }}" + on: workflow_run: workflows: ["Build on PR"]