Skip to content

Commit

Permalink
Switch to cache for transferring data
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-heyer committed Jan 13, 2025
1 parent cb971a0 commit 721e1a3
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 30 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/build-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ on:
description: SHA, should correspond to ref
required: true
type: string
outputs:
cache-key:
description: key to use to pull built pages from cache
value: ${{ jobs.build.outputs.cache-key }}

jobs:
build:
runs-on: docs-16c-64gb-600gb
outputs:
cache-key: ${{ steps.cache-key.outputs.key }}
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -54,6 +60,11 @@ jobs:
- name: Run NPM install scripts
run: |
npm rebuild
- name: Compose cache key
id: cache-key
run: |
echo "key=${{ runner.os }}-gatsby-build-${{ hashFiles('package.json', 'gatsby-config.js', 'gatsby-node.js') }}-${{ inputs.ref }}-${{ inputs.sha }}" >> "$GITHUB_OUTPUT"
- name: Checking Gatsby cache
id: gatsby-cache-build
Expand All @@ -63,7 +74,7 @@ jobs:
public/*
!public/pdfs
.cache
key: ${{ runner.os }}-gatsby-build-${{ hashFiles('package.json', 'gatsby-config.js', 'gatsby-node.js') }}-${{ inputs.ref }}-${{ inputs.sha }}
key: ${{ steps.cache-key.outputs.key }}
restore-keys: |
${{ runner.os }}-gatsby-build-${{ hashFiles('package.json', 'gatsby-config.js', 'gatsby-node.js') }}-${{ inputs.ref }}
${{ runner.os }}-gatsby-build-${{ hashFiles('package.json', 'gatsby-config.js', 'gatsby-node.js') }}
Expand All @@ -85,10 +96,3 @@ jobs:
ALGOLIA_INDEX_NAME: edb-docs-staging
INDEX_ON_BUILD: ${{ inputs.ref == 'develop' }}

- name: Store pages
uses: actions/upload-artifact@v4
with:
name: pages-build
path: |
public/*
!public/pdfs
28 changes: 13 additions & 15 deletions .github/workflows/build-pdfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ on:
description: SHA, should correspond to ref
required: true
type: string

outputs:
cache-key:
description: key to use to pull built pages from cache
value: ${{ jobs.build.outputs.cache-key }}

jobs:
build:
runs-on: docs-16c-64gb-600gb
outputs:
cache-key: ${{ steps.cache-key.outputs.key }}
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -61,6 +67,11 @@ jobs:
run: |
npm install
- name: Compose cache key
id: cache-key
run: |
echo "key=${{ runner.os }}-build-pdfs-${{ hashFiles('scripts/pdf/*', 'scripts/pdf/lib/*') }}-${{ inputs.sha }}" >> "$GITHUB_OUTPUT"
- name: Checking PDF cache
id: pdf-cache-build
uses: actions/cache@v4
Expand All @@ -70,22 +81,9 @@ jobs:
product_docs/**/*.pdf-hash
advocacy_docs/**/*.pdf
advocacy_docs/**/*.pdf-hash
key: ${{ runner.os }}-build-pdfs-${{ hashFiles('scripts/pdf/*', 'scripts/pdf/lib/*') }}-${{ inputs.sha }}
key: ${{ steps.cache-key.outputs.key }}
restore-keys: |
${{ runner.os }}-build-pdfs-${{ hashFiles('scripts/pdf/*', 'scripts/pdf/lib/*') }}
- name: Build all pdfs
run: npm run pdf:build-all-ci

- name: Copy pdfs to build output
run: |
mkdir -p public/pdfs
shopt -s globstar
rsync -avm --filter="+ */" --filter="-! *.pdf" advocacy_docs/ public/pdfs/
rsync -avm --filter="+ */" --filter="-! *.pdf" product_docs/docs/ public/pdfs/
- name: Store pdfs
uses: actions/upload-artifact@v4
with:
name: pdf-build
path: public/*
9 changes: 8 additions & 1 deletion .github/workflows/deploy-draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ jobs:
# this job will fail only if build-pdfs failed (not if it was skipped)
# however, it will set an output - check-has-pdfs.steps.check.has-pdfs - true if PDFs were generated
check-has-pdfs:
runs-on: ubuntu-22.04
needs: build-pdfs
if: ${{ always() }}
runs-on: ubuntu-22.04
outputs:
cache-key: ${{ steps.check.outputs.cache-key }}
has-pdfs: ${{ steps.check.outputs.has-pdfs }}
steps:
- name: check
id: check
run: |
echo "cache-key=${{ needs.build-pdfs.outputs.cache-key }}" >> "$GITHUB_OUTPUT"
echo "has-pdfs=${{ needs.build-pdfs.result == 'success' }}" >> "$GITHUB_OUTPUT"
exit ${{ needs.build-pdfs.result == 'failure' && 1 || 0 }}
Expand All @@ -53,6 +58,8 @@ jobs:
if: ${{ !cancelled() && needs.build-pages.result == 'success' && needs.check-has-pdfs.result == 'success' }}
uses: ./.github/workflows/deploy-to-netlify.yml
with:
pages-cache-key: ${{ needs.build-pages.outputs.cache-key }}
pdf-cache-key: ${{ needs.check-has-pdfs.outputs.cache-key }}
enable-commit-comment: false
alias: deploy-preview-${{ github.event.number }}
secrets: inherit
43 changes: 37 additions & 6 deletions .github/workflows/deploy-to-netlify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ on:
workflow_dispatch:
workflow_call:
inputs:
pages-cache-key:
description: key for pages cache
required: true
type: string
pdf-cache-key:
description: key for pdf cache
required: false
type: string
enable-pull-request-comment:
description: whether to comment on the triggering PR
required: false
Expand All @@ -20,14 +28,37 @@ on:

jobs:
deploy:
runs-on: ubuntu-22.04
runs-on: docs-16c-64gb-600gb
steps:
- name: Pull build artifacts
uses: actions/download-artifact@v4
with:
path: ./public
merge-multiple: true
- name: Pull pages cache
uses: actions/cache/restore@v4
with:
fail-on-cache-miss: true
path: |
public/*
!public/pdfs
.cache
key: ${{ inputs.pages-cache-key }}

- name: Pull PDF cache
uses: actions/cache/restore@v4
with:
path: |
product_docs/**/*.pdf
product_docs/**/*.pdf-hash
advocacy_docs/**/*.pdf
advocacy_docs/**/*.pdf-hash
key: ${{ inputs.pdf-cache-key }}


- name: Copy pdfs to build output
run: |
sudo apt update
sudo apt install -y rsync
mkdir -p public/pdfs
rsync -avm --filter="+ */" --filter="-! *.pdf" advocacy_docs/ public/pdfs/
rsync -avm --filter="+ */" --filter="-! *.pdf" product_docs/docs/ public/pdfs/
- name: list
run: ls -lfR ./public

Expand Down

0 comments on commit 721e1a3

Please sign in to comment.