From d4484f1cf175d376dd82c0c7eb2383c22b1a3716 Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Mon, 16 Oct 2023 13:43:58 -0400 Subject: [PATCH] build: Fixed GH Action build issues - Bumped three action versions due to node 12 deprecation - actions/checkout@v2 to actions/checkout@v3 - actions/setup-node@v2 to actions/setup-node@v3 - actions/checkout@v2 to actions/checkout@v3 - Converted s3-deploy to use concord-consortium/s3-deploy-action@v1 --- .github/workflows/release-production.yml | 24 ++++++ .github/workflows/release-staging.yml | 24 ++++++ .github/workflows/researcher-reports.yml | 46 ++++++----- researcher-reports/README.md | 10 +-- researcher-reports/s3_deploy.sh | 100 ----------------------- researcher-reports/s3_website.yml | 25 ------ researcher-reports/webpack.config.js | 9 ++ 7 files changed, 86 insertions(+), 152 deletions(-) create mode 100644 .github/workflows/release-production.yml create mode 100644 .github/workflows/release-staging.yml delete mode 100755 researcher-reports/s3_deploy.sh delete mode 100644 researcher-reports/s3_website.yml diff --git a/.github/workflows/release-production.yml b/.github/workflows/release-production.yml new file mode 100644 index 0000000..4f1ff05 --- /dev/null +++ b/.github/workflows/release-production.yml @@ -0,0 +1,24 @@ +name: Release Production +on: + workflow_dispatch: + inputs: + version: + description: The git tag for the version to use for index.html + required: true +env: + BUCKET: models-resources + PREFIX: researcher-reports + SRC_FILE: index-top.html + DEST_FILE: index.html +jobs: + release: + runs-on: ubuntu-latest + steps: + - run: > + aws s3 cp + s3://${{ env.BUCKET }}/${{ env.PREFIX }}/version/${{ github.event.inputs.version }}/${{ env.SRC_FILE }} + s3://${{ env.BUCKET }}/${{ env.PREFIX }}/${{ env.DEST_FILE }} + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-east-1 \ No newline at end of file diff --git a/.github/workflows/release-staging.yml b/.github/workflows/release-staging.yml new file mode 100644 index 0000000..111acb9 --- /dev/null +++ b/.github/workflows/release-staging.yml @@ -0,0 +1,24 @@ +name: Release Staging +on: + workflow_dispatch: + inputs: + version: + description: The git tag for the version to use for index-staging.html + required: true +env: + BUCKET: models-resources + PREFIX: researcher-reports + SRC_FILE: index-top.html + DEST_FILE: index-staging.html +jobs: + release: + runs-on: ubuntu-latest + steps: + - run: > + aws s3 cp + s3://${{ env.BUCKET }}/${{ env.PREFIX }}/version/${{ github.event.inputs.version }}/${{ env.SRC_FILE }} + s3://${{ env.BUCKET }}/${{ env.PREFIX }}/${{ env.DEST_FILE }} + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-east-1 \ No newline at end of file diff --git a/.github/workflows/researcher-reports.yml b/.github/workflows/researcher-reports.yml index 7186822..a89f008 100644 --- a/.github/workflows/researcher-reports.yml +++ b/.github/workflows/researcher-reports.yml @@ -12,8 +12,8 @@ jobs: name: Build and Run Jest Tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: '16' - name: Install Dependencies @@ -23,7 +23,7 @@ jobs: - name: Run Tests run: npm run test:coverage -- --runInBand - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v2 with: flags: jest cypress: @@ -40,7 +40,7 @@ jobs: containers: [1, 2, 3] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - uses: cypress-io/github-action@v2 with: working-directory: ./researcher-reports @@ -61,32 +61,34 @@ jobs: # should be much faster CODE_COVERAGE: true - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v2 with: flags: cypress s3-deploy: name: S3 Deploy needs: - build_test - # - cypress - runs-on: ubuntu-18.04 + #- cypress + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: '16' - - name: Setup Ruby - uses: actions/setup-ruby@v1 - with: - ruby-version: '2.7' - name: Install Dependencies - run: | - gem install s3_website -v 3.4.0 - npm ci - - name: Build - run: npm run build - - name: Deploy - run: ./s3_deploy.sh + run: npm ci env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} \ No newline at end of file + # skip installing cypress since it isn't needed for just building + # This decreases the deploy time quite a bit + CYPRESS_INSTALL_BINARY: 0 + - uses: concord-consortium/s3-deploy-action@v1 + with: + bucket: models-resources + prefix: researcher-reports + workingDirectory: ./researcher-reports + awsAccessKeyId: ${{ secrets.AWS_ACCESS_KEY_ID }} + awsSecretAccessKey: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + # Parameters to GHActions have to be strings, so a regular yaml array cannot + # be used. Instead the `|` turns the following lines into a string + topBranches: | + ["master"] \ No newline at end of file diff --git a/researcher-reports/README.md b/researcher-reports/README.md index a0995dc..71ed859 100644 --- a/researcher-reports/README.md +++ b/researcher-reports/README.md @@ -36,11 +36,11 @@ To deploy a production release: 4. Run `npm run build` 5. Copy asset size markdown table from previous release and change sizes to match new sizes in `dist` 6. Create `release-` branch and commit changes, push to GitHub, create PR and merge -7. Checkout master and pull -8. Checkout production -9. Run `git merge master --no-ff` -10. Push production to GitHub -11. Use https://github.com/concord-consortium/starter-projects/releases to create a new release tag +7. Test the master build at: https://researcher-reports.concord.org/index-master.html +8. Push a version tag to GitHub and/or use https://github.com/concord-consortium/researcher-reports/releases to create a new GitHub release +9. Stage the release by running the [Release Staging Workflow](https://github.com/concord-consortium/researcher-reports/actions/workflows/release-staging.yml) and entering the version tag you just pushed. +10. Test the staged release at https://researcher-reports.concord.org/index-staging.html +11. Update production by running the [Release Workflow](https://github.com/concord-consortium/researcher-reports/actions/workflows/release.yml) and entering the release version tag. ### Testing diff --git a/researcher-reports/s3_deploy.sh b/researcher-reports/s3_deploy.sh deleted file mode 100755 index 5e82be9..0000000 --- a/researcher-reports/s3_deploy.sh +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/bash - -# Typically this is the Project name. -# The trailing slash is important -# Can be set to an empty string for working at the top level of the bucket -S3_BUCKET_PREFIX='researcher-reports/' -# AWS CloudFront distribution ID -DISTRIBUTION_ID='E871G1995LFXX' -# AWS CloudFront distribution domain -DISTRIBUTION_DOMAIN='researcher-reports.concord.org' -# name of branch to deploy to root of site -ROOT_BRANCH='production' -# Bucket to deploy to, typically this is 'model-resources', but some projects -# have their own buckets -S3_BUCKET='models-resources' -# location of built files -SRC_DIR='dist' - -# exit when any command fails -set -e - -# keep track of the last executed command -trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG -# echo an error message before exiting -trap 'echo "\"${last_command}\" command exited with code $?."' EXIT - -# extract current TAG if present -# the 2> is to prevent error messages when no match is found -# the || echo prevents script exit when it doesn't match -CURRENT_TAG=`git describe --tags --exact-match $GITHUB_SHA 2> /dev/null || echo ''` - -# Extract the branch or tag name from the GITHUB_REF -# it should either be: refs/head/branch-name or -# or refs/tags/v1.2.3 -# since we ought to know if this is a branch or tag based on the ref -# we could simplify the CURRENT_TAG approach above -BRANCH_OR_TAG=${GITHUB_REF#refs/*/} -echo branch or tag: $BRANCH_OR_TAG - -# strip PT ID from branch name for branch builds -DEPLOY_DIR_NAME=$BRANCH_OR_TAG -PT_PREFIX_REGEX="^([0-9]{8,}-)(.+)$" -PT_SUFFIX_REGEX="^(.+)(-[0-9]{8,})$" -if [[ $DEPLOY_DIR_NAME =~ $PT_PREFIX_REGEX ]]; then - DEPLOY_DIR_NAME=${BASH_REMATCH[2]} -fi -if [[ $DEPLOY_DIR_NAME =~ $PT_SUFFIX_REGEX ]]; then - DEPLOY_DIR_NAME=${BASH_REMATCH[1]} -fi - -# tagged builds deploy to /version/TAG_NAME -if [ "$BRANCH_OR_TAG" = "$CURRENT_TAG" ]; then - mkdir -p _site/version - S3_DEPLOY_DIR="version/$BRANCH_OR_TAG" - DEPLOY_DEST="_site/$S3_DEPLOY_DIR" - INVAL_PATH="/version/$BRANCH_OR_TAG/index.html" - # in this case we are going to deploy this code to a subfolder of version - # So ignore everything except this folder. - # Currently this only escapes `.` - S3_DEPLOY_DIR_ESCAPED=$(sed 's/[.]/[&]/g;' <<<"$S3_DEPLOY_DIR") - IGNORE_ON_SERVER="^(?!$S3_BUCKET_PREFIX$S3_DEPLOY_DIR_ESCAPED/)" - -# root branch builds deploy to root of site -elif [ "$BRANCH_OR_TAG" = "$ROOT_BRANCH" ]; then - DEPLOY_DEST="_site" - INVAL_PATH="/index.html" - # in this case we are going to deploy this branch to the top level - # so we need to ignore the version and branch folders - IGNORE_ON_SERVER="^$S3_BUCKET_PREFIX(version/|branch/)" - -# branch builds deploy to /branch/BRANCH_NAME -else - mkdir -p _site/branch - S3_DEPLOY_DIR="branch/$DEPLOY_DIR_NAME" - DEPLOY_DEST="_site/$S3_DEPLOY_DIR" - INVAL_PATH="/branch/$DEPLOY_DIR_NAME/index.html" - # in this case we are going to deploy this code to a subfolder of branch - # So ignore everything except this folder. - # Currently this only escapes `.` - S3_DEPLOY_DIR_ESCAPED=$(sed 's/[.]/[&]/g;' <<<"$S3_DEPLOY_DIR") - IGNORE_ON_SERVER="^(?!$S3_BUCKET_PREFIX$S3_DEPLOY_DIR_ESCAPED/)" -fi - -# used by s3_website.yml -export S3_BUCKET_PREFIX -export IGNORE_ON_SERVER -export DISTRIBUTION_ID -export DISTRIBUTION_DOMAIN -export S3_BUCKET - -# copy files to destination -mv $SRC_DIR $DEPLOY_DEST - -# deploy the site contents; increase memory for s3_website gem -echo Deploying "$BRANCH_OR_TAG" to "$S3_BUCKET:$S3_BUCKET_PREFIX$S3_DEPLOY_DIR"... -JAVA_TOOL_OPTIONS="-Xms1g -Xmx2g" s3_website push --site _site - -# explicit CloudFront invalidation to workaround s3_website gem invalidation bug -# with origin path (https://github.com/laurilehmijoki/s3_website/issues/207). -aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths $INVAL_PATH diff --git a/researcher-reports/s3_website.yml b/researcher-reports/s3_website.yml deleted file mode 100644 index 071d25e..0000000 --- a/researcher-reports/s3_website.yml +++ /dev/null @@ -1,25 +0,0 @@ -s3_bucket: <%= ENV['S3_BUCKET'] %> -# only add the s3_key_prefix if there is one -<% if ENV['S3_BUCKET_PREFIX'] != '' %> -# Everywhere else the s3 prefix needs a trailing slash -# However s3_website config doesn't need one -s3_key_prefix: <%= ENV['S3_BUCKET_PREFIX'].sub(/\\/$/, '') %> -<% end %> -s3_endpoint: us-east-1 -gzip: true - -cloudfront_distribution_id: <%= ENV['DISTRIBUTION_ID'] %> -cloudfront_invalidate_root: true -cloudfront_wildcard_invalidation: true - -ignore_on_server: <%= ENV['IGNORE_ON_SERVER'] %> -max_age: - "<%= ENV['S3_BUCKET_PREFIX'] %>*": 600 # 10 minutes - "<%= ENV['S3_BUCKET_PREFIX'] %>version/*": 31536000 # 1 year - "<%= ENV['S3_BUCKET_PREFIX'] %>branch/*": 0 - -cloudfront_distribution_config: - aliases: - quantity: 1 - items: - - <%= ENV['DISTRIBUTION_DOMAIN'] %> diff --git a/researcher-reports/webpack.config.js b/researcher-reports/webpack.config.js index 49901b2..cd691c0 100644 --- a/researcher-reports/webpack.config.js +++ b/researcher-reports/webpack.config.js @@ -5,6 +5,10 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const HtmlWebpackPlugin = require('html-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); +// DEPLOY_PATH is set by the s3-deploy-action its value will be: +// `branch/[branch-name]/` or `version/[tag-name]/` +const DEPLOY_PATH = process.env.DEPLOY_PATH; + module.exports = (env, argv) => { const devMode = argv.mode !== 'production'; @@ -124,6 +128,11 @@ module.exports = (env, argv) => { template: 'src/index.html', favicon: 'src/public/favicon.ico' }), + ...(DEPLOY_PATH ? [new HtmlWebpackPlugin({ + filename: "index-top.html", + template: "src/index.html", + publicPath: DEPLOY_PATH, + })] : []), new CleanWebpackPlugin(), ] };