| | |
| | | name: AWS DEPLOY CI |
| | | on: # change to `on:` to turn on |
| | | workflow_dispatch: |
| | | branches: |
| | | - production # change to 'main' to automate |
| | | push: |
| | | paths: |
| | | # - exampleSite/content/**/* |
| | |
| | | jobs: |
| | | build: |
| | | # In this phase, the code is pulled from main and the site rendered in Hugo. The built site is stored as an artifact for other stages. # deploy: |
| | | runs-on: ubuntu-20.04 |
| | | runs-on: ubuntu-latest |
| | | concurrency: |
| | | group: ${{ github.workflow }}-${{ github.ref }} |
| | | steps: |
| | | - uses: actions/checkout@v3 |
| | | - uses: actions/checkout@v4 |
| | | with: |
| | | submodules: true # Fetch Hugo themes (true OR recursive) |
| | | fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod |
| | | |
| | | - name: Setup Hugo |
| | | uses: peaceiris/actions-hugo@v2 |
| | | uses: peaceiris/actions-hugo@v3 |
| | | with: |
| | | hugo-version: 'latest' |
| | | extended: true |
| | |
| | | run: hugo -e "production" -d "dist" -s "exampleSite" --minify |
| | | # If build succeeds, store the dist/ dir as an artifact to be used in subsequent phases. |
| | | - name: Upload output public dir as artifact |
| | | uses: actions/upload-artifact@v1 |
| | | uses: actions/upload-artifact@v4 |
| | | with: |
| | | name: public |
| | | path: dist/ |
| | | publish: |
| | | # In the publish phase, the site is pushed up to a different branch which only stores the dist/ folder ("site" branch) and is also delta synchronized to the S3 bucket. CloudFront invalidation happens last. |
| | | runs-on: ubuntu-20.04 |
| | | runs-on: ubuntu-latest |
| | | needs: build |
| | | steps: |
| | | # Check out the site branch this time since we have to ultimately commit those changes there. |
| | | - name: Checkout site branch |
| | | uses: actions/checkout@v3 |
| | | uses: actions/checkout@v4 |
| | | with: |
| | | submodules: true |
| | | fetch-depth: 0 |
| | | ref: ${{ env.SITE-BRANCH }} |
| | | # Download the artifact containing the newly built site. This overwrites the dist/ dir from the check out above. |
| | | - name: Download artifact from build stage |
| | | uses: actions/download-artifact@v1 |
| | | uses: actions/download-artifact@v4 |
| | | with: |
| | | name: public |
| | | # Add all the files/changes in dist/ that were pulled down from the build stage and then commit them. |
| | |
| | | git config --local user.name "GitHub Action" |
| | | git add -A dist/ |
| | | commit_message=$(git commit -m "Publish generated Hugo site." -a | tr -d '\n' || true) |
| | | echo "commit_message=$commit_message >> $GITHUB_OUTPUT" |
| | | echo "commit_message=$commit_message" >> $GITHUB_OUTPUT |
| | | # Checks if previous stage had any valid commit. |
| | | - name: Nothing to commit |
| | | id: nothing_committed |
| | |
| | | # Push those changes back to the site branch. |
| | | - name: Push to site branch |
| | | if: steps.nothing_committed.conclusion == 'skipped' |
| | | uses: ad-m/github-push-action@master |
| | | uses: ad-m/github-push-action@v1.0.0 |
| | | with: |
| | | github_token: ${{ secrets.GITHUB_TOKEN }} |
| | | branch: ${{ env.SITE-BRANCH }} |
| | | # Store the AWS credentials on the runner. |
| | | - name: Configure AWS credentials |
| | | if: steps.nothing_committed.conclusion == 'skipped' |
| | | uses: aws-actions/configure-aws-credentials@v1-node16 |
| | | uses: aws-actions/configure-aws-credentials@v4 |
| | | with: |
| | | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| | | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| | |
| | | # Use the aws cli tool to perform a glob invalidation of the entire site against CloudFront. |
| | | - name: Invalidate cache on CloudFront |
| | | if: steps.nothing_committed.conclusion == 'skipped' |
| | | run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRO_ID }} --paths "/*" |
| | | run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_DISTRO_ID }} --paths "/*" |