Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save cache with hash key #98

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/actions/compile-assets/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Compile assets for deploy
description: Restore a deployed asset cache, precompile, and clean
inputs:
rails_env:
description: RAILS_ENV to set.
required: true
fail_on_missing_cache:
description: Whether to fail the action on a missing cache
required: true
save_cache:
description: Whether to save the compiled assets to a cache
required: false
default: false
runs:
using: composite
steps:
- uses: ./.github/actions/setup-languages

- name: Restore asset cache
uses: actions/cache/restore@v4
with:
key: ${{ inputs.rails_env }}-assets
fail-on-cache-miss: ${{ inputs.fail_on_missing_cache }}
path: |
public/assets
app/assets/builds
app/javascript/generated

- name: Precompile assets
env:
RAILS_ENV: ${{ inputs.rails_env }}
SECRET_KEY_BASE_DUMMY: 1
shell: bash
run: ./bin/rake assets:precompile

- name: Clean old assets
env:
RAILS_ENV: ${{ inputs.rails_env }}
SECRET_KEY_BASE_DUMMY: 1
shell: bash
run: ./bin/rake assets:clean

- name: Save cache
if: ${{ inputs.save_cache }}
uses: actions/cache/save@v4
with:
key: ${{ inputs.rails_env }}-assets-${{ hashFiles('public/assets/.manifest.json') }}
path: |
public/assets
app/assets/builds
app/javascript/generated
13 changes: 5 additions & 8 deletions .github/actions/setup-project/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ outputs:
runs:
using: composite
steps:
- name: Set up Ruby & Javascript
uses: ./.github/actions/setup-languages

- name: Precompile assets
env:
RAILS_ENV: ${{ inputs.rails_env }}
SECRET_KEY_BASE: not-actually-secret
shell: bash
run: bundle exec rake assets:precompile
uses: ./.github/actions/compile-assets
with:
rails_env: ${{ inputs.rails_env }}
fail_on_missing_cache: false
save_cache: true

- name: Set up database
env:
Expand Down
19 changes: 6 additions & 13 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-languages
- name: Asset cache
uses: actions/cache@v4

- name: Compile assets
uses: ./.github/actions/compile-assets
with:
key: staging-assets-deployed
path: |
public/assets
app/assets/builds
app/javascript/generated
- name: Precompile assets and clean old versions
env:
RAILS_ENV: staging
SECRET_KEY_BASE_DUMMY: 1
run: ./bin/rake assets:precompile && ./bin/rake assets:clean
rails_env: staging
fail_on_missing_cache: false
save_cache: true

- name: Terraform apply
uses: dflook/terraform-apply@v1
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/owasp-daily-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Touch staging cache
uses: ./.github/actions/compile-assets
with:
rails_env: staging
fail_on_missing_cache: true

- id: setup
uses: ./.github/actions/setup-project

Expand Down
18 changes: 4 additions & 14 deletions .github/workflows/terraform-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,11 @@ jobs:
with:
path: terraform

- uses: ./.github/actions/setup-languages
- name: Restore asset cache
uses: actions/cache/restore@v4
- name: Compile assets
uses: ./.github/actions/compile-assets
with:
key: staging-assets-deployed
fail-on-cache-miss: true
path: |
public/assets
app/assets/builds
app/javascript/generated
- name: Precompile assets and clean old versions
env:
RAILS_ENV: staging
SECRET_KEY_BASE_DUMMY: 1
run: ./bin/rake assets:precompile && ./bin/rake assets:clean
rails_env: staging
fail_on_missing_cache: true

- name: terraform plan
uses: dflook/terraform-plan@v1
Expand Down
Loading