mirror of
https://github.com/actions/setup-go.git
synced 2025-04-23 17:40:50 +00:00
Fix parseGoVersionFile
This commit is contained in:
parent
fabe2129ee
commit
dbe1872ad4
3 changed files with 18 additions and 16 deletions
|
@ -797,7 +797,9 @@ exclude example.com/thismodule v1.3.0
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Setup go stable version spec 1.14');
|
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.14');
|
||||||
|
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.14...');
|
||||||
|
expect(logSpy).toHaveBeenCalledWith('matching 1.14...');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reads version from .go-version', async () => {
|
it('reads version from .go-version', async () => {
|
||||||
|
@ -806,9 +808,9 @@ exclude example.com/thismodule v1.3.0
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.13.0');
|
||||||
'Setup go stable version spec 1.13.0'
|
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.13.0...');
|
||||||
);
|
expect(logSpy).toHaveBeenCalledWith('matching 1.13.0...');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is overwritten by go-version', async () => {
|
it('is overwritten by go-version', async () => {
|
||||||
|
@ -818,9 +820,9 @@ exclude example.com/thismodule v1.3.0
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.13.1');
|
||||||
'Setup go stable version spec 1.13.1'
|
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.13.1...');
|
||||||
);
|
expect(logSpy).toHaveBeenCalledWith('matching 1.13.1...');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reports a read failure', async () => {
|
it('reports a read failure', async () => {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import * as path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import * as httpm from '@actions/http-client';
|
import * as httpm from '@actions/http-client';
|
||||||
import * as sys from './system';
|
import * as sys from './system';
|
||||||
|
import fs from 'fs';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
|
||||||
type InstallationType = 'dist' | 'manifest';
|
type InstallationType = 'dist' | 'manifest';
|
||||||
|
@ -299,11 +300,13 @@ export function makeSemver(version: string): string {
|
||||||
return fullVersion;
|
return fullVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseGoVersionFile(contents: string, isMod: boolean): string {
|
export function parseGoVersionFile(versionFilePath: string): string {
|
||||||
if (!isMod) {
|
const contents = fs.readFileSync(versionFilePath).toString();
|
||||||
return contents.trim();
|
|
||||||
|
if (path.basename(versionFilePath) === 'go.mod') {
|
||||||
|
const match = contents.match(/^go (\d+(\.\d+)*)/m);
|
||||||
|
return match ? match[1] : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const match = contents.match(/^go (\d+(\.\d+)*)/m);
|
return contents.trim();
|
||||||
return match ? match[1] : '';
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,10 +120,7 @@ function resolveVersionInput(): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (versionFilePath) {
|
if (versionFilePath) {
|
||||||
version = installer.parseGoVersionFile(
|
version = installer.parseGoVersionFile(versionFilePath);
|
||||||
fs.readFileSync(versionFilePath).toString(),
|
|
||||||
path.basename(versionFilePath) === 'go.mod'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
|
|
Loading…
Add table
Reference in a new issue