From 8db862d5b3019899fa648bd16def2a58e6763bcd Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Fri, 8 Mar 2024 09:17:43 -0500 Subject: [PATCH 1/8] feat: cache assets on successful deploy --- .github/workflows/deploy.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ec1182b8ad..08d0d12c9b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -48,3 +48,9 @@ jobs: PAGES_BRANCH: gh-pages BUILD_DIR: . TOKEN: ${{ secrets.CART_PAT }} + + - name: Update generate-assets cache + uses: actions/cache/save@v4 + with: + path: content/assets + key: assets-${{ hashFiles('generate-assets/**/*.rs', 'generate-assets/Cargo.toml', 'generate-assets/generate_assets.sh') }} From 98ce5789b92b01089852d188cc92680c7eab9c67 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Fri, 8 Mar 2024 09:23:35 -0500 Subject: [PATCH 2/8] feat: restore assets cache in ci action --- .github/workflows/ci.yml | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b17043f71e..a9cd3449ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,27 +86,17 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/cache@v4 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - generate-assets/target/ - key: ${{ runner.os }}-generate-assets-${{ hashFiles('generate-assets/Cargo.toml') }} - - - name: Get cache key - id: cache-key - run: echo "key=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT - - - name: Get crates.io datadump from cache - uses: actions/cache@v4 + - name: Restore cached assets + id: restore-cached-assets + uses: actions/cache/restore@v4 with: - path: generate-assets/data - key: ${{ runner.os }}-${{ steps.cache-key.outputs.key }} + # Must be kept in sync with deploy.yml + path: content/assets + key: assets-${{ hashFiles('generate-assets/**/*.rs', 'generate-assets/Cargo.toml', 'generate-assets/generate_assets.sh') }} - name: "Build Bevy Assets" + # Only run if no cache was found + if: ${{ !steps.restore-cached-assets.outputs.cache-hit }} run: > cd generate-assets && export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} && From 4f367bf59815c73fe89e8b6c8dc3610769c046ec Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Fri, 8 Mar 2024 09:25:41 -0500 Subject: [PATCH 3/8] refactor: simplify generate-assets step --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9cd3449ee..ec81309dca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,10 +97,10 @@ jobs: - name: "Build Bevy Assets" # Only run if no cache was found if: ${{ !steps.restore-cached-assets.outputs.cache-hit }} - run: > - cd generate-assets && - export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} && - ./generate_assets.sh + working-directory: generate-assets + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./generate_assets.sh - uses: actions/upload-artifact@v4 with: From 92208a97dcf2a4d42de350efdbcab7e27331e891 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Fri, 8 Mar 2024 10:12:06 -0500 Subject: [PATCH 4/8] chore: add further comments to caching steps --- .github/workflows/ci.yml | 1 + .github/workflows/deploy.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec81309dca..7f5d047513 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,6 +86,7 @@ jobs: steps: - uses: actions/checkout@v4 + # Uses the generate-assets cache, which is updated in deploy.yml - name: Restore cached assets id: restore-cached-assets uses: actions/cache/restore@v4 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 08d0d12c9b..270e0da57a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -49,6 +49,7 @@ jobs: BUILD_DIR: . TOKEN: ${{ secrets.CART_PAT }} + # Caches output of generate-assets for use in ci.yml - name: Update generate-assets cache uses: actions/cache/save@v4 with: From 141dc25421b8bb335ddba4975526621c93581534 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Fri, 8 Mar 2024 10:16:59 -0500 Subject: [PATCH 5/8] feat: do not use cache in merge queue --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f5d047513..a20efd990c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,6 +88,8 @@ jobs: # Uses the generate-assets cache, which is updated in deploy.yml - name: Restore cached assets + # Do not use cache when in merge queue + if: ${{ github.event_name != 'merge_group' }} id: restore-cached-assets uses: actions/cache/restore@v4 with: @@ -96,8 +98,8 @@ jobs: key: assets-${{ hashFiles('generate-assets/**/*.rs', 'generate-assets/Cargo.toml', 'generate-assets/generate_assets.sh') }} - name: "Build Bevy Assets" - # Only run if no cache was found - if: ${{ !steps.restore-cached-assets.outputs.cache-hit }} + # Only run if in merge queue or if no cache was found + if: ${{ github.event_name == 'merge_group' || !steps.restore-cached-assets.outputs.cache-hit }} working-directory: generate-assets env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From fc8ec06f7dc789553792b32ecec4ad2f741f0c4d Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Fri, 8 Mar 2024 21:24:15 -0500 Subject: [PATCH 6/8] fix: include date in assets cache key Caches cannot be overwritten after their creation, so the date ensures the cache is refreshed daily. This is especially true since `deploy.yml` is scheduled to run daily anyways, so there will always be a cache available for `ci.yml`. --- .github/workflows/ci.yml | 6 +++++- .github/workflows/deploy.yml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a20efd990c..b5084c931f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,6 +86,10 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Get current date + id: date + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + # Uses the generate-assets cache, which is updated in deploy.yml - name: Restore cached assets # Do not use cache when in merge queue @@ -95,7 +99,7 @@ jobs: with: # Must be kept in sync with deploy.yml path: content/assets - key: assets-${{ hashFiles('generate-assets/**/*.rs', 'generate-assets/Cargo.toml', 'generate-assets/generate_assets.sh') }} + key: assets-${{ steps.date.outputs.date }}-${{ hashFiles('generate-assets/**/*.rs', 'generate-assets/Cargo.toml', 'generate-assets/generate_assets.sh') }} - name: "Build Bevy Assets" # Only run if in merge queue or if no cache was found diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 270e0da57a..9e5346514b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -54,4 +54,4 @@ jobs: uses: actions/cache/save@v4 with: path: content/assets - key: assets-${{ hashFiles('generate-assets/**/*.rs', 'generate-assets/Cargo.toml', 'generate-assets/generate_assets.sh') }} + key: assets-${{ steps.date.outputs.date }}-${{ hashFiles('generate-assets/**/*.rs', 'generate-assets/Cargo.toml', 'generate-assets/generate_assets.sh') }} From 191457160082b8f374239d6edd4f8cc7171db277 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Fri, 8 Mar 2024 21:26:58 -0500 Subject: [PATCH 7/8] chore!: don't cache crates.io data dump I don't think `deploy.yml` should use any cached data, in case it ever becomes invalid. This is why `deploy.yml` only stores the cache. By deleting the crates.io cache, it may increase deploy times. If this becomes an issue, I'll make a follow-up PR and undo this change. --- .github/workflows/deploy.yml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9e5346514b..79d2efab00 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,16 +13,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Get current date - id: date - run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT - - - name: Cache multiple crates.io datadump - uses: actions/cache@v4 - with: - path: generate-assets/data - key: ${{ runner.os }}-${{ steps.date.outputs.date }} - - name: "Build Bevy Assets" run: cd generate-assets && ./generate_assets.sh env: @@ -49,6 +39,10 @@ jobs: BUILD_DIR: . TOKEN: ${{ secrets.CART_PAT }} + - name: Get current date + id: date + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + # Caches output of generate-assets for use in ci.yml - name: Update generate-assets cache uses: actions/cache/save@v4 From 30a809e100edb292b5b4673911f1dff72c9ceb3a Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Fri, 8 Mar 2024 21:31:48 -0500 Subject: [PATCH 8/8] Revert "chore!: don't cache crates.io data dump" This reverts commit 191457160082b8f374239d6edd4f8cc7171db277. --- .github/workflows/deploy.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 79d2efab00..9e5346514b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,6 +13,16 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Get current date + id: date + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + + - name: Cache multiple crates.io datadump + uses: actions/cache@v4 + with: + path: generate-assets/data + key: ${{ runner.os }}-${{ steps.date.outputs.date }} + - name: "Build Bevy Assets" run: cd generate-assets && ./generate_assets.sh env: @@ -39,10 +49,6 @@ jobs: BUILD_DIR: . TOKEN: ${{ secrets.CART_PAT }} - - name: Get current date - id: date - run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT - # Caches output of generate-assets for use in ci.yml - name: Update generate-assets cache uses: actions/cache/save@v4