ci: reuse main branch build caches for releases

- Warm Rust, Bun, and core caches on pushes to main
- Save shared caches only on main to avoid duplication across tags
- Isolate build caches by runner
- Skip signing and publishing during cache warmup
- Cancel outdated warmup runs without interrupting releases
This commit is contained in:
lzt404 committed 2026-09-06 21:54:29 +08:00
1 parent 4941808e91
commit 6c0e158661
1 file changed
+35 -11
+35 -11
View File
@@ -1,7 +1,7 @@
name: Build portable releases
run-name: >-
Portable release ${{ (github.ref_type == 'tag' && github.ref_name) || inputs.release_tag || github.ref_name }}
${{ github.event_name == 'push' && github.ref_type == 'branch' && 'Warm build caches' || 'Portable release' }} ${{ (github.ref_type == 'tag' && github.ref_name) || inputs.release_tag || github.ref_name }}
on:
workflow_dispatch:
@@ -16,9 +16,15 @@ on:
default: true
type: boolean
push:
branches:
- main
tags:
- 'v*'
concurrency:
group: portable-${{ github.ref }}-${{ github.event_name == 'push' && github.ref_type == 'branch' && 'cache' || 'release' }}
cancel-in-progress: ${{ github.event_name == 'push' && github.ref_type == 'branch' }}
permissions:
contents: read
@@ -96,6 +102,8 @@ jobs:
suffix: zip
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
env:
PACKAGE_RELEASE: ${{ github.event_name == 'workflow_dispatch' || github.ref_type == 'tag' }}
steps:
- uses: actions/checkout@v7
with:
@@ -104,21 +112,24 @@ jobs:
with:
bun-version: 1.3.14
- uses: dtolnay/rust-toolchain@1.97.0
- name: Cache Bun packages
uses: actions/cache@v5
- name: Restore Bun packages
id: bun-cache
uses: actions/cache/restore@v5
with:
path: ~/.bun/install/cache
key: bun-${{ runner.os }}-${{ runner.arch }}-1.3.14-${{ hashFiles('bun.lock') }}
key: bun-${{ matrix.runner }}-1.3.14-${{ hashFiles('bun.lock') }}
restore-keys: |
bun-${{ runner.os }}-${{ runner.arch }}-1.3.14-
bun-${{ matrix.runner }}-1.3.14-
- name: Cache Rust dependencies and build outputs
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.runner }}
workspaces: src-tauri -> target
cache-workspace-crates: true
cache-on-failure: true
- name: Cache bundled core archive
uses: actions/cache@v5
save-if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
- name: Restore bundled core archive
id: core-cache
uses: actions/cache/restore@v5
with:
path: cpa-core
key: core-v2-${{ matrix.os }}-${{ matrix.arch }}-${{ hashFiles('core-version.txt') }}
@@ -154,8 +165,20 @@ jobs:
--arch "${{ matrix.arch }}"
--download true
shell: bash
- name: Save Bun packages
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && steps.bun-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: ~/.bun/install/cache
key: ${{ steps.bun-cache.outputs.cache-primary-key }}
- name: Save bundled core archive
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && steps.core-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: cpa-core
key: ${{ steps.core-cache.outputs.cache-primary-key }}
- name: Build signed macOS DMG
if: matrix.os == 'darwin'
if: env.PACKAGE_RELEASE == 'true' && matrix.os == 'darwin'
shell: bash
env:
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
@@ -252,14 +275,15 @@ jobs:
--wait
xcrun stapler staple "$output_dmg"
- name: Archive Linux release
if: matrix.os == 'linux'
if: env.PACKAGE_RELEASE == 'true' && matrix.os == 'linux'
run: tar -czf "${{ steps.package.outputs.stem }}.tar.gz" -C release "${{ steps.package.outputs.stem }}"
- name: Archive Windows release
if: matrix.os == 'windows'
if: env.PACKAGE_RELEASE == 'true' && matrix.os == 'windows'
shell: pwsh
run: |
Compress-Archive -Path "release/${{ steps.package.outputs.stem }}" -DestinationPath "${{ steps.package.outputs.stem }}.zip"
- uses: actions/upload-artifact@v7
if: env.PACKAGE_RELEASE == 'true'
with:
name: ${{ steps.package.outputs.stem }}
path: ${{ steps.package.outputs.stem }}.${{ matrix.suffix }}