@@ -14,53 +14,57 @@ permissions:
14
14
actions : read
15
15
16
16
jobs :
17
- pull-request-data :
17
+ deployment-metadata :
18
18
if : ${{ github.event.workflow_run.conclusion == 'success' }}
19
19
runs-on : ubuntu-latest
20
20
outputs :
21
- number : ${{ steps.pull_request.outputs.number }}
22
- ref : ${{ steps.pull_request.outputs.ref }}
23
- any_changed : ${{ steps.pull_request.outputs.any_changed }}
21
+ pr_number : ${{ steps.metadata.outputs.pr_number }}
22
+ ref : ${{ steps.metadata.outputs.ref }}
23
+ should_deploy : ${{ steps.metadata.outputs.should_deploy }}
24
+ path_prefix : ${{ steps.metadata.outputs.path_prefix }}
24
25
steps :
25
- - name : Download PR data
26
+ - name : Download deployment metadata
26
27
env :
27
28
GH_TOKEN : ${{ github.token }}
28
29
run : |
29
30
gh run download ${{ github.event.workflow_run.id }} \
30
31
--repo "${GITHUB_REPOSITORY}" \
31
- --name pull-request-data
32
- - name : Get PR data
33
- id : pull_request
32
+ --name deployment_metadata
33
+ - name : Get deployment metadata
34
+ id : metadata
34
35
run : |
35
36
{
36
- echo "number=$(jq -r '.number' pull_request.json)"
37
- echo "ref=$(jq -r '.ref' pull_request.json)"
38
- echo "any_changed=$(jq -r '.any_changed' pull_request.json)"
37
+ echo "pr_number=$(jq -r '.pr_number' deployment_metadata.json)"
38
+ echo "ref=$(jq -r '.ref' deployment_metadata.json)"
39
+ echo "path_prefix=$(jq -r '.path_prefix' deployment_metadata.json)"
40
+ echo "should_deploy=$(jq -r '.should_deploy' deployment_metadata.json)"
39
41
} >> "${GITHUB_OUTPUT}"
40
42
41
43
deploy :
42
- needs : pull-request-data
43
- if : needs.pull-request-data .outputs.any_changed == 'true'
44
+ needs : deployment-metadata
45
+ if : needs.deployment-metadata .outputs.should_deploy == 'true'
44
46
runs-on : ubuntu-latest
45
47
concurrency :
46
- group : ${{ github.workflow }}-${{ needs.pull-request-data .outputs.number }}
48
+ group : ${{ github.workflow }}-${{ needs.deployment-metadata .outputs.pr_number }}
47
49
cancel-in-progress : true
48
50
steps :
49
51
- name : Create Deployment
50
52
uses : actions/github-script@v7
51
53
id : deployment
52
54
env :
53
- PR_NUMBER : ${{ needs.pull-request-data .outputs.number }}
54
- PR_REF : ${{ needs.pull-request-data .outputs.ref }}
55
+ PR_NUMBER : ${{ needs.deployment-metadata .outputs.pr_number }}
56
+ REF : ${{ needs.deployment-metadata .outputs.ref }}
55
57
with :
56
58
result-encoding : string
57
59
script : |
58
60
const { owner, repo } = context.repo;
61
+ const prNumber = process.env.PR_NUMBER;
62
+ const environment = prNumber ? `docs-preview-${prNumber}` : 'docs-preview';
59
63
const deployment = await github.rest.repos.createDeployment({
60
64
owner,
61
65
repo,
62
- ref: process.env.PR_REF ,
63
- environment: `docs-preview-${ process.env.PR_NUMBER}` ,
66
+ environment ,
67
+ ref: process.env.REF ,
64
68
auto_merge: false,
65
69
required_contexts: [],
66
70
})
@@ -86,25 +90,27 @@ jobs:
86
90
87
91
- name : Upload to S3
88
92
env :
89
- PR_NUMBER : ${{ needs.pull-request-data.outputs.number }}
93
+ PR_NUMBER : ${{ needs.deployment-metadata.outputs.pr_number }}
94
+ PATH_PREFIX : ${{ needs.deployment-metadata.outputs.path_prefix }}
90
95
run : |
91
- aws s3 sync ./html "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER }" --delete
96
+ aws s3 sync ./html "s3://elastic-docs-v3-website-preview${PATH_PREFIX }" --delete
92
97
aws cloudfront create-invalidation \
93
98
--distribution-id EKT7LT5PM8RKS \
94
- --paths "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER} " "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER }/*"
99
+ --paths "${PATH_PREFIX} " "/${PATH_PREFIX }/*"
95
100
96
101
- name : Update deployment status
97
102
uses : actions/github-script@v7
98
103
if : always() && steps.deployment.outputs.result
99
104
env :
100
- PR_NUMBER : ${{ needs.pull-request-data.outputs.number }}
105
+ PR_NUMBER : ${{ needs.deployment-metadata.outputs.pr_number }}
106
+ PATH_PREFIX : ${{ needs.deployment-metadata.outputs.path_prefix }}
101
107
with :
102
108
script : |
103
109
await github.rest.repos.createDeploymentStatus({
104
110
owner: context.repo.owner,
105
111
repo: context.repo.repo,
106
112
deployment_id: ${{ steps.deployment.outputs.result }},
107
113
state: "${{ job.status == 'success' && 'success' || 'failure' }}",
108
- environment_url: `https://docs-v3-preview.elastic.dev/${context.repo.owner}/${context.repo.repo}/pull/${ process.env.PR_NUMBER }`,
114
+ environment_url: `https://docs-v3-preview.elastic.dev${ process.env.PATH_PREFIX }`,
109
115
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
110
116
})
0 commit comments