mirror of
https://github.com/actions/setup-go.git
synced 2026-02-04 22:48:21 +00:00
Add support for rc and beta versions in go.mod file
The regex in `parseGoVersionFile()` didn't consider rc and beta versions. The regex has been extended. In `findMatch()` the match is checked using `semver.satisfies()`. But `semver.satisfies()` doesn't no about Go's non-semver rc and beta version formats (1.16c1 instead of 1.16.0-rc.1). We cannot use `makeSemver()` on `versionSpec` and compare the result using `semver.satisfies()` because `versionSpec` could be, well, a spec. Instead we first check if there is a strict match between the candidate version and the versionSpec. Fixes #525.
This commit is contained in:
parent
7a3fe6cf4c
commit
90e09cb0fc
4 changed files with 228 additions and 6 deletions
|
|
@ -423,7 +423,10 @@ export async function findMatch(
|
|||
const version = makeSemver(candidate.version);
|
||||
|
||||
core.debug(`check ${version} satisfies ${versionSpec}`);
|
||||
if (semver.satisfies(version, versionSpec)) {
|
||||
if (
|
||||
candidate.version.replace(/^go/, '') === versionSpec ||
|
||||
semver.satisfies(version, versionSpec)
|
||||
) {
|
||||
goFile = candidate.files.find(file => {
|
||||
core.debug(
|
||||
`${file.arch}===${archFilter} && ${file.os}===${platFilter}`
|
||||
|
|
@ -511,7 +514,7 @@ export function parseGoVersionFile(versionFilePath: string): string {
|
|||
}
|
||||
|
||||
// go directive: https://go.dev/ref/mod#go-mod-file-go
|
||||
const matchGo = contents.match(/^go (\d+(\.\d+)*)/m);
|
||||
const matchGo = contents.match(/^go (\d+(\.\d+)*(?:\.\d+|(beta|rc)\d+)?)/m);
|
||||
return matchGo ? matchGo[1] : '';
|
||||
} else if (path.basename(versionFilePath) === '.tool-versions') {
|
||||
const match = contents.match(/^golang\s+([^\n#]+)/m);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue