add support for SETUP_UV_SAVE_CACHE

This commit is contained in:
Kevin Stillhammer
2025-09-14 16:00:45 +02:00
parent b75a909f75
commit 6db51338cf
3 changed files with 76 additions and 27 deletions

View File

@ -561,6 +561,42 @@ jobs:
env: env:
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }} CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
test-setup-cache-save-cache-env:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Setup with cache
uses: ./
with:
enable-cache: true
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-save-cache-env
- run: uv sync
working-directory: __tests__/fixtures/uv-project
shell: bash
- run: echo "SETUP_UV_SAVE_CACHE=false" >> $GITHUB_ENV
test-restore-cache-save-cache-env:
runs-on: ubuntu-latest
needs: test-setup-cache-save-cache-env
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Restore with cache
id: restore
uses: ./
with:
enable-cache: true
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-save-cache-env
- name: Cache was not hit
run: |
if [ "$CACHE_HIT" == "true" ]; then
exit 1
fi
env:
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
test-setup-cache-restore-cache-false: test-setup-cache-restore-cache-false:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -823,6 +859,8 @@ jobs:
- test-restore-cache-save-cache-false - test-restore-cache-save-cache-false
- test-setup-cache-restore-cache-false - test-setup-cache-restore-cache-false
- test-restore-cache-restore-cache-false - test-restore-cache-restore-cache-false
- test-setup-cache-save-cache-env
- test-restore-cache-save-cache-env
- test-setup-cache-local - test-setup-cache-local
- test-restore-cache-local - test-restore-cache-local
- test-tilde-expansion-cache-local-path - test-tilde-expansion-cache-local-path

32
dist/save-cache/index.js generated vendored
View File

@ -90021,21 +90021,25 @@ const exec = __importStar(__nccwpck_require__(5236));
const restore_cache_1 = __nccwpck_require__(5391); const restore_cache_1 = __nccwpck_require__(5391);
const inputs_1 = __nccwpck_require__(9612); const inputs_1 = __nccwpck_require__(9612);
async function run() { async function run() {
if (!inputs_1.enableCache) {
return;
}
if (!inputs_1.saveCache) {
core.info("save-cache is false. Skipping save cache step.");
return;
}
if (process.env.SETUP_UV_SAVE_CACHE === "false") {
core.info("Environment variable SETUP_UV_SAVE_CACHE is set to false. Skipping save cache step.");
return;
}
try { try {
if (inputs_1.enableCache) { await saveCache();
if (inputs_1.saveCache) { // node will stay alive if any promises are not resolved,
await saveCache(); // which is a possibility if HTTP requests are dangling
} // due to retries or timeouts. We know that if we got here
else { // that all promises that we care about have successfully
core.info("save-cache is false. Skipping save cache step."); // resolved, so simply exit with success.
} process.exit(0);
// node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling
// due to retries or timeouts. We know that if we got here
// that all promises that we care about have successfully
// resolved, so simply exit with success.
process.exit(0);
}
} }
catch (error) { catch (error) {
const err = error; const err = error;

View File

@ -15,20 +15,27 @@ import {
} from "./utils/inputs"; } from "./utils/inputs";
export async function run(): Promise<void> { export async function run(): Promise<void> {
if (!enableCache) {
return;
}
if (!shouldSaveCache) {
core.info("save-cache is false. Skipping save cache step.");
return;
}
if (process.env.SETUP_UV_SAVE_CACHE === "false") {
core.info(
"Environment variable SETUP_UV_SAVE_CACHE is set to false. Skipping save cache step.",
);
return;
}
try { try {
if (enableCache) { await saveCache();
if (shouldSaveCache) { // node will stay alive if any promises are not resolved,
await saveCache(); // which is a possibility if HTTP requests are dangling
} else { // due to retries or timeouts. We know that if we got here
core.info("save-cache is false. Skipping save cache step."); // that all promises that we care about have successfully
} // resolved, so simply exit with success.
// node will stay alive if any promises are not resolved, process.exit(0);
// which is a possibility if HTTP requests are dangling
// due to retries or timeouts. We know that if we got here
// that all promises that we care about have successfully
// resolved, so simply exit with success.
process.exit(0);
}
} catch (error) { } catch (error) {
const err = error as Error; const err = error as Error;
core.setFailed(err.message); core.setFailed(err.message);