11name : Deploy preview for PR
22
33on :
4- pull_request :
5- types : [opened, synchronize, reopened ]
6- # Allow manual runs from the Actions tab
7- workflow_dispatch :
4+ workflow_run :
5+ workflows : ["Build preview for PR" ]
6+ types :
7+ - completed
88
9- # Set permissions of the GITHUB_TOKEN
109permissions :
1110 contents : read
1211 id-token : write
1312 pull-requests : write
1413
15- # Allow only one concurrent deployment
1614concurrency :
17- group : ${{ github.workflow }}-${{ github.ref }}
15+ group : ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}
1816 cancel-in-progress : false
1917
20- # Define environment variables
2118env :
22- HUGO_BASEURL : " https://preview-developer.espressif.com/pr${{ github.event.pull_request.number }}/"
23-
24- # Default to bash
25- defaults :
26- run :
27- shell : bash
19+ HUGO_BASEURL : " https://preview-developer.espressif.com/pr${{ github.event.workflow_run.pull_requests[0].number }}/"
2820
2921jobs :
30- build-and- deploy-preview :
22+ deploy-preview :
3123 runs-on : ubuntu-latest
24+ if : >
25+ github.event.workflow_run.event == 'pull_request' &&
26+ github.event.workflow_run.conclusion == 'success'
3227
3328 steps :
34-
35- - name : Install Hugo CLI
36- env :
37- HUGO_VERSION : 0.135.0
38- run : |
39- wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
40- && sudo dpkg -i ${{ runner.temp }}/hugo.deb
41-
42- - name : Check out repo
43- uses : actions/checkout@v4
29+ - name : Download artifacts
30+ uses : actions/download-artifact@v3
4431 with :
45- submodules : recursive
46-
47- - name : Build website with Hugo
48- env :
49- # For maximum backward compatibility with Hugo modules
50- HUGO_ENVIRONMENT : preview
51- HUGO_ENV : preview
52- run : |
53- hugo \
54- --gc \
55- --minify
32+ name : public-folder
33+ path : ./public
5634
5735 - name : Deploy to AWS S3 PR-specific subdirectory
5836 uses : jakejarvis/s3-sync-action@master
@@ -61,28 +39,27 @@ jobs:
6139 env :
6240 AWS_S3_BUCKET : ${{ secrets.PREVIEW_AWS_BUCKET_NAME }}
6341 SOURCE_DIR : ' ./public'
64- # Subdirectory for the PR
65- DEST_DIR : " pr${{ github.event.pull_request.number }}"
42+ DEST_DIR : " pr${{ github.event.workflow_run.pull_requests[0].number }}"
6643 AWS_REGION : ${{ secrets.AWS_REGION }}
6744 AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
6845 AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
6946
7047 - name : Post Preview Link to PR
7148 uses : actions/github-script@v7
7249 with :
73- github-token : ${{secrets.GITHUB_TOKEN}}
50+ github-token : ${{ secrets.GITHUB_TOKEN }}
7451 script : |
7552 github.rest.issues.createComment({
76- issue_number: context.issue .number,
53+ issue_number: context.event.workflow_run.pull_requests[0] .number,
7754 owner: context.repo.owner,
7855 repo: context.repo.repo,
79- body: `🎉 A preview of this PR is available at: ${{ env.HUGO_BASEURL }} `
56+ body: `🎉 A preview of this PR is available at: ${{ env.HUGO_BASEURL }}`
8057 })
8158
8259 - name : Invalidate CloudFront cache for PR
8360 uses : chetan/invalidate-cloudfront-action@v2
8461 env :
85- PATHS : " /pr-${{ github.event.pull_request .number }}/*"
62+ PATHS : " /pr-${{ github.event.workflow_run.pull_requests[0] .number }}/*"
8663 DISTRIBUTION : ${{ secrets.PREVIEW_CLOUDFRONT_DISTRIBUTION }}
8764 AWS_REGION : ${{ secrets.AWS_REGION }}
8865 AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
0 commit comments