Skip to content

Commit 38dbe75

Browse files
authored
Add stable and oldstable aliases (#300)
1 parent 30c39bf commit 38dbe75

File tree

10 files changed

+354
-45
lines changed

10 files changed

+354
-45
lines changed

.github/workflows/versions.yml

+51
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,57 @@ on:
1212
- cron: 0 0 * * *
1313

1414
jobs:
15+
stable:
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [ubuntu-latest, windows-latest, macos-latest]
21+
steps:
22+
- uses: actions/checkout@v3
23+
- name: Setup Go Stable
24+
uses: ./
25+
with:
26+
go-version: stable
27+
- name: Verify Go
28+
run: go version
29+
30+
oldstable:
31+
runs-on: ${{ matrix.os }}
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
os: [ubuntu-latest, windows-latest, macos-latest]
36+
steps:
37+
- uses: actions/checkout@v3
38+
- name: Setup Go oldStable
39+
uses: ./
40+
with:
41+
go-version: oldstable
42+
- name: Verify Go
43+
run: go version
44+
45+
aliases-arch:
46+
runs-on: ${{ matrix.os }}
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
os: [ubuntu-latest, windows-latest, macos-latest]
51+
version: [stable, oldstable]
52+
architecture: [x64, x32]
53+
exclude:
54+
- os: macos-latest
55+
architecture: x32
56+
steps:
57+
- uses: actions/checkout@v3
58+
- name: Setup Go ${{ matrix.version }} ${{ matrix.architecture }}
59+
uses: ./
60+
with:
61+
go-version: ${{ matrix.version }}
62+
architecture: ${{ matrix.architecture }}
63+
- name: Verify Go
64+
run: go version
65+
1566
local-cache:
1667
name: Setup local-cache version
1768
runs-on: ${{ matrix.os }}

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The V3 edition of the action offers:
1616
- Proxy support
1717
- Check latest version
1818
- Caching packages dependencies
19+
- stable and oldstable aliases
1920
- Bug Fixes (including issues around version matching and semver)
2021

2122
The action will first check the local cache for a version match. If a version is not found locally, it will pull it from the `main` branch of the [go-versions](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository. On miss or failure, it will fall back to downloading directly from [go dist](https://storage.googleapis.com/golang). To change the default behavior, please use the [check-latest input](#check-latest-version).
@@ -95,6 +96,33 @@ steps:
9596
check-latest: true
9697
- run: go run hello.go
9798
```
99+
100+
## Using stable/oldstable aliases
101+
102+
If `stable` is provided, action will get the latest stable version from the [`go-versions`](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository manifest.
103+
104+
If `oldstable` is provided, when current release is 1.19.x, action will resolve version as 1.18.x, where x is the latest patch release.
105+
106+
**Note:** using these aliases will result in same version as using corresponding minor release with `check-latest` input set to `true`
107+
108+
```yaml
109+
steps:
110+
- uses: actions/checkout@v3
111+
- uses: actions/setup-go@v3
112+
with:
113+
go-version: 'stable'
114+
- run: go run hello.go
115+
```
116+
117+
```yaml
118+
steps:
119+
- uses: actions/checkout@v3
120+
- uses: actions/setup-go@v3
121+
with:
122+
go-version: 'oldstable'
123+
- run: go run hello.go
124+
```
125+
98126
## Caching dependency files and build outputs:
99127

100128
The action has a built-in functionality for caching and restoring go modules and build outputs. It uses [actions/cache](https://github.com/actions/cache) under the hood but requires less configuration settings. The `cache` input is optional, and caching is turned off by default.

__tests__/setup-go.test.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('setup-go', () => {
4141
let mkdirpSpy: jest.SpyInstance;
4242
let execSpy: jest.SpyInstance;
4343
let getManifestSpy: jest.SpyInstance;
44+
let getAllVersionsSpy: jest.SpyInstance;
4445

4546
beforeAll(async () => {
4647
process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
@@ -83,6 +84,7 @@ describe('setup-go', () => {
8384
cacheSpy = jest.spyOn(tc, 'cacheDir');
8485
getSpy = jest.spyOn(im, 'getVersionsDist');
8586
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
87+
getAllVersionsSpy = jest.spyOn(im, 'getManifest');
8688

8789
// io
8890
whichSpy = jest.spyOn(io, 'which');
@@ -700,7 +702,7 @@ describe('setup-go', () => {
700702

701703
findSpy.mockImplementation(() => '');
702704
dlSpy.mockImplementation(async () => '/some/temp/path');
703-
const toolPath = path.normalize('/cache/go/1.17.5/x64');
705+
const toolPath = path.normalize('/cache/go/1.17.6/x64');
704706
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
705707
cacheSpy.mockImplementation(async () => toolPath);
706708

@@ -779,6 +781,7 @@ describe('setup-go', () => {
779781
getManifestSpy.mockImplementation(() => {
780782
throw new Error('Unable to download manifest');
781783
});
784+
getAllVersionsSpy.mockImplementationOnce(() => undefined);
782785

783786
dlSpy.mockImplementation(async () => '/some/temp/path');
784787
let toolPath = path.normalize('/cache/go/1.13.7/x64');
@@ -926,5 +929,32 @@ use .
926929
);
927930
}
928931
}, 100000);
932+
933+
it.each(['stable', 'oldstable'])(
934+
'acquires latest go version with %s go-version input',
935+
async (alias: string) => {
936+
const arch = 'x64';
937+
os.platform = 'darwin';
938+
os.arch = arch;
939+
940+
inputs['go-version'] = alias;
941+
inputs['architecture'] = os.arch;
942+
943+
// ... but not in the local cache
944+
findSpy.mockImplementation(() => '');
945+
946+
dlSpy.mockImplementation(async () => '/some/temp/path');
947+
let toolPath = path.normalize(`/cache/go/${alias}/${arch}`);
948+
cacheSpy.mockImplementation(async () => toolPath);
949+
950+
await main.run();
951+
952+
const releaseIndex = alias === 'stable' ? 0 : 1;
953+
954+
expect(logSpy).toHaveBeenCalledWith(
955+
`${alias} version resolved as ${goTestManifest[releaseIndex].version}`
956+
);
957+
}
958+
);
929959
});
930960
});

dist/cache-save/index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -60313,7 +60313,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
6031360313
var __importStar = (this && this.__importStar) || function (mod) {
6031460314
if (mod && mod.__esModule) return mod;
6031560315
var result = {};
60316-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
60316+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
6031760317
__setModuleDefault(result, mod);
6031860318
return result;
6031960319
};
@@ -60418,7 +60418,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
6041860418
var __importStar = (this && this.__importStar) || function (mod) {
6041960419
if (mod && mod.__esModule) return mod;
6042060420
var result = {};
60421-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
60421+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
6042260422
__setModuleDefault(result, mod);
6042360423
return result;
6042460424
};
@@ -60437,7 +60437,7 @@ const cache = __importStar(__nccwpck_require__(7799));
6043760437
const core = __importStar(__nccwpck_require__(2186));
6043860438
const exec = __importStar(__nccwpck_require__(1514));
6043960439
const package_managers_1 = __nccwpck_require__(6663);
60440-
exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
60440+
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
6044160441
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
6044260442
if (exitCode) {
6044360443
stderr = !stderr.trim()
@@ -60447,21 +60447,24 @@ exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, fu
6044760447
}
6044860448
return stdout.trim();
6044960449
});
60450-
exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
60450+
exports.getCommandOutput = getCommandOutput;
60451+
const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
6045160452
if (!package_managers_1.supportedPackageManagers[packageManager]) {
6045260453
throw new Error(`It's not possible to use ${packageManager}, please, check correctness of the package manager name spelling.`);
6045360454
}
6045460455
const obtainedPackageManager = package_managers_1.supportedPackageManagers[packageManager];
6045560456
return obtainedPackageManager;
6045660457
});
60457-
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
60458+
exports.getPackageManagerInfo = getPackageManagerInfo;
60459+
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
6045860460
let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
6045960461
const emptyPaths = pathList.filter(item => !item);
6046060462
if (emptyPaths.length) {
6046160463
throw new Error(`Could not get cache folder paths.`);
6046260464
}
6046360465
return pathList;
6046460466
});
60467+
exports.getCacheDirectoryPath = getCacheDirectoryPath;
6046560468
function isGhes() {
6046660469
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
6046760470
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';

0 commit comments

Comments
 (0)