From a787bd71ab1cc73a6bed18500a9980d894712e63 Mon Sep 17 00:00:00 2001 From: Nat Hillard <72811320+NatHillardUSDS@users.noreply.github.com> Date: Tue, 27 Jul 2021 12:37:17 -0400 Subject: [PATCH] Merges to main don't get posted to main && it should be clearer how branches are deployed (#415) * fixes #319 - merges to main still don't get posted to /main , and #362 It should be clearer how branches are deployed -- move to using 'pull_request' instead of 'push' (we can't push to master directly anyhow), and run on 'closed'; also add comment on PR itself * updating to add subsequent pushes to the same PR --- .github/workflows/build_deploy.yml | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_deploy.yml b/.github/workflows/build_deploy.yml index da8ac748..0c72e67b 100644 --- a/.github/workflows/build_deploy.yml +++ b/.github/workflows/build_deploy.yml @@ -6,12 +6,15 @@ name: GH Pages deploy on: - push: + pull_request: + types: [ closed, opened ] branches: [main] paths: - 'client/**/*' - pull_request: - branches: [main] + push: + branches: + - '*' # Run on all updates to PR branches + - '!main' # Do not run on pushes to main jobs: build: runs-on: ubuntu-latest @@ -30,7 +33,7 @@ jobs: # If this is just a PR branch, put content in a hash directory. Otherwise, put it in "main" # 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 + if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true run: | echo "DESTINATION_FOLDER=main" >> $GITHUB_ENV - name: Set DESTINATION_FOLDER for branch @@ -72,7 +75,7 @@ jobs: path: ./public # If this is just a PR branch, put content in a hash directory. Otherwise, put it in "main" - name: Set DESTINATION_FOLDER for main - if: github.event.pull_request.merged == true + if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true run: | echo "DESTINATION_FOLDER=main" >> $GITHUB_ENV - name: Set DESTINATION_FOLDER for branch @@ -82,7 +85,6 @@ jobs: - 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 @@ -95,3 +97,18 @@ jobs: aws-region: us-east-1 - name: Deploy to Geoplatform AWS run: aws s3 sync ./public/ s3://usds-geoplatform-justice40-website/justice40-tool/${{env.DESTINATION_FOLDER}} --delete + - name: Update PR with deployed URL + uses: mshick/add-pr-comment@v1 + if: github.event_name == 'pull_request' && github.event.action == 'opened' || github.event_name == 'push' # Only comment if the PR has been opened or a push has updated it + with: + message: | + **🚢 PR Deployed! 🚢** + Find it here: https://d2zjid6n5ja2pt.cloudfront.net/justice40-tool/${{env.DESTINATION_FOLDER}}/en/cejst/ ! + repo-token: ${{ secrets.GITHUB_TOKEN }} + repo-token-user-login: 'github-actions[bot]' # The user.login for temporary GitHub tokens + allow-repeats: false # This is the default + - name: Printing deployment URLs + run: | + echo "Github pages: https://usds.github.io/justice40-tool/$DESTINATION_FOLDER/en" + echo "Standard S3 bucket version (http only) : http://usds-geoplatform-justice40-website.s3-website-us-east-1.amazonaws.com/justice40-tool/$DESTINATION_FOLDER/en" + echo "Cloudfront https: https://d2zjid6n5ja2pt.cloudfront.net/justice40-tool/$DESTINATION_FOLDER/en" \ No newline at end of file