From 496737f505cbdf3edcec872f6110c3282890cd1d Mon Sep 17 00:00:00 2001 From: uolter Date: Wed, 4 Jan 2023 14:40:45 +0100 Subject: [PATCH] param 2 disable build cache in github actions --- .github/workflows/aws-live-deploy.yml | 12 +++++++- .github/workflows/aws-preview-deploy.yml | 12 +++++++- .github/workflows/deploy/action.yaml | 35 ++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/.github/workflows/aws-live-deploy.yml b/.github/workflows/aws-live-deploy.yml index ed78942..778c53b 100644 --- a/.github/workflows/aws-live-deploy.yml +++ b/.github/workflows/aws-live-deploy.yml @@ -11,6 +11,14 @@ on: options: - dev - prod + cache: + description: 'Cache yarn and gatsby builds.' + type: choice + default: true + required: true + options: + - true + - false # webhook trigger repository_dispatch: @@ -64,6 +72,7 @@ jobs: aws_iam_role: ${{ secrets.IAM_ROLE }} aws_bucket: ${{ matrix.AWS_BUCKET }} aws_cloudfront_id: ${{ matrix.AWS_CLOUDFRONT_ID }} + build_with_cache: ${{ inputs.cache }} - name: Webhook Build and Deploy if: ${{ github.event.action == format('webhook-live-{0}', matrix.environment) }} @@ -75,4 +84,5 @@ jobs: strapi_token: ${{ secrets.STRAPI_TOKEN }} aws_iam_role: ${{ secrets.IAM_ROLE }} aws_bucket: ${{ matrix.AWS_BUCKET }} - aws_cloudfront_id: ${{ matrix.AWS_CLOUDFRONT_ID }} \ No newline at end of file + aws_cloudfront_id: ${{ matrix.AWS_CLOUDFRONT_ID }} + build_with_cache: true \ No newline at end of file diff --git a/.github/workflows/aws-preview-deploy.yml b/.github/workflows/aws-preview-deploy.yml index 6368215..8416ecd 100644 --- a/.github/workflows/aws-preview-deploy.yml +++ b/.github/workflows/aws-preview-deploy.yml @@ -11,6 +11,14 @@ on: options: - dev - prod + cache: + description: 'Cache yarn and gatsby builds.' + type: choice + default: true + required: true + options: + - true + - false # webhook trigger repository_dispatch: @@ -64,6 +72,7 @@ jobs: aws_iam_role: ${{ secrets.IAM_ROLE }} aws_bucket: ${{ matrix.AWS_BUCKET }} aws_cloudfront_id: ${{ matrix.AWS_CLOUDFRONT_ID }} + build_with_cache: ${{ inputs.cache }} - name: Webhook Build and Deploy if: ${{ github.event.action == format('webhook-preview-{0}', matrix.environment) }} @@ -75,4 +84,5 @@ jobs: strapi_token: ${{ secrets.STRAPI_TOKEN }} aws_iam_role: ${{ secrets.IAM_ROLE }} aws_bucket: ${{ matrix.AWS_BUCKET }} - aws_cloudfront_id: ${{ matrix.AWS_CLOUDFRONT_ID }} \ No newline at end of file + aws_cloudfront_id: ${{ matrix.AWS_CLOUDFRONT_ID }} + build_with_cache: true \ No newline at end of file diff --git a/.github/workflows/deploy/action.yaml b/.github/workflows/deploy/action.yaml index 537f9d2..d561bae 100644 --- a/.github/workflows/deploy/action.yaml +++ b/.github/workflows/deploy/action.yaml @@ -23,6 +23,10 @@ inputs: aws_cloudfront_id: required: true type: string + build_with_cache: + required: false + type: bool + default: true runs: @@ -40,6 +44,37 @@ runs: uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 with: node-version: 16 + + - name: Yarn cache + if: ${{ inputs.build_with_cache == true }} + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Gatsby Cache Folder + if: ${{ inputs.build_with_cache == true }} + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + id: gatsby-cache-folder + with: + path: src/app/.cache + key: ${{ runner.os }}-cache-gatsby + restore-keys: | + ${{ runner.os }}-cache-gatsby + + - name: Gatsby Public Folder + if: ${{ inputs.build_with_cache == true }} + uses: actions/cache@4723a57e26efda3a62cbde1812113b730952852d + id: gatsby-public-folder + with: + path: src/app/public/ + key: ${{ runner.os }}-public-gatsby + restore-keys: | + ${{ runner.os }}-public-gatsby + - name: Build id: build shell: bash