From 9ea0f946ebd13b844666b56b1a4ccb83b7aaee92 Mon Sep 17 00:00:00 2001 From: Nat Hillard <72811320+NatHillardUSDS@users.noreply.github.com> Date: Mon, 14 Jun 2021 10:42:09 -0400 Subject: [PATCH] Adding SHA (for PRs)/ Main (for main) to URL (#121) * Fixes #90 - adds a GHA SHA to PR branches and 'main' for merges to main --- .github/workflows/build_deploy.yml | 13 ++++++++++++- client/gatsby-config.js | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_deploy.yml b/.github/workflows/build_deploy.yml index e710aa1d..81ea3f5f 100644 --- a/.github/workflows/build_deploy.yml +++ b/.github/workflows/build_deploy.yml @@ -27,6 +27,11 @@ 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 - name: Install run: npm ci - name: Build @@ -59,12 +64,18 @@ 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: Deploy to Github Pages uses: JamesIves/github-pages-deploy-action@4.1.0 with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 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 - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 with: @@ -72,4 +83,4 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: us-east-1 - name: Deploy to Geoplatform AWS - run: aws s3 sync ./public/ s3://usds-geoplatform-justice40-website/justice40-tool --delete + run: aws s3 sync ./public/ s3://usds-geoplatform-justice40-website/justice40-tool/${{env.DESTINATION_FOLDER}} --delete diff --git a/client/gatsby-config.js b/client/gatsby-config.js index 12c6480c..cae5a4d5 100644 --- a/client/gatsby-config.js +++ b/client/gatsby-config.js @@ -2,7 +2,7 @@ module.exports = { siteMetadata: { title: 'Justice40', }, - pathPrefix: '/justice40-tool', + pathPrefix: `/justice40-tool/${process.env.DESTINATION_FOLDER}`, plugins: [ { resolve: 'gatsby-plugin-sass',