Compare commits

...

4 Commits

Author SHA1 Message Date
Roberto Tyley 887947024c
Merge ed3ab602f8 into 99b8673ff6 2024-03-17 15:40:39 +07:00
mahabaleshwars 99b8673ff6
Patch for java version file (#610)
* patch to extract file from other location

* patch to extract filename from other directories

* removed code failing checks

* changed the validation for .java-version type
2024-03-14 09:12:58 -05:00
Roberto Tyley ed3ab602f8 Is version.sbt still being included... 2024-02-22 15:57:56 +00:00
Roberto Tyley f228ab54b9 Avoid sbt cache being invalidated for a library that is only incrementing it's own version
While working on https://github.com/guardian/gha-scala-library-release-workflow I noticed that no matter how many times I ran the workflow, `actions/setup-java` would always report `sbt cache is not found`, even if there had been no substantial change in the project - simply that `version.sbt` (the file used by https://github.com/sbt/sbt-release) had the version number in it incremented (as in b2152325ba).

This meant that turning on `cache: sbt` would actually slow the workflow considerably, as it would never benefit from the cache being present, and would always have to save it, which could take 2-3 minutes - even though it can't take advantage of the data it's saving.

As such, it would be great to exclude `version.sbt` files from the cache hash key.

Background: `cache: sbt` was orginally introduced with https://github.com/actions/setup-java/pull/302
2023-12-07 12:06:46 +00:00
5 changed files with 4560 additions and 4389 deletions

4464
dist/cleanup/index.js vendored

File diff suppressed because it is too large Load Diff

BIN
dist/index.js generated vendored Normal file

Binary file not shown.

4464
dist/setup/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -58,7 +58,8 @@ const supportedPackageManager: PackageManager[] = [
'**/*.sbt',
'**/project/build.properties',
'**/project/**.scala',
'**/project/**.sbt'
'**/project/**.sbt',
'!**/version.sbt' // releasing a new version of a library project shouldn't invalidate the entire sbt cache
]
}
];
@ -92,13 +93,15 @@ async function computeCacheKey(
const pattern = cacheDependencyPath
? cacheDependencyPath.trim().split('\n')
: packageManager.pattern;
const fileHash = await glob.hashFiles(pattern.join('\n'));
const fileHash = await glob.hashFiles(pattern.join('\n'), undefined, undefined, true);
if (!fileHash) {
throw new Error(
`No file in ${process.cwd()} matched to [${pattern}], make sure you have checked out the target repository`
);
}
return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${packageManager.id}-${fileHash}`;
const cacheKey = `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${packageManager.id}-${fileHash}`;
core.info(`cacheKey is ${cacheKey}`);
return cacheKey;
}
/**

View File

@ -119,13 +119,17 @@ export function getVersionFromFileContent(
versionFile: string
): string | null {
let javaVersionRegExp: RegExp;
if (versionFile == '.tool-versions') {
function getFileName(versionFile: string) {
return path.basename(versionFile);
}
const versionFileName = getFileName(versionFile);
if (versionFileName == '.tool-versions') {
javaVersionRegExp =
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
} else if (versionFile == '.java-version') {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
} else {
throw new Error('Invalid version file');
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}
const fileContent = content.match(javaVersionRegExp)?.groups?.version