Skip to content

Upload phar to S3

Upload phar to S3 #588

Workflow file for this run

name: Upload phar to S3
on:
workflow_run:
workflows: [CI]
types:
- completed
permissions:
pull-requests: write
jobs:
upload-s3:
runs-on: ubuntu-latest
if: >-
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
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@v7
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/pr/${{ steps.pr.outputs.result }}/
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: Comment on PR
run: |
GITHUB_PR=${{ steps.pr.outputs.result }}
COMMENT="Try the dev build for this PR: https://acquia-cli.s3.amazonaws.com/build/pr/${{ steps.pr.outputs.result }}/acli.phar
\`\`\`
curl -OL https://acquia-cli.s3.amazonaws.com/build/pr/${{ steps.pr.outputs.result }}/acli.phar
chmod +x acli.phar
\`\`\`"
COMMENT_URL="https://github.com/$GITHUB_REPOSITORY/pull/$GITHUB_PR"
gh pr comment --edit-last $COMMENT_URL --body "$COMMENT" || gh pr comment $COMMENT_URL --body "$COMMENT"
env:
GH_TOKEN: ${{ github.token }}