Skip to content

Commit

Permalink
Merge pull request #5 from ubiquity/ci/download-build-artifact
Browse files Browse the repository at this point in the history
ci: download build artifact
  • Loading branch information
rndquu authored Mar 19, 2024
2 parents 5f7a489 + 5bbf322 commit c797941
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ inputs:
current_branch:
description: "Compare if not production branch for preview deploys"
required: true
pull_request_number:
description: "Pull request number for posting the deployment link"
cloudflare_account_id:
description: "Cloudflare account id"
required: true
cloudflare_api_token:
description: "Cloudflare API token"
required: true
cloudflare_account_id:
description: "Cloudflare account id"
Expand All @@ -25,21 +28,43 @@ inputs:
required: true
commit_sha:
description: "Commit SHA for posting the deployment link"
required: false
required: true
workflow_run_id:
description: "Workflow run id which called the action, used for fetching the build artifact"
required: true

runs:
using: "composite"
steps:
- name: Check for pull_request_number or commit_sha
shell: bash
run: |
if [ -z "${{ inputs.pull_request_number }}" ] && [ -z "${{ inputs.commit_sha }}" ]; then
# this is for merged pull requests, which do not contain a commit sha
echo "COMMIT_SHA=${{ github.sha }}" >> $GITHUB_ENV
else
# this is for normal commits on pull requests
echo "COMMIT_SHA=${{ inputs.commit_sha }}" >> $GITHUB_ENV
fi
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20.10.0

- name: Find associated pull request
id: pr
uses: actions/github-script@v7
with:
script: |
const response = await github.rest.search.issuesAndPullRequests({
q: 'repo:${{ inputs.repository }} is:pr sha:${{ inputs.commit_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 build artifact
uses: dawidd6/action-download-artifact@v3
with:
name: ${{ inputs.output_directory }}
path: ${{ inputs.output_directory }}
run_id: ${{ inputs.workflow_run_id }}

- name: Deploy to Cloudflare
run: bash ../../_actions/ubiquity/cloudflare-deploy-action/main/.github/cloudflare-deploy.sh "${{ inputs.repository }}" "${{ inputs.production_branch }}" "${{ inputs.output_directory }}" "${{ inputs.current_branch }}"
Expand All @@ -56,5 +81,5 @@ runs:
yarn tsx src/index.ts \
--deployment_output "${{ env.DEPLOYMENT_OUTPUT }}" \
--repository "${{ inputs.repository }}" \
--pull_request_number "${{ inputs.pull_request_number }}" \
--commit_sha "${{ env.COMMIT_SHA }}"
--pull_request_number "${{ steps.pr.outputs.result }}" \
--commit_sha "${{ inputs.commit_sha }}"

0 comments on commit c797941

Please sign in to comment.