Skip to content

Commit eb32ae0

Browse files
authored
ci(preview): pass PR number to deploy-preview via artifacts (#361)
1 parent 760021a commit eb32ae0

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

.github/workflows/pr-build-preview.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@ jobs:
3838
--gc \
3939
--minify
4040
41-
- name: Print preview link to PR
42-
run: |
43-
echo "Preview link ${{ env.HUGO_BASEURL }}"
44-
4541
- name: Upload artifacts
4642
uses: actions/upload-artifact@v4
4743
with:
4844
name: public-folder
4945
path: ./public
46+
47+
- name: Create PR number file
48+
run: echo "${{ github.event.pull_request.number }}" > pr-num.txt
49+
50+
- name: Upload PR number artifact
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: pr-num
54+
path: pr-num.txt

.github/workflows/pr-deploy-preview.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ concurrency:
1717
cancel-in-progress: false
1818

1919
env:
20-
HUGO_BASEURL: "https://preview-developer.espressif.com/pr${{ github.event.workflow_run.pull_requests[0].number }}/"
20+
HUGO_BASEURL: "https://preview-developer.espressif.com/"
2121

2222
jobs:
2323
deploy-preview:
@@ -27,7 +27,21 @@ jobs:
2727
github.event.workflow_run.conclusion == 'success'
2828
2929
steps:
30-
- name: Download artifacts
30+
- name: Download artifacts (PR number file)
31+
uses: actions/download-artifact@v4
32+
with:
33+
name: pr-num
34+
path: ./
35+
run-id: ${{ github.event.workflow_run.id }}
36+
github-token: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Read PR number from file
39+
id: read-pr-num
40+
run: |
41+
echo "PR_NUMBER=$(cat pr-num.txt)" >> $GITHUB_ENV
42+
echo ${{ env.PR_NUMBER }}
43+
44+
- name: Download artifacts (Public folder)
3145
uses: actions/download-artifact@v4
3246
with:
3347
name: public-folder
@@ -42,7 +56,7 @@ jobs:
4256
env:
4357
AWS_S3_BUCKET: ${{ secrets.PREVIEW_AWS_BUCKET_NAME }}
4458
SOURCE_DIR: './public'
45-
DEST_DIR: "pr${{ github.event.workflow_run.pull_requests[0].number }}"
59+
DEST_DIR: "pr${{ env.PR_NUMBER }}"
4660
AWS_REGION: ${{ secrets.AWS_REGION }}
4761
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
4862
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
@@ -53,16 +67,16 @@ jobs:
5367
github-token: ${{ secrets.GITHUB_TOKEN }}
5468
script: |
5569
github.rest.issues.createComment({
56-
issue_number: ${{ github.event.workflow_run.pull_requests[0].number }},
70+
issue_number: ${{ env.PR_NUMBER }},
5771
owner: context.repo.owner,
5872
repo: context.repo.repo,
59-
body: `🎉 A preview for this PR is available at: ${{ env.HUGO_BASEURL }}`
73+
body: `🎉 A preview for this PR is available at: ${{ env.HUGO_BASEURL }}pr${{ env.PR_NUMBER }}/`
6074
});
6175
6276
- name: Invalidate CloudFront cache for PR
6377
uses: chetan/invalidate-cloudfront-action@v2
6478
env:
65-
PATHS: "/pr-${{ github.event.workflow_run.pull_requests[0].number }}/*"
79+
PATHS: "/pr${{ env.PR_NUMBER }}/*"
6680
DISTRIBUTION: ${{ secrets.PREVIEW_CLOUDFRONT_DISTRIBUTION }}
6781
AWS_REGION: ${{ secrets.AWS_REGION }}
6882
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}

0 commit comments

Comments
 (0)