Skip to content

Hugo Upgrade

Hugo Upgrade #82

Workflow file for this run

name: Deploy Hugo site
on:
push:
branches:
- main
pull_request:
permissions:
id-token: write
contents: read
pull-requests: write
defaults:
run:
shell: bash
jobs:
deploy-infra:
name: Deploy Terraform Infrastructure as Code
runs-on: ubuntu-latest
outputs:
distribution: ${{ steps.terraform.outputs.DID }}
bucket: ${{ steps.terraform.outputs.URL }}
baseurl: ${{ steps.terraform.outputs.BASE }}
defaults:
run:
working-directory: terraform/
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE }}
aws-region: us-east-1
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.GH_APP_ID }}
private_key: ${{ secrets.GH_PRIVATE_KEY }}
installation_retrieval_mode: id
installation_retrieval_payload: ${{ secrets.GH_INSTALLATION_ID }}
- name: Terraform Format
id: fmt
run: terraform fmt -no-color -check
continue-on-error: true
- name: Terraform Init
id: init
run: terraform init -no-color
- name: Terraform Validate
id: validate
run: terraform validate -no-color
- name: Terraform Plan
id: plan
run: terraform plan -out .planfile
- name: Post PR comment
if: github.event_name == 'pull_request'
uses: borchero/terraform-plan-comment@v2
with:
token: ${{ steps.generate_token.outputs.token }}
planfile: .planfile
working-directory: terraform/
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -no-color -auto-approve .planfile
- name: Output Terraform values
id: terraform
run: |
echo "DID=$(terraform output -raw cloudFrontDistributionID)" >> "$GITHUB_OUTPUT"
echo "URL=$(terraform output -raw URL)" >> "$GITHUB_OUTPUT"
echo "BASE=$(terraform output -raw hostname)" >> "$GITHUB_OUTPUT"
build-hugo:
name: Generate Hugo site
runs-on: ubuntu-latest
needs: deploy-infra
env:
HUGO_ENV: production
HUGO_CACHEDIR: /tmp/hugo_cache
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Setup Dart Sass
run: sudo snap install dart-sass && sudo snap alias dart-sass sass
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: 'latest'
extended: true
- run: npm ci
- uses: actions/cache@v4
with:
path: ${{ env.HUGO_CACHEDIR }}
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-hugomod-
- name: Hugo Build
run: hugo build --gc --cleanDestinationDir --enableGitInfo --minify --baseURL https://${{ needs.deploy-infra.outputs.baseurl }}/
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GITHUB_ACTIONS_ROLE }}
aws-region: us-east-1
- name: Assume IAM Role
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_TERRAFORM_DEPLOY_ROLE }}
role-chaining: true
aws-region: us-east-1
# - name: Update Hugo Deployment
# run: |
# sed -i "s@CLOUDFRONT_DISTRIBUTION_ID@${{ needs.deploy-infra.outputs.distribution }}@g" config/production/deployment.yaml
# sed -i "s@S3_BUCKET_URL@${{ needs.deploy-infra.outputs.bucket }}@g" config/production/deployment.yaml
# - name: Hugo Deploy (dry-run)
# if: github.event_name == 'pull_request'
# run: hugo deploy --dryRun --target AWS
- name: Hugo Deploy
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# run: hugo deploy --maxDeletes -1 --target AWS --logLevel info
uses: reggionick/s3-deploy@v4
with:
folder: public
dist-id: ${{ needs.deploy-infra.outputs.distribution }}
bucket: ${{ needs.deploy-infra.outputs.bucket }}
bucket-region: us-east-1
delete-removed: true
cache: 3600
private: true
files-to-include: '{.*/**,**}'