From 969e9612f5269583e01f27a752d027ac7abc7365 Mon Sep 17 00:00:00 2001 From: Peter Gorniak Date: Thu, 25 Feb 2021 14:24:27 -0800 Subject: [PATCH] check for artifact presence --- .github/workflows/make_card_db_pr.yml | 29 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/make_card_db_pr.yml b/.github/workflows/make_card_db_pr.yml index 8797afa..efbdf76 100644 --- a/.github/workflows/make_card_db_pr.yml +++ b/.github/workflows/make_card_db_pr.yml @@ -14,27 +14,38 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/github-script@v3.1.0 + id: get-metadata with: + result-encoding: string script: | var artifacts = await github.actions.listWorkflowRunArtifacts({ owner: context.repo.owner, repo: context.repo.repo, run_id: ${{github.event.workflow_run.id }}, }); - var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + var matchArtifacts = artifacts.data.artifacts.filter((artifact) => { return artifact.name == "card_db" - })[0]; - var download = await github.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', }); - var fs = require('fs'); - fs.writeFileSync('${{github.workspace}}/card_db.zip', Buffer.from(download.data)); + if (matchArtifacts.length > 0) { + var matchArtifact = matchArtifacts[0]; + var download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/card_db.zip', Buffer.from(download.data)); + return 'found_artifact'; + } else { + return 'no_artifact' + } - run: unzip -d src/domdiv/card_db card_db.zip + if: steps.get-metadata.output.result == 'found_artifact' - run: rm -f card_db.zip + if: steps.get-metadata.output.result == 'found_artifact' - name: Make PR + if: steps.get-metadata.output.result == 'found_artifact' uses: peter-evans/create-pull-request@v3 with: body: |