-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
6 changed files
with
142 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: Deploy preview for PR | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
# Allow manual runs from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Set permissions of the GITHUB_TOKEN | ||
permissions: | ||
contents: read | ||
id-token: write | ||
pull-requests: write | ||
|
||
# Allow only one concurrent deployment | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: false | ||
|
||
# Define environment variables | ||
env: | ||
HUGO_BASEURL: "https://preview-developer.espressif.com/pr${{ github.event.pull_request.number }}/" | ||
|
||
# Default to bash | ||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
build-and-deploy-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 \ | ||
--gc \ | ||
--minify | ||
- 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' | ||
# Subdirectory for the PR | ||
DEST_DIR: "pr${{ github.event.pull_request.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: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `🎉 A preview of this PR is available at: ${{ env.HUGO_BASEURL }} ` | ||
}) | ||
- 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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |