Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .github/workflows/pr-build-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
permissions:
contents: read

env:
HUGO_BASEURL: "https://preview-developer.espressif.com/pr${{ github.event.pull_request.number }}/"

jobs:
build-preview:
runs-on: ubuntu-latest
Expand All @@ -31,11 +34,35 @@ jobs:
HUGO_ENV: preview
run: |
hugo \
--baseURL ${{ env.HUGO_BASEURL }} \
--gc \
--minify

- name: Print preview link to PR
run: |
echo "Preview link ${{ env.HUGO_BASEURL }}"

- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: public-folder
path: ./public

- name: Publish index.xml
if: success()
run: |
if [ -f ./public/index.xml ]; then
echo "Contents of index.xml:"
cat ./public/index.xml
else
echo "index.xml not found in ./public"
fi

- name: Create PR number file
run: echo "${{ github.event.pull_request.number }}" > pr-num.txt

- name: Upload PR number artifact
uses: actions/upload-artifact@v4
with:
name: pr-num
path: pr-num.txt
35 changes: 26 additions & 9 deletions .github/workflows/pr-deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Deploy preview for PR

on:
workflow_run:
workflows: ["Build preview for PR"]
workflows:
- "Build preview for PR"
types:
- completed

Expand All @@ -16,7 +17,7 @@ concurrency:
cancel-in-progress: false

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

jobs:
deploy-preview:
Expand All @@ -26,11 +27,27 @@ jobs:
github.event.workflow_run.conclusion == 'success'

steps:
- name: Download artifacts
uses: actions/download-artifact@v3
- name: Download artifacts (PR number file)
uses: actions/download-artifact@v4
with:
name: pr-num
path: ./
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Read PR number from file
id: read-pr-num
run: |
echo "PR_NUMBER=$(cat pr-num.txt)" >> $GITHUB_ENV
echo ${{ env.PR_NUMBER }}

- name: Download artifacts (Public folder)
uses: actions/download-artifact@v4
with:
name: public-folder
path: ./public
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy to AWS S3 PR-specific subdirectory
uses: jakejarvis/s3-sync-action@master
Expand All @@ -39,7 +56,7 @@ jobs:
env:
AWS_S3_BUCKET: ${{ secrets.PREVIEW_AWS_BUCKET_NAME }}
SOURCE_DIR: './public'
DEST_DIR: "pr${{ github.event.workflow_run.pull_requests[0].number }}"
DEST_DIR: "pr${{ env.PR_NUMBER }}"
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand All @@ -50,16 +67,16 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.event.workflow_run.pull_requests[0].number,
issue_number: ${{ env.PR_NUMBER }},
owner: context.repo.owner,
repo: context.repo.repo,
body: `🎉 A preview of this PR is available at: ${{ env.HUGO_BASEURL }}`
})
body: `🎉 A preview for this PR is available at: ${{ env.HUGO_BASEURL }}pr${{ env.PR_NUMBER }}/`
});

- name: Invalidate CloudFront cache for PR
uses: chetan/invalidate-cloudfront-action@v2
env:
PATHS: "/pr-${{ github.event.workflow_run.pull_requests[0].number }}/*"
PATHS: "/pr${{ env.PR_NUMBER }}/*"
DISTRIBUTION: ${{ secrets.PREVIEW_CLOUDFRONT_DISTRIBUTION }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down
6 changes: 6 additions & 0 deletions content/blog/test-preview-workflows/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "Test Preview Workflows"
date: 2024-12-10T18:20:42+08:00
---

This page is added to test how GitHub actions deploy and remove previews for PRs to the Espressif Developer Portal.