If you’re trying to implement CI/CD for a code repository that’s hosted on GitHub, then GitHub Actions are a great place to start.

Setting up Github Actions

It’s easy :)

Config for this blog

Can be found at https://github.com/brriann/homepage/blob/master/.github/workflows/deploy-to-aws.yml

name: Deploy to AWS
on: 
  workflow_dispatch:
  push:
    paths:
      - 'content/**'
    branches:
      - 'master'
  
jobs:
  Build-And-Deploy:
    name: Build and Deploy
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup Hugo
        env:
          HUGO_VERSION: 0.98.0
        run: |
          mkdir ~/hugo
          cd ~/hugo
          curl -L "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_Linux-64bit.tar.gz" --output hugo.tar.gz
          tar -xvzf hugo.tar.gz
          sudo mv hugo /usr/local/bin

      - name: Build
        run: hugo --minify

      - name: Deploy
        run: |
          aws s3 sync --delete ./public s3://${{ secrets.BUCKET_NAME }}
          aws cloudfront create-invalidation --distribution-id ${{ secrets.DISTRIBUTION_ID }} --paths /*
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_DEFAULT_REGION: 'us-west-2'

References

https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions

https://docs.github.com/en/actions/learn-github-actions/essential-features-of-github-actions

https://www.yellowduck.be/posts/deploy-hugo-site-with-github-actions/

https://swharden.com/blog/2022-03-20-github-actions-hugo/

aws  cicd  devops  git