Skip to content

Commit ad6c739

Browse files
committed
Add concurrency to deploy job
1 parent f8f88ba commit ad6c739

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

.github/workflows/preview-deploy.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ permissions:
1414
actions: read
1515

1616
jobs:
17-
deploy:
17+
pull-request-data:
1818
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1919
runs-on: ubuntu-latest
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 }}
2024
steps:
2125
- name: Download PR data
2226
env:
@@ -33,14 +37,21 @@ jobs:
3337
echo "ref=$(jq -r '.ref' pull_request.json)"
3438
echo "any_changed=$(jq -r '.any_changed' pull_request.json)"
3539
} >> "${GITHUB_OUTPUT}"
36-
40+
41+
deploy:
42+
needs: pull-request-data
43+
runs-on: ubuntu-latest
44+
concurrency:
45+
group: ${{ github.workflow }}-${{ needs.pull-request-data.outputs.number }}
46+
cancel-in-progress: true
47+
steps:
3748
- name: Create Deployment
38-
if: steps.pull_request.outputs.any_changed == 'true'
49+
if: needs.pull-request-data.outputs.any_changed == 'true'
3950
uses: actions/github-script@v7
4051
id: deployment
4152
env:
42-
PR_NUMBER: ${{ steps.pull_request.outputs.number }}
43-
PR_REF: ${{ steps.pull_request.outputs.ref }}
53+
PR_NUMBER: ${{ needs.pull-request-data.outputs.number }}
54+
PR_REF: ${{ needs.pull-request-data.outputs.ref }}
4455
with:
4556
result-encoding: string
4657
script: |
@@ -63,7 +74,7 @@ jobs:
6374
return deployment.data.id
6475
6576
- name: Download docs
66-
if: steps.pull_request.outputs.any_changed == 'true'
77+
if: needs.pull-request-data.outputs.any_changed == 'true'
6778
env:
6879
GH_TOKEN: ${{ github.token }}
6980
run: |
@@ -73,12 +84,12 @@ jobs:
7384
--dir html
7485
7586
- uses: elastic/docs-builder/.github/actions/aws-auth@main
76-
if: steps.pull_request.outputs.any_changed == 'true'
87+
if: needs.pull-request-data.outputs.any_changed == 'true'
7788

7889
- name: Upload to S3
79-
if: steps.pull_request.outputs.any_changed == 'true'
90+
if: needs.pull-request-data.outputs.any_changed == 'true'
8091
env:
81-
PR_NUMBER: ${{ steps.pull_request.outputs.number }}
92+
PR_NUMBER: ${{ needs.pull-request-data.outputs.number }}
8293
run: |
8394
aws s3 sync ./html "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --delete
8495
aws cloudfront create-invalidation --distribution-id EKT7LT5PM8RKS --paths "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}/*"
@@ -93,6 +104,6 @@ jobs:
93104
repo: context.repo.repo,
94105
deployment_id: ${{ steps.deployment.outputs.result }},
95106
state: "${{ job.status == 'success' && 'success' || 'failure' }}",
96-
environment_url: `https://docs-v3-preview.elastic.dev/${context.repo.owner}/${context.repo.repo}/pull/${{ steps.pull_request.outputs.number}}`,
107+
environment_url: `https://docs-v3-preview.elastic.dev/${context.repo.owner}/${context.repo.repo}/pull/${{ needs.pull-request-data.outputs.number}}`,
97108
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
98109
})

0 commit comments

Comments
 (0)