mirror of
https://code.forgejo.org/actions/setup-go.git
synced 2024-12-24 22:12:13 -05:00
Extend go-version to accept go.mod files
This commit is contained in:
parent
0a12ed9d6a
commit
8e6a7f3c64
4 changed files with 50 additions and 53 deletions
|
@ -868,18 +868,6 @@ use .
|
|||
expect(logSpy).toHaveBeenCalledWith('matching 1.19...');
|
||||
});
|
||||
|
||||
it('reads version from .go-version', async () => {
|
||||
inputs['go-version-file'] = '.go-version';
|
||||
existsSpy.mockImplementation(() => true);
|
||||
readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`));
|
||||
|
||||
await main.run();
|
||||
|
||||
expect(logSpy).toHaveBeenCalledWith('Setup go 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 () => {
|
||||
inputs['go-version'] = '1.13.1';
|
||||
inputs['go-version-file'] = 'go.mod';
|
||||
|
@ -904,6 +892,29 @@ use .
|
|||
);
|
||||
});
|
||||
|
||||
it('go-version accepts a go.mod file', async () => {
|
||||
inputs['go-version'] = 'go.mod';
|
||||
existsSpy.mockImplementation(() => true);
|
||||
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
|
||||
|
||||
await main.run();
|
||||
|
||||
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.14');
|
||||
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.14...');
|
||||
expect(logSpy).toHaveBeenCalledWith('matching 1.14...');
|
||||
});
|
||||
|
||||
it('go-version reports a read failure', async () => {
|
||||
inputs['go-version'] = 'path/to/go.mod';
|
||||
existsSpy.mockImplementation(() => false);
|
||||
|
||||
await main.run();
|
||||
|
||||
expect(cnSpy).toHaveBeenCalledWith(
|
||||
`::error::The specified go version file at: path/to/go.mod does not exist${osm.EOL}`
|
||||
);
|
||||
});
|
||||
|
||||
it('acquires specified architecture of go', async () => {
|
||||
for (const {arch, version, osSpec} of [
|
||||
{arch: 'amd64', version: '1.13.7', osSpec: 'linux'},
|
||||
|
|
30
dist/setup/index.js
vendored
30
dist/setup/index.js
vendored
|
@ -88244,7 +88244,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.resolveStableVersionInput = exports.parseGoVersionFile = exports.makeSemver = exports.getVersionsDist = exports.findMatch = exports.getInfoFromManifest = exports.getManifest = exports.extractGoArchive = exports.getGo = void 0;
|
||||
exports.resolveStableVersionInput = exports.makeSemver = exports.getVersionsDist = exports.findMatch = exports.getInfoFromManifest = exports.getManifest = exports.extractGoArchive = exports.getGo = void 0;
|
||||
const tc = __importStar(__nccwpck_require__(7784));
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const path = __importStar(__nccwpck_require__(1017));
|
||||
|
@ -88540,16 +88540,6 @@ function makeSemver(version) {
|
|||
return fullVersion;
|
||||
}
|
||||
exports.makeSemver = makeSemver;
|
||||
function parseGoVersionFile(versionFilePath) {
|
||||
const contents = fs_1.default.readFileSync(versionFilePath).toString();
|
||||
if (path.basename(versionFilePath) === 'go.mod' ||
|
||||
path.basename(versionFilePath) === 'go.work') {
|
||||
const match = contents.match(/^go (\d+(\.\d+)*)/m);
|
||||
return match ? match[1] : '';
|
||||
}
|
||||
return contents.trim();
|
||||
}
|
||||
exports.parseGoVersionFile = parseGoVersionFile;
|
||||
function resolveStableVersionDist(versionSpec, arch) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const archFilter = sys.getArch(arch);
|
||||
|
@ -88749,18 +88739,22 @@ function parseGoVersion(versionString) {
|
|||
exports.parseGoVersion = parseGoVersion;
|
||||
function resolveVersionInput() {
|
||||
let version = core.getInput('go-version');
|
||||
const versionFilePath = core.getInput('go-version-file');
|
||||
let versionFilePath = core.getInput('go-version-file');
|
||||
if (version && versionFilePath) {
|
||||
core.warning('Both go-version and go-version-file inputs are specified, only go-version will be used');
|
||||
}
|
||||
if (version) {
|
||||
return version;
|
||||
versionFilePath = '';
|
||||
}
|
||||
if (versionFilePath) {
|
||||
if (!fs_1.default.existsSync(versionFilePath)) {
|
||||
throw new Error(`The specified go version file at: ${versionFilePath} does not exist`);
|
||||
version = versionFilePath;
|
||||
}
|
||||
if (path_1.default.basename(version) === 'go.mod' ||
|
||||
path_1.default.basename(version) === 'go.work') {
|
||||
if (!fs_1.default.existsSync(version)) {
|
||||
throw new Error(`The specified go version file at: ${version} does not exist`);
|
||||
}
|
||||
version = installer.parseGoVersionFile(versionFilePath);
|
||||
const contents = fs_1.default.readFileSync(version).toString();
|
||||
const match = contents.match(/^go (\d+(\.\d+)*)/m);
|
||||
return match ? match[1] : '';
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
|
|
@ -417,20 +417,6 @@ export function makeSemver(version: string): string {
|
|||
return fullVersion;
|
||||
}
|
||||
|
||||
export function parseGoVersionFile(versionFilePath: string): string {
|
||||
const contents = fs.readFileSync(versionFilePath).toString();
|
||||
|
||||
if (
|
||||
path.basename(versionFilePath) === 'go.mod' ||
|
||||
path.basename(versionFilePath) === 'go.work'
|
||||
) {
|
||||
const match = contents.match(/^go (\d+(\.\d+)*)/m);
|
||||
return match ? match[1] : '';
|
||||
}
|
||||
|
||||
return contents.trim();
|
||||
}
|
||||
|
||||
async function resolveStableVersionDist(versionSpec: string, arch: string) {
|
||||
const archFilter = sys.getArch(arch);
|
||||
const platFilter = sys.getPlatform();
|
||||
|
|
24
src/main.ts
24
src/main.ts
|
@ -137,25 +137,31 @@ export function parseGoVersion(versionString: string): string {
|
|||
|
||||
function resolveVersionInput(): string {
|
||||
let version = core.getInput('go-version');
|
||||
const versionFilePath = core.getInput('go-version-file');
|
||||
let versionFilePath = core.getInput('go-version-file');
|
||||
|
||||
if (version && versionFilePath) {
|
||||
core.warning(
|
||||
'Both go-version and go-version-file inputs are specified, only go-version will be used'
|
||||
);
|
||||
versionFilePath = '';
|
||||
}
|
||||
|
||||
if (version) {
|
||||
return version;
|
||||
}
|
||||
|
||||
if (versionFilePath) {
|
||||
if (!fs.existsSync(versionFilePath)) {
|
||||
version = versionFilePath;
|
||||
}
|
||||
|
||||
if (
|
||||
path.basename(version) === 'go.mod' ||
|
||||
path.basename(version) === 'go.work'
|
||||
) {
|
||||
if (!fs.existsSync(version)) {
|
||||
throw new Error(
|
||||
`The specified go version file at: ${versionFilePath} does not exist`
|
||||
`The specified go version file at: ${version} does not exist`
|
||||
);
|
||||
}
|
||||
version = installer.parseGoVersionFile(versionFilePath);
|
||||
|
||||
const contents = fs.readFileSync(version).toString();
|
||||
const match = contents.match(/^go (\d+(\.\d+)*)/m);
|
||||
return match ? match[1] : '';
|
||||
}
|
||||
|
||||
return version;
|
||||
|
|
Loading…
Reference in a new issue