From ca194135e2ca43dfff0741aafc300faecf78494e Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Thu, 11 Apr 2024 20:29:26 -0700 Subject: [PATCH] use workflow_run event --- .github/workflows/ci.yml | 7 ----- .github/workflows/upload-s3.yml | 56 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/upload-s3.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a8199e35..3e45f6620 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,13 +105,6 @@ jobs: with: name: acli.phar path: var/acli.phar - - name: Store artifact in S3 - run: | - aws s3 cp var/acli.phar s3://acquia-cli/build/$GITHUB_SHA/ - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: us-east-1 - name: Release uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') diff --git a/.github/workflows/upload-s3.yml b/.github/workflows/upload-s3.yml new file mode 100644 index 000000000..1e287eede --- /dev/null +++ b/.github/workflows/upload-s3.yml @@ -0,0 +1,56 @@ +name: Upload phar to S3 +on: + workflow_run: + workflows: [CI] + types: + - completed +jobs: + download: + runs-on: ubuntu-latest + steps: + - name: Find associated pull request + id: pr + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 + with: + script: | + const response = await github.rest.search.issuesAndPullRequests({ + q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}', + per_page: 1, + }) + const items = response.data.items + if (items.length < 1) { + console.error('No PRs found') + return + } + const pullRequestNumber = items[0].number + console.info("Pull request number is", pullRequestNumber) + return pullRequestNumber + - name: 'Download artifact' + 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 == "acli.phar" + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/acli.phar.zip`, Buffer.from(download.data)); + - name: 'Unzip artifact' + run: unzip acli.phar.zip + - name: Store artifact in S3 + run: | + aws s3 cp acli.phar s3://acquia-cli/build/$GITHUB_SHA/ + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-east-1