From 7e50469ae6046da08b87a690f245f5448af64cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Varga?= Date: Mon, 9 Dec 2024 07:47:37 +0100 Subject: [PATCH] fix: Optimize Firebase CI workflows with caching for firebase.json - **Workflows Updated**: - **`delete-firebase-hosting-channel.yml`**: - Added caching for `firebase.json` using `actions/cache` to persist configuration across workflow runs. - Updated `actions/checkout` and `w9jds/firebase-action` to pinned versions for enhanced stability. - Conditional execution of Firebase actions based on cache availability. - **`firebase-hosting-pull-request.yml`**: - Implemented `actions/cache/save` to store `firebase.json` after build and test steps. - Updated workflow to ensure `firebase.json` is available for subsequent Firebase deployments. - **Impact**: - Speeds up Firebase workflow executions by reducing redundant `firebase.json` generation. - Enhances workflow reliability with pinned dependencies and optimized caching. --- .github/workflows/delete-firebase-hosting-channel.yml | 11 ++++++++++- .github/workflows/firebase-hosting-pull-request.yml | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/delete-firebase-hosting-channel.yml b/.github/workflows/delete-firebase-hosting-channel.yml index 791a27a..fb658ab 100644 --- a/.github/workflows/delete-firebase-hosting-channel.yml +++ b/.github/workflows/delete-firebase-hosting-channel.yml @@ -8,8 +8,17 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 10 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Restore firebase.json + id: cache-restore-firebase-json + uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0 + env: + cache-name: firebase + with: + path: firebase.json + key: ${{ github.head_ref }} - uses: w9jds/firebase-action@12e7dd1a31239567f9b4d398e6c1dc9f1c6fc70a # v13.28.0 + if: steps.cache-restore-firebase-json.outputs.cache-hit == 'true' with: # Extracts the full channel name from the PR number and feeds it to the delete command args: hosting:channel:list | grep 'pr${{ github.event.pull_request.number }}' | cut --delimiter ' ' --fields 2 | xargs -I {} firebase hosting:channel:delete --force {} diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/firebase-hosting-pull-request.yml index 8098194..9a2e204 100644 --- a/.github/workflows/firebase-hosting-pull-request.yml +++ b/.github/workflows/firebase-hosting-pull-request.yml @@ -23,6 +23,13 @@ jobs: key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - name: Build and Test run: ./scripts/build.sh + - name: Save firebase.json + uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0 + env: + cache-name: firebase + with: + path: firebase.json + key: ${{ github.head_ref }} - uses: FirebaseExtended/action-hosting-deploy@0cbcac4740c2bfb00d632f0b863b57713124eb5a # v0.9.0 with: repoToken: '${{ secrets.GITHUB_TOKEN }}'