Skip to content

Commit

Permalink
Merge branch 'espressif:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
BlakeHansen130 authored Dec 16, 2024
2 parents 6f081d6 + eb32ae0 commit b498aaf
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy Hugo site
name: Deploy production

on:
# Run on pushes to the default branch
Expand All @@ -8,10 +8,9 @@ on:
# Allow manual runs from the Actions tab
workflow_dispatch:

# Set permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
# Set permissions of the GITHUB_TOKEN
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment
Expand Down Expand Up @@ -68,7 +67,7 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Invalidate cloudfront cache
- name: Invalidate CloudFront cache
uses: chetan/invalidate-cloudfront-action@v2
env:
PATHS: "/*"
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/pr-build-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build preview for PR

on:
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: read

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

jobs:
build-preview:
runs-on: ubuntu-latest

steps:
- name: Install Hugo CLI
env:
HUGO_VERSION: 0.135.0
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Check out repo
uses: actions/checkout@v4
with:
submodules: recursive

- name: Build website with Hugo
env:
# For maximum backward compatibility with Hugo modules
HUGO_ENVIRONMENT: preview
HUGO_ENV: preview
run: |
hugo \
--baseURL ${{ env.HUGO_BASEURL }} \
--gc \
--minify
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: public-folder
path: ./public

- 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
83 changes: 83 additions & 0 deletions .github/workflows/pr-deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Deploy preview for PR

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

permissions:
contents: read
id-token: write
pull-requests: write

concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: false

env:
HUGO_BASEURL: "https://preview-developer.espressif.com/"

jobs:
deploy-preview:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- 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
with:
args: --follow-symlinks --delete --cache-control no-cache
env:
AWS_S3_BUCKET: ${{ secrets.PREVIEW_AWS_BUCKET_NAME }}
SOURCE_DIR: './public'
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 }}

- name: Post Preview Link to PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: ${{ env.PR_NUMBER }},
owner: context.repo.owner,
repo: context.repo.repo,
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${{ env.PR_NUMBER }}/*"
DISTRIBUTION: ${{ secrets.PREVIEW_CLOUDFRONT_DISTRIBUTION }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
31 changes: 31 additions & 0 deletions .github/workflows/pr-remove-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Remove preview for PR

on:
pull_request:
types:
- closed

jobs:
remove-preview:
name: Remove preview for PR
runs-on: ubuntu-latest

steps:
# Remove the PR-specific folder from S3
- name: Remove PR-specific subdirectory from S3
run: |
echo "Cleaning up preview folder for PR #${{ github.event.pull_request.number }}"
aws s3 rm "s3://${{ secrets.PREVIEW_AWS_BUCKET_NAME }}/pr${{ github.event.pull_request.number }}" --recursive
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Invalidate CloudFront cache for PR
uses: chetan/invalidate-cloudfront-action@v2
env:
PATHS: "/pr-${{ github.event.pull_request.number }}/*"
DISTRIBUTION: ${{ secrets.PREVIEW_CLOUDFRONT_DISTRIBUTION }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
12 changes: 6 additions & 6 deletions config/_default/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# Refer to the theme docs for more details about each of these parameters.
# https://blowfish.page/docs/getting-started/

theme = "blowfish"
baseURL = "https://developer.espressif.com"
baseURL = "https://preview-developer.espressif.com/"
languageCode = "en"
defaultContentLanguage = "en"
title = "Espressif Developer Portal Preview"
theme = "blowfish"

# Keep English on top level
defaultContentLanguageInSubdir = false
Expand All @@ -14,10 +16,8 @@ defaultContentLanguageInSubdir = false
enableRobotsTXT = true
summaryLength = 0

buildDrafts = false
buildFuture = false

googleAnalytics = "G-K9NTMXPGN3"
buildDrafts = true
buildFuture = true

[pagination]
pagerSize = 30
Expand Down
13 changes: 13 additions & 0 deletions config/production/hugo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# -- Site Configuration --
# Refer to the theme docs for more details about each of these parameters.
# https://blowfish.page/docs/getting-started/

baseURL = "https://developer.espressif.com/"
title = "Espressif Developer Portal"

buildDrafts = false
buildFuture = false

[services]
[services.googleAnalytics]
id = "G-K9NTMXPGN3"
9 changes: 0 additions & 9 deletions hugo.toml

This file was deleted.

0 comments on commit b498aaf

Please sign in to comment.