From 6f4087d2475f3b5c5ae555612f27123b2dec2a03 Mon Sep 17 00:00:00 2001 From: Nat Hillard <72811320+NatHillardUSDS@users.noreply.github.com> Date: Mon, 28 Jun 2021 10:59:08 -0400 Subject: [PATCH] Fix Github Actions deploy for merges to main Addresses part of #125 - merges to main now go to a path with a `main` prefix --- .github/workflows/build_deploy.yml | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_deploy.yml b/.github/workflows/build_deploy.yml index de06ca2e..23bb9608 100644 --- a/.github/workflows/build_deploy.yml +++ b/.github/workflows/build_deploy.yml @@ -27,11 +27,16 @@ jobs: uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - - name: Set GITHUB_SHA_SHORT - run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV # If this is just a PR branch, put content in a hash directory. Otherwise, put it in "main" - - name: Set DESTINATION_FOLDER - run: echo "DESTINATION_FOLDER=${{ github.event.pull_request.merged == 'true' && 'main' || env.GITHUB_SHA_SHORT }}" >> $GITHUB_ENV + # This variable is used by gatsby-config.js to set a prefixPath + - name: Set DESTINATION_FOLDER for main + if: ${{ github.event.pull_request.merged == true }} + run: | + echo "DESTINATION_FOLDER=main" >> $GITHUB_ENV + - name: Set DESTINATION_FOLDER for branch + if: ${{ github.event.pull_request.merged != true }} + run: | + echo "DESTINATION_FOLDER=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV - name: Install run: npm ci - name: Build @@ -65,11 +70,15 @@ jobs: with: name: J40Static path: ./public - - name: Set GITHUB_SHA_SHORT - run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV # If this is just a PR branch, put content in a hash directory. Otherwise, put it in "main" - - name: Set DESTINATION_FOLDER - run: echo "DESTINATION_FOLDER=${{ github.event.pull_request.merged == 'true' && 'main' || env.GITHUB_SHA_SHORT }}" >> $GITHUB_ENV + - name: Set DESTINATION_FOLDER for main + if: ${{ github.event.pull_request.merged == true }} + run: | + echo "DESTINATION_FOLDER=main" >> $GITHUB_ENV + - name: Set DESTINATION_FOLDER for branch + if: ${{ github.event.pull_request.merged != true }} + run: | + echo "DESTINATION_FOLDER=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV - name: Deploy to Github Pages uses: JamesIves/github-pages-deploy-action@4.1.0 with: @@ -77,6 +86,7 @@ jobs: BRANCH: gh-pages # The branch the action should deploy to. FOLDER: public # The folder the action should deploy. TARGET-FOLDER: ${{env.DESTINATION_FOLDER}} # If we're on a PR branch, merge to PR folder + CLEAN: true - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 with: