From 7b010714a4ded0180b762d0f089687a6187b86d9 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Sun, 17 Dec 2023 10:38:49 +0400 Subject: [PATCH 1/8] Use `actions/upload-artifact@v4` in CI + CD workflow --- .github/workflows/ci_cd.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 26a57ce5283..b637d09df6f 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -231,11 +231,16 @@ jobs: FRONTEND_PNPM_VERSION=${{ steps.prepare-build-args.outputs.frontend_pnpm_version }} - name: Upload image `${{ matrix.image }}` - uses: actions/upload-artifact@v3 + id: upload-img + uses: actions/upload-artifact@v4 with: name: ${{ matrix.image }} path: /tmp/${{ matrix.image }}.tar + - name: Show artifact ID + run: | + echo '${{ matrix.image }} artifact ID is ${{ steps.upload-img.outputs.artifact-id }}' + ########### # Catalog # ########### @@ -346,7 +351,7 @@ jobs: - name: Upload ingestion test logs if: success() || failure() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ing_logs path: ingestion_server/test/ingestion_logs.txt @@ -399,7 +404,7 @@ jobs: - name: Upload API test logs if: success() || failure() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: api_logs path: api_logs @@ -456,7 +461,7 @@ jobs: - name: Upload schema if: matrix.name == 'test_doc' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: openapi.json path: ./api/openapi.json @@ -653,7 +658,7 @@ jobs: - name: Run Playwright tests run: just frontend/run ${{ matrix.script }} --workers=2 - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: failure() id: test-results with: @@ -771,7 +776,7 @@ jobs: # Docs will be located at `/tmp/docs`. - name: Upload documentation - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: documentation path: /tmp/docs/ From 3ae047cea8abe8eaa0b12a73f97a6e3fc2bf7399 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Sun, 17 Dec 2023 11:07:48 +0400 Subject: [PATCH 2/8] Use `actions/download-artifact@v4` in CI + CD workflow --- .github/workflows/ci_cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index b637d09df6f..da1bd07c167 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -814,7 +814,7 @@ jobs: steps: - name: Download documentation - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: documentation path: /tmp/docs From 58e8f5c1d6f6d4bd15ec776966d5ba1584d5cafc Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Sun, 17 Dec 2023 12:10:25 +0400 Subject: [PATCH 3/8] Accept workflow run ID as an action input `run_id` --- .github/actions/load-img/action.yml | 4 ++++ .github/workflows/ci_cd.yml | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/.github/actions/load-img/action.yml b/.github/actions/load-img/action.yml index dd4f35ab2e8..2c75ce0672a 100644 --- a/.github/actions/load-img/action.yml +++ b/.github/actions/load-img/action.yml @@ -2,6 +2,10 @@ name: openverse/load-img description: Download and import Docker images from artifacts inputs: + run_id: + description: The ID of the current workflow run + required: true + setup_images: default: "upstream_db ingestion_server catalog api api_nginx frontend" description: Space-separated list of image names diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index da1bd07c167..81fac43a17a 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -272,6 +272,7 @@ jobs: - name: Load Docker images uses: ./.github/actions/load-img with: + run_id: ${{ github.run_id }} setup_images: upstream_db catalog - name: Run tests @@ -303,6 +304,7 @@ jobs: - name: Load Docker images uses: ./.github/actions/load-img with: + run_id: ${{ github.run_id }} setup_images: upstream_db catalog - name: Check DAG documentation @@ -339,6 +341,7 @@ jobs: - name: Load Docker images uses: ./.github/actions/load-img with: + run_id: ${{ github.run_id }} setup_images: upstream_db ingestion_server - name: Run ingestion-server tests @@ -388,6 +391,7 @@ jobs: - name: Load Docker images uses: ./.github/actions/load-img with: + run_id: ${{ github.run_id }} setup_images: upstream_db ingestion_server api - name: Start API, ingest and index test data @@ -452,6 +456,7 @@ jobs: - name: Load Docker images uses: ./.github/actions/load-img with: + run_id: ${{ github.run_id }} setup_images: upstream_db ingestion_server api - name: Run check recipe @@ -931,6 +936,7 @@ jobs: - name: Load Docker image `${{ matrix.image }}` uses: ./.github/actions/load-img with: + run_id: ${{ github.run_id }} setup_images: ${{ matrix.image }} - name: Load and tag image `${{ matrix.image }}` (latest & sha) From 5381c13fcb2889176517dfdc6b2bb359aa84308e Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Sun, 17 Dec 2023 12:12:35 +0400 Subject: [PATCH 4/8] Update `@actions/artifact` package to v2 --- .github/actions/load-img/action.yml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/actions/load-img/action.yml b/.github/actions/load-img/action.yml index 2c75ce0672a..d7344823ecf 100644 --- a/.github/actions/load-img/action.yml +++ b/.github/actions/load-img/action.yml @@ -27,18 +27,28 @@ runs: - name: Install `@actions/artifact` shell: bash run: | - pnpm install @actions/artifact@1 -w + pnpm install @actions/artifact -w - name: Download images uses: actions/github-script@v6 with: script: | - const artifact = require("@actions/artifact") - const artifactClient = artifact.create() - const images = "${{ inputs.setup_images }}".split(" ") - for (image of images) { - await artifactClient.downloadArtifact(image, "/tmp", { createArtifactFolder: false }) + const { DefaultArtifactClient } = await import('@actions/artifact') + const artifact = new DefaultArtifactClient() + const images = '${{ inputs.setup_images }}'.split(' ') + const [repositoryOwner, repositoryName] = '${{ github.repository }}'.split('/') + const findBy = { + repositoryOwner, + repositoryName, + workflowRunId: '${{ inputs.run_id }}', } + const workflowArtifacts = await artifact.listArtifacts({ findBy }) + await Promise.all( + workflowArtifacts.artifacts + .filter((item) => images.includes(item.name)) + .map((item) => artifact.downloadArtifact(item.id, { findBy, path: '/tmp' })) + ) + console.log('Downloaded artifacts') - name: Load images shell: bash From 2dd03fd39dd69f1b04e61d60ed43d122ca9729a6 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Sun, 17 Dec 2023 12:23:57 +0400 Subject: [PATCH 5/8] Use `require` instead of `import` --- .github/actions/load-img/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/load-img/action.yml b/.github/actions/load-img/action.yml index d7344823ecf..9e2c40ff2cb 100644 --- a/.github/actions/load-img/action.yml +++ b/.github/actions/load-img/action.yml @@ -33,7 +33,7 @@ runs: uses: actions/github-script@v6 with: script: | - const { DefaultArtifactClient } = await import('@actions/artifact') + const { DefaultArtifactClient } = require('@actions/artifact') const artifact = new DefaultArtifactClient() const images = '${{ inputs.setup_images }}'.split(' ') const [repositoryOwner, repositoryName] = '${{ github.repository }}'.split('/') From bc0562a9018474abb6395c973ff4ce76e07dbb32 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Sun, 17 Dec 2023 12:45:49 +0400 Subject: [PATCH 6/8] Pass token to `@actions/artifacts` --- .github/actions/load-img/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/load-img/action.yml b/.github/actions/load-img/action.yml index 9e2c40ff2cb..3aefc264da7 100644 --- a/.github/actions/load-img/action.yml +++ b/.github/actions/load-img/action.yml @@ -41,6 +41,7 @@ runs: repositoryOwner, repositoryName, workflowRunId: '${{ inputs.run_id }}', + token: '${{ github.token }}', } const workflowArtifacts = await artifact.listArtifacts({ findBy }) await Promise.all( From f623bb84401d1704efdf197ed679f92f61e6d240 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Sun, 17 Dec 2023 13:27:18 +0400 Subject: [PATCH 7/8] Update other usages of `actions/upload-artifact` to v4 --- .github/workflows/pr_automations_init.yml | 2 +- .github/workflows/renovate.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr_automations_init.yml b/.github/workflows/pr_automations_init.yml index 265e189dab6..acae02e9253 100644 --- a/.github/workflows/pr_automations_init.yml +++ b/.github/workflows/pr_automations_init.yml @@ -44,7 +44,7 @@ jobs: PR_NODE_ID: ${{ github.event.pull_request.node_id }} - name: Upload event info as artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: event_info path: /tmp/event.json diff --git a/.github/workflows/renovate.yml b/.github/workflows/renovate.yml index bd98989f6d8..3673f75c0d6 100644 --- a/.github/workflows/renovate.yml +++ b/.github/workflows/renovate.yml @@ -78,7 +78,7 @@ jobs: # To solve *that*, we'd have to extract to root (/), which isn't safe. tar -czvf "$cache_archive" -C "$cache_dir" . - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: github.event.inputs.repoCache != 'disabled' with: name: ${{ env.cache_key }} From cd159bc557e1109487f0a781b320828ea201210a Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Sun, 17 Dec 2023 14:05:52 +0400 Subject: [PATCH 8/8] Replace unmaintained action with `actions/download-artifact` --- .github/workflows/push_docker_image.yml | 26 +++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/.github/workflows/push_docker_image.yml b/.github/workflows/push_docker_image.yml index 0ce266cb4c2..a519c833718 100644 --- a/.github/workflows/push_docker_image.yml +++ b/.github/workflows/push_docker_image.yml @@ -26,14 +26,32 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Determine successful run ID + id: determine-run-id + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.ACCESS_TOKEN }} + script: | + const [owner, repo] = '${{ github.repository }}'.split('/') + const { data: runs } = await github.rest.actions.listWorkflowRunsForRepo({ + owner, + repo, + branch: 'main', + event: 'push', + status: 'success', + head_sha: '${{ github.event.inputs.commit }}', + }) + const runId = runs.workflow_runs.find((run) => run.name === 'CI + CD').id + core.setOutput('run_id', runId) + - name: Download image `${{ github.event.inputs.image }}` - uses: dawidd6/action-download-artifact@v2 + uses: actions/download-artifact@v4 with: - workflow: ci_cd.yml - workflow_conclusion: success - commit: ${{ github.event.inputs.commit }} name: ${{ github.event.inputs.image }} path: /tmp + github_token: ${{ secrets.ACCESS_TOKEN }} + repository: ${{ github.repository }} + run_id: ${{ steps.determine-run-id.outputs.run_id }} - name: Load and tag image `${{ github.event.inputs.image }}` env: