@@ -14,53 +14,57 @@ permissions:
1414 actions : read
1515
1616jobs :
17- pull-request-data :
17+ deployment-metadata :
1818 if : ${{ github.event.workflow_run.conclusion == 'success' }}
1919 runs-on : ubuntu-latest
2020 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 }}
2425 steps :
25- - name : Download PR data
26+ - name : Download deployment metadata
2627 env :
2728 GH_TOKEN : ${{ github.token }}
2829 run : |
2930 gh run download ${{ github.event.workflow_run.id }} \
3031 --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
3435 run : |
3536 {
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)"
3941 } >> "${GITHUB_OUTPUT}"
4042
4143 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'
4446 runs-on : ubuntu-latest
4547 concurrency :
46- group : ${{ github.workflow }}-${{ needs.pull-request-data .outputs.number }}
48+ group : ${{ github.workflow }}-${{ needs.deployment-metadata .outputs.pr_number }}
4749 cancel-in-progress : true
4850 steps :
4951 - name : Create Deployment
5052 uses : actions/github-script@v7
5153 id : deployment
5254 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 }}
5557 with :
5658 result-encoding : string
5759 script : |
5860 const { owner, repo } = context.repo;
61+ const prNumber = process.env.PR_NUMBER;
62+ const environment = prNumber ? `docs-preview-${prNumber}` : 'docs-preview';
5963 const deployment = await github.rest.repos.createDeployment({
6064 owner,
6165 repo,
62- ref: process.env.PR_REF ,
63- environment: `docs-preview-${ process.env.PR_NUMBER}` ,
66+ environment ,
67+ ref: process.env.REF ,
6468 auto_merge: false,
6569 required_contexts: [],
6670 })
@@ -86,25 +90,27 @@ jobs:
8690
8791 - name : Upload to S3
8892 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 }}
9095 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
9297 aws cloudfront create-invalidation \
9398 --distribution-id EKT7LT5PM8RKS \
94- --paths "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER} " "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER }/*"
99+ --paths "${PATH_PREFIX} " "/${PATH_PREFIX }/*"
95100
96101 - name : Update deployment status
97102 uses : actions/github-script@v7
98103 if : always() && steps.deployment.outputs.result
99104 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 }}
101107 with :
102108 script : |
103109 await github.rest.repos.createDeploymentStatus({
104110 owner: context.repo.owner,
105111 repo: context.repo.repo,
106112 deployment_id: ${{ steps.deployment.outputs.result }},
107113 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 }`,
109115 log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
110116 })
0 commit comments