diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7df7676..d6ddfe3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,10 +1,11 @@ -name: Update latest data +name: Build and Deploy on: workflow_dispatch: - schedule: - - cron: "30 9,10 * * 5" # Run at 5:30 and 6:30 pm every Thuesday Eastern Time (cron is in UTC) + push: + branches: + - master jobs: - update-data: + deploy: runs-on: ubuntu-latest steps: - name: Get current date @@ -41,14 +42,15 @@ jobs: ${{ env.cache-name }}-${{ github.ref }}- - name: Install dependencies run: yarn install - - name: Fetch latest data file - run: ./downloadDataFile.js - - name: Verify successful build + - name: Build site run: yarn build - - name: Commit & Push changes - uses: actions-js/push@master + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 with: - branch: "master" - github_token: ${{ secrets.GITHUB_TOKEN }} - author_name: "Databot" - message: "Add latest data" \ No newline at end of file + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + - name: Deploy + run: S3_BUCKET_NAME=${{ secrets.S3_BUCKET_NAME }} yarn deploy + - name: Invalidate cloudfront + run: CLOUDFRONT_DISTRIBUTON_ID=${{ secrets.CLOUDFRONT_DISTRIBUTON_ID }} yarn invalidate-cloudfront diff --git a/.github/workflows/update-data.yml b/.github/workflows/update-data.yml index 9b6e361..303c9f9 100644 --- a/.github/workflows/update-data.yml +++ b/.github/workflows/update-data.yml @@ -12,8 +12,8 @@ jobs: run: echo "::set-output name=date::$(date +'%Y-%m-%d')" - name: Check out repository code uses: actions/checkout@v2 + - run : git pull origin master - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - uses: actions/setup-node@v2 with: node-version: "14.16.1" diff --git a/package.json b/package.json index a715bbf..0ec3d96 100644 --- a/package.json +++ b/package.json @@ -53,10 +53,11 @@ "build": "GATSBY_EXPERIMENTAL_PAGE_BUILD_ON_DATA_CHANGES=true gatsby build", "develop": "gatsby develop", "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"", - "serve": "gatsby serve", + "serve": "gatsby serve", "clean": "gatsby clean", "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1", - "deploy": "aws s3 sync ./public s3://$S3_BUCKET_NAME/" + "deploy": "aws s3 sync ./public s3://$S3_BUCKET_NAME/", + "invalidate-cloudfront": "aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths \"/*\"" }, "repository": { "type": "git",