Default to enable-cache: true on GitHub hosted runners (#193)

Closes: #54
This commit is contained in:
Kevin Stillhammer 2024-12-13 20:12:42 +01:00 committed by GitHub
parent 3460fe1a9a
commit e3017a763c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 51 additions and 10 deletions

View File

@ -11,18 +11,26 @@ concurrency:
jobs:
test-setup-cache:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
enable-cache: [ "true", "false", "auto" ]
os: ["ubuntu-latest", "selfhosted-ubuntu-arm64"]
steps:
- uses: actions/checkout@v4
- name: Setup with cache
uses: ./
with:
enable-cache: true
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache
enable-cache: ${{ matrix.enable-cache }}
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-${{ matrix.os }}-${{ matrix.enable-cache }}
- run: uv sync
working-directory: __tests__/fixtures/uv-project
test-restore-cache:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
enable-cache: [ "true", "false", "auto" ]
os: [ "ubuntu-latest", "selfhosted-ubuntu-arm64" ]
needs: test-setup-cache
steps:
- uses: actions/checkout@v4
@ -30,15 +38,24 @@ jobs:
id: restore
uses: ./
with:
enable-cache: true
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache
enable-cache: ${{ matrix.enable-cache }}
cache-suffix: ${{ github.run_id }}-${{ github.run_attempt }}-test-setup-cache-${{ matrix.os }}-${{ matrix.enable-cache }}
- name: Cache was hit
if: ${{ matrix.enable-cache == 'true' || (matrix.enable-cache == 'auto' && matrix.os == 'ubuntu-latest') }}
run: |
if [ "$CACHE_HIT" != "true" ]; then
exit 1
fi
env:
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
- name: Cache was not hit
if: ${{ matrix.enable-cache == 'false' || (matrix.enable-cache == 'auto' && matrix.os == 'selfhosted-ubuntu-arm64') }}
run: |
if [ "$CACHE_HIT" == "true" ]; then
exit 1
fi
env:
CACHE_HIT: ${{ steps.restore.outputs.cache-hit }}
- run: uv sync
working-directory: __tests__/fixtures/uv-project
test-setup-cache-requirements-txt:

View File

@ -84,6 +84,8 @@ jobs:
with:
version: "0.3.2"
checksum: ${{ matrix.checksum }}
- run: uv sync
working-directory: __tests__/fixtures/uv-project
test-with-explicit-token:
runs-on: ubuntu-latest
steps:

View File

@ -20,7 +20,7 @@ inputs:
default: ${{ github.token }}
enable-cache:
description: "Enable caching of the uv cache"
default: "false"
default: "auto"
cache-dependency-glob:
description:
"Glob pattern to match files relative to the repository root to control

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

@ -91803,7 +91803,7 @@ const node_path_1 = __importDefault(__nccwpck_require__(6760));
exports.version = core.getInput("version");
exports.pythonVersion = core.getInput("python-version");
exports.checkSum = core.getInput("checksum");
exports.enableCache = core.getInput("enable-cache") === "true";
exports.enableCache = getEnableCache();
exports.cacheSuffix = core.getInput("cache-suffix") || "";
exports.cacheLocalPath = getCacheLocalPath();
exports.cacheDependencyGlob = core.getInput("cache-dependency-glob");
@ -91812,6 +91812,13 @@ exports.ignoreNothingToCache = core.getInput("ignore-nothing-to-cache") === "tru
exports.toolBinDir = getToolBinDir();
exports.toolDir = getToolDir();
exports.githubToken = core.getInput("github-token");
function getEnableCache() {
const enableCacheInput = core.getInput("enable-cache");
if (enableCacheInput === "auto") {
return process.env.RUNNER_ENVIRONMENT === "github-hosted";
}
return enableCacheInput === "true";
}
function getToolBinDir() {
const toolBinDirInput = core.getInput("tool-bin-dir");
if (toolBinDirInput !== "") {

9
dist/setup/index.js generated vendored
View File

@ -99334,7 +99334,7 @@ const node_path_1 = __importDefault(__nccwpck_require__(6760));
exports.version = core.getInput("version");
exports.pythonVersion = core.getInput("python-version");
exports.checkSum = core.getInput("checksum");
exports.enableCache = core.getInput("enable-cache") === "true";
exports.enableCache = getEnableCache();
exports.cacheSuffix = core.getInput("cache-suffix") || "";
exports.cacheLocalPath = getCacheLocalPath();
exports.cacheDependencyGlob = core.getInput("cache-dependency-glob");
@ -99343,6 +99343,13 @@ exports.ignoreNothingToCache = core.getInput("ignore-nothing-to-cache") === "tru
exports.toolBinDir = getToolBinDir();
exports.toolDir = getToolDir();
exports.githubToken = core.getInput("github-token");
function getEnableCache() {
const enableCacheInput = core.getInput("enable-cache");
if (enableCacheInput === "auto") {
return process.env.RUNNER_ENVIRONMENT === "github-hosted";
}
return enableCacheInput === "true";
}
function getToolBinDir() {
const toolBinDirInput = core.getInput("tool-bin-dir");
if (toolBinDirInput !== "") {

View File

@ -4,7 +4,7 @@ import path from "node:path";
export const version = core.getInput("version");
export const pythonVersion = core.getInput("python-version");
export const checkSum = core.getInput("checksum");
export const enableCache = core.getInput("enable-cache") === "true";
export const enableCache = getEnableCache();
export const cacheSuffix = core.getInput("cache-suffix") || "";
export const cacheLocalPath = getCacheLocalPath();
export const cacheDependencyGlob = core.getInput("cache-dependency-glob");
@ -15,6 +15,14 @@ export const toolBinDir = getToolBinDir();
export const toolDir = getToolDir();
export const githubToken = core.getInput("github-token");
function getEnableCache(): boolean {
const enableCacheInput = core.getInput("enable-cache");
if (enableCacheInput === "auto") {
return process.env.RUNNER_ENVIRONMENT === "github-hosted";
}
return enableCacheInput === "true";
}
function getToolBinDir(): string | undefined {
const toolBinDirInput = core.getInput("tool-bin-dir");
if (toolBinDirInput !== "") {