Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V dmshib/fix test for aliases #12

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
546aac7
Add stable and oldstable aliases
panticmilos Nov 20, 2022
4fd17ff
Remove .gitignore changes
panticmilos Nov 20, 2022
e0cb28b
Update package lock json
panticmilos Nov 20, 2022
d33323e
Remove unnecessary variables
panticmilos Nov 20, 2022
5552b45
Introduce new stable alias type
panticmilos Nov 20, 2022
317adaa
Apply PR suggestions
panticmilos Nov 21, 2022
46c78a9
Apply PR suggestions
panticmilos Nov 21, 2022
ee153a7
Add check latest check
panticmilos Nov 21, 2022
84f83e7
Add check latest check
panticmilos Nov 21, 2022
9b762a9
Add check latest check
panticmilos Nov 21, 2022
58547ff
Add documentation
panticmilos Nov 21, 2022
6590366
Update docs
panticmilos Nov 21, 2022
9d73e82
Update docs
panticmilos Nov 21, 2022
a29996a
Apply PR suggestions
panticmilos Nov 23, 2022
18c62c8
Return alias condition to main
panticmilos Nov 23, 2022
17fabf6
Move condition to the installer
panticmilos Nov 24, 2022
f1f69d4
Apply internal discussion agreements
panticmilos Nov 25, 2022
ece959c
Rebuild dist
panticmilos Nov 25, 2022
b7bdf8d
add type conversion
dmitry-shibanov Nov 29, 2022
eb4d2dd
possible fix
dmitry-shibanov Nov 29, 2022
f623296
minor changes
dmitry-shibanov Dec 5, 2022
a965b3d
minor fix
dmitry-shibanov Dec 5, 2022
6cc33f6
change prettier version
dmitry-shibanov Dec 5, 2022
487336c
remove logs and rebuild
dmitry-shibanov Dec 5, 2022
3a18a01
format code
dmitry-shibanov Dec 5, 2022
9e85e1c
fix returning values
dmitry-shibanov Dec 6, 2022
85c684e
minor fixes
dmitry-shibanov Dec 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@ on:
- cron: 0 0 * * *

jobs:
stable:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- name: Setup Go and check latest
uses: ./
with:
go-version: stable
- name: Verify Go
run: go version

oldstable:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- name: Setup Go and check latest
uses: ./
with:
go-version: oldstable
- name: Verify Go
run: go version

local-cache:
name: Setup local-cache version
runs-on: ${{ matrix.os }}
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The V3 edition of the action offers:
- Proxy support
- Check latest version
- Caching packages dependencies
- stable and oldstable aliases
- Bug Fixes (including issues around version matching and semver)

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).
Expand Down Expand Up @@ -95,6 +96,33 @@ steps:
check-latest: true
- run: go run hello.go
```

## Using stable/oldstable aliases

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.

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.

**Note:** using these aliases will result in same version as using corresponding minor release with `check-latest` input set to `true`

```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 'stable'
- run: go run hello.go
```

```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 'oldstable'
- run: go run hello.go
```

## Caching dependency files and build outputs:

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.
Expand Down
32 changes: 31 additions & 1 deletion __tests__/setup-go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('setup-go', () => {
let mkdirpSpy: jest.SpyInstance;
let execSpy: jest.SpyInstance;
let getManifestSpy: jest.SpyInstance;
let getAllVersionsSpy: jest.SpyInstance;

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

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

findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
const toolPath = path.normalize('/cache/go/1.17.5/x64');
const toolPath = path.normalize('/cache/go/1.17.6/x64');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);

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

dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.13.7/x64');
Expand Down Expand Up @@ -926,5 +929,32 @@ use .
);
}
}, 100000);

it.each(['stable', 'oldstable'])(
'acquires latest go version with %s go-version input',
async (alias: string) => {
const arch = 'x64';
os.platform = 'darwin';
os.arch = arch;

inputs['go-version'] = alias;
inputs['architecture'] = os.arch;

// ... but not in the local cache
findSpy.mockImplementation(() => '');

dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize(`/cache/go/${alias}/${arch}`);
cacheSpy.mockImplementation(async () => toolPath);

await main.run();

const releaseIndex = alias === 'stable' ? 0 : 1;

expect(logSpy).toHaveBeenCalledWith(
`${alias} version resolved as ${goTestManifest[releaseIndex].version}`
);
}
);
});
});
13 changes: 8 additions & 5 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60313,7 +60313,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Expand Down Expand Up @@ -60418,7 +60418,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Expand All @@ -60437,7 +60437,7 @@ const cache = __importStar(__nccwpck_require__(7799));
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
const package_managers_1 = __nccwpck_require__(6663);
exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
const getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
let { stdout, stderr, exitCode } = yield exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true });
if (exitCode) {
stderr = !stderr.trim()
Expand All @@ -60447,21 +60447,24 @@ exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, fu
}
return stdout.trim();
});
exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
exports.getCommandOutput = getCommandOutput;
const getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
if (!package_managers_1.supportedPackageManagers[packageManager]) {
throw new Error(`It's not possible to use ${packageManager}, please, check correctness of the package manager name spelling.`);
}
const obtainedPackageManager = package_managers_1.supportedPackageManagers[packageManager];
return obtainedPackageManager;
});
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
exports.getPackageManagerInfo = getPackageManagerInfo;
const getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map(command => exports.getCommandOutput(command)));
const emptyPaths = pathList.filter(item => !item);
if (emptyPaths.length) {
throw new Error(`Could not get cache folder paths.`);
}
return pathList;
});
exports.getCacheDirectoryPath = getCacheDirectoryPath;
function isGhes() {
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
Expand Down
Loading