Skip to content

Commit

Permalink
chore: Add no-cache to service worker and manifest (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
v-almonacid authored Mar 8, 2024
1 parent f8f1f75 commit 7375231
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ jobs:
AWS_REGION: "eu-west-1" # optional: defaults to us-east-1
SOURCE_DIR: "dist"

set-index-cache-control:
uses: ./.github/workflows/set-index-cache-control.yml
set-cache-control:
uses: ./.github/workflows/set-cache-control.yml
needs: deploy
if: needs.deploy.result == 'success'
with:
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/deploy-epsilon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ jobs:
AWS_REGION: "eu-west-1" # optional: defaults to us-east-1
SOURCE_DIR: "dist"

set-cache-control:
uses: ./.github/workflows/set-cache-control.yml
needs: deploy
if: needs.deploy.result == 'success'
with:
ENVIRONMENT: epsilon
VALUE: "no-cache"
secrets: inherit

# Get message VARs and Notify team through discord of deployment
notify:
name: Notify
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ jobs:
AWS_REGION: "eu-west-1" # optional: defaults to us-east-1
SOURCE_DIR: "dist"

set-index-cache-control:
uses: ./.github/workflows/set-index-cache-control.yml
set-cache-control:
uses: ./.github/workflows/set-cache-control.yml
needs: deploy
if: needs.deploy.result == 'success'
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ jobs:
AWS_REGION: "eu-west-1" # optional: defaults to us-east-1
SOURCE_DIR: "dist"

set-index-cache-control:
uses: ./.github/workflows/set-index-cache-control.yml
set-cache-control:
uses: ./.github/workflows/set-cache-control.yml
needs: deploy
if: needs.deploy.result == 'success'
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# This workflow is used to set the cache-control header of the app's index.html file
# This workflow is used to set the cache-control header of sensitive files, namely
# - index.html
# - sw.js
# - manifest.webmanifest
# (which should in general be set to `no-cache`).

name: Set Index Cache Control
name: Set Cache Control

on:
workflow_dispatch:
Expand All @@ -11,11 +14,12 @@ on:
# eg. "max-age=86400" or "no-cache"
type: string
ENVIRONMENT:
description: "Environment to set the cache control header of index.html"
description: "Environment to set the cache control header for sensitive files"
required: true
default: "zetta"
type: choice
options:
- "epsilon"
- "zetta"
- "gamma"
- "alpha"
Expand All @@ -31,7 +35,7 @@ on:
type: string

jobs:
set-index-cache-control:
set-cache-control:
runs-on: ubuntu-latest
steps:
- name: Sets env vars for production
Expand All @@ -44,11 +48,17 @@ jobs:
echo "BUCKET=${{ secrets.STAGING__FRONTEND__S3_BUCKET }}" >> $GITHUB_ENV
if: contains(inputs.ENVIRONMENT, 'gamma')

- name: Sets env vars for development
- name: Sets env vars for development (zetta)
run: |
echo "BUCKET=${{ secrets.DEV__FRONTEND__S3_BUCKET }}" >> $GITHUB_ENV
if: contains(inputs.ENVIRONMENT, 'zetta')

- name: Sets env vars for development (epsilon)
run: |
echo "BUCKET=${{ secrets.DEV__FRONTENDV2__S3_BUCKET }}" >> $GITHUB_ENV
if: contains(inputs.ENVIRONMENT, 'epsilon')

# Set cache for index.html
- uses: keithweaver/[email protected]
with:
command: cp
Expand All @@ -62,3 +72,33 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.DEPLOYER__AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEPLOYER__SECRET_ACCESS_KEY }}
AWS_S3_PATH: s3://${{ env.BUCKET }}/index.html

# Set cache for sw.js
- uses: keithweaver/[email protected]
with:
command: cp
source: ${{ env.AWS_S3_PATH }}
destination: ${{ env.AWS_S3_PATH }}
flags: "--cache-control ${{ inputs.VALUE }}"
aws_access_key_id: ${{ env.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws_region: us-west-1
env:
AWS_ACCESS_KEY_ID: ${{ secrets.DEPLOYER__AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEPLOYER__SECRET_ACCESS_KEY }}
AWS_S3_PATH: s3://${{ env.BUCKET }}/sw.js

# Set cache for manifest.webmanifest
- uses: keithweaver/[email protected]
with:
command: cp
source: ${{ env.AWS_S3_PATH }}
destination: ${{ env.AWS_S3_PATH }}
flags: "--cache-control ${{ inputs.VALUE }}"
aws_access_key_id: ${{ env.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws_region: us-west-1
env:
AWS_ACCESS_KEY_ID: ${{ secrets.DEPLOYER__AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEPLOYER__SECRET_ACCESS_KEY }}
AWS_S3_PATH: s3://${{ env.BUCKET }}/manifest.webmanifest

0 comments on commit 7375231

Please sign in to comment.