Skip to content

Commit 4cb27a8

Browse files
committed
Feat/add workflow preview prs (#348)
* fix: improve comments and name for deploy workflow * feat: clean up and improve config files * feat: add workflow to preview prs * feat: add workflow to remove preview files when pr closed
1 parent 981e011 commit 4cb27a8

File tree

6 files changed

+142
-19
lines changed

6 files changed

+142
-19
lines changed

.github/workflows/deploy-hugo-site.yml renamed to .github/workflows/deploy-production.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy Hugo site
1+
name: Deploy production
22

33
on:
44
# Run on pushes to the default branch
@@ -8,10 +8,9 @@ on:
88
# Allow manual runs from the Actions tab
99
workflow_dispatch:
1010

11-
# Set permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
11+
# Set permissions of the GITHUB_TOKEN
1212
permissions:
1313
contents: read
14-
pages: write
1514
id-token: write
1615

1716
# Allow only one concurrent deployment
@@ -68,7 +67,7 @@ jobs:
6867
runs-on: ubuntu-latest
6968
steps:
7069

71-
- name: Invalidate cloudfront cache
70+
- name: Invalidate CloudFront cache
7271
uses: chetan/invalidate-cloudfront-action@v2
7372
env:
7473
PATHS: "/*"
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Deploy preview for PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
# Allow manual runs from the Actions tab
7+
workflow_dispatch:
8+
9+
# Set permissions of the GITHUB_TOKEN
10+
permissions:
11+
contents: read
12+
id-token: write
13+
pull-requests: write
14+
15+
# Allow only one concurrent deployment
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: false
19+
20+
# Define environment variables
21+
env:
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
28+
29+
jobs:
30+
build-and-deploy-preview:
31+
runs-on: ubuntu-latest
32+
33+
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
44+
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
56+
57+
- name: Deploy to AWS S3 PR-specific subdirectory
58+
uses: jakejarvis/s3-sync-action@master
59+
with:
60+
args: --follow-symlinks --delete --cache-control no-cache
61+
env:
62+
AWS_S3_BUCKET: ${{ secrets.PREVIEW_AWS_BUCKET_NAME }}
63+
SOURCE_DIR: './public'
64+
# Subdirectory for the PR
65+
DEST_DIR: "pr${{ github.event.pull_request.number }}"
66+
AWS_REGION: ${{ secrets.AWS_REGION }}
67+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
68+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
69+
70+
- name: Post Preview Link to PR
71+
uses: actions/github-script@v7
72+
with:
73+
github-token: ${{secrets.GITHUB_TOKEN}}
74+
script: |
75+
github.rest.issues.createComment({
76+
issue_number: context.issue.number,
77+
owner: context.repo.owner,
78+
repo: context.repo.repo,
79+
body: `🎉 A preview of this PR is available at: ${{ env.HUGO_BASEURL }} `
80+
})
81+
82+
- name: Invalidate CloudFront cache for PR
83+
uses: chetan/invalidate-cloudfront-action@v2
84+
env:
85+
PATHS: "/pr-${{ github.event.pull_request.number }}/*"
86+
DISTRIBUTION: ${{ secrets.PREVIEW_CLOUDFRONT_DISTRIBUTION }}
87+
AWS_REGION: ${{ secrets.AWS_REGION }}
88+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
89+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Remove preview for PR
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
jobs:
9+
remove-preview:
10+
name: Remove preview for PR
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
# Remove the PR-specific folder from S3
15+
- name: Remove PR-specific subdirectory from S3
16+
run: |
17+
echo "Cleaning up preview folder for PR #${{ github.event.pull_request.number }}"
18+
aws s3 rm "s3://${{ secrets.PREVIEW_AWS_BUCKET_NAME }}/pr${{ github.event.pull_request.number }}" --recursive
19+
env:
20+
AWS_REGION: ${{ secrets.AWS_REGION }}
21+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
22+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
23+
24+
- name: Invalidate CloudFront cache for PR
25+
uses: chetan/invalidate-cloudfront-action@v2
26+
env:
27+
PATHS: "/pr-${{ github.event.pull_request.number }}/*"
28+
DISTRIBUTION: ${{ secrets.PREVIEW_CLOUDFRONT_DISTRIBUTION }}
29+
AWS_REGION: ${{ secrets.AWS_REGION }}
30+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
31+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

config/_default/hugo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# Refer to the theme docs for more details about each of these parameters.
33
# https://blowfish.page/docs/getting-started/
44

5-
theme = "blowfish"
6-
baseURL = "https://developer.espressif.com"
5+
baseURL = "https://preview-developer.espressif.com/"
6+
languageCode = "en"
77
defaultContentLanguage = "en"
8+
title = "Espressif Developer Portal Preview"
9+
theme = "blowfish"
810

911
# Keep English on top level
1012
defaultContentLanguageInSubdir = false
@@ -14,10 +16,8 @@ defaultContentLanguageInSubdir = false
1416
enableRobotsTXT = true
1517
summaryLength = 0
1618

17-
buildDrafts = false
18-
buildFuture = false
19-
20-
googleAnalytics = "G-K9NTMXPGN3"
19+
buildDrafts = true
20+
buildFuture = true
2121

2222
[pagination]
2323
pagerSize = 30

config/production/hugo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -- Site Configuration --
2+
# Refer to the theme docs for more details about each of these parameters.
3+
# https://blowfish.page/docs/getting-started/
4+
5+
baseURL = "https://developer.espressif.com/"
6+
title = "Espressif Developer Portal"
7+
8+
buildDrafts = false
9+
buildFuture = false
10+
11+
[services]
12+
[services.googleAnalytics]
13+
id = "G-K9NTMXPGN3"

hugo.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)