-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaction.yml
102 lines (95 loc) · 3.89 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: "Continuous Deployment to Cloudflare Pages"
description: "Deploy to Cloudflare Pages"
inputs:
repository:
description: 'The GitHub repository to deploy, in the format "organization/repository"'
required: true
production_branch:
description: "Production Branch"
required: true
build_artifact_name:
description: "Github artifact name of the build output file"
required: true
output_directory:
description: "Output Directory"
required: true
current_branch:
description: "Compare if not production branch for preview deploys"
required: true
cloudflare_account_id:
description: "Cloudflare account id"
required: true
cloudflare_api_token:
description: "Cloudflare API token"
required: true
commit_sha:
description: "Commit SHA for posting the deployment link"
required: true
workflow_run_id:
description: "Workflow run id which called the action, used for fetching the build artifact"
required: true
statics_directory:
description: "Directory that contains static files"
required: false
app_id:
description: "GitHub App ID"
required: false
app_private_key:
description: "GitHub App Private Key"
required: false
runs:
using: "composite"
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20.10.0
- name: Get GitHub App token
if: inputs.app_id != '' && inputs.app_private_key != '' # Only attempt to authenticate if `app_id` and `app_private_key` are provided
uses: tibdex/[email protected]
id: get_installation_token
with:
app_id: ${{ inputs.app_id }}
private_key: ${{ inputs.app_private_key }}
- name: Find associated pull request
id: pr
uses: actions/github-script@v7
with:
github-token: ${{ steps.get_installation_token.outputs.token || github.token }}
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 {forcePreviewDeploy: false, pullRequestNumber: null }
}
const pullRequestNumber = items[0].number
const forcePreviewDeploy = pullRequestNumber > 0 && items[0].pull_request.merged_at == null
console.info("Pull request number is", pullRequestNumber)
console.info("forcePreviewDeploy", forcePreviewDeploy)
return {forcePreviewDeploy: forcePreviewDeploy, pullRequestNumber: pullRequestNumber }
- name: Download build artifact
uses: dawidd6/action-download-artifact@v3
with:
name: ${{ inputs.build_artifact_name }}
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 }}" "${{ fromJSON(steps.pr.outputs.result).forcePreviewDeploy && format('{0}/{1}', github.repository_owner, inputs.current_branch) || inputs.current_branch }}" "${{ inputs.statics_directory }}"
shell: bash
env:
CLOUDFLARE_ACCOUNT_ID: ${{ inputs.cloudflare_account_id }}
CLOUDFLARE_API_TOKEN: ${{ inputs.cloudflare_api_token }}
- name: Post Deployment on Pull Request or Commit
shell: bash
run: |
cd ../../_actions/ubiquity/cloudflare-deploy-action/main
yarn
yarn tsx src/index.ts \
--deployment_output "${{ env.DEPLOYMENT_OUTPUT }}" \
--repository "${{ inputs.repository }}" \
--pull_request_number "${{ fromJSON(steps.pr.outputs.result).pullRequestNumber }}" \
--commit_sha "${{ inputs.commit_sha }}"