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

Fix check latest licenses #9

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v2

- name: Set Node.js 12.x
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: 12.x

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/licensed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install licensed
run: |
cd $RUNNER_TEMP
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.12.2/licensed-2.12.2-linux-x64.tar.gz
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.3.1/licensed-3.3.1-linux-x64.tar.gz
sudo tar -xzf licensed.tar.gz
sudo mv licensed /usr/local/bin/licensed
- run: licensed status
18 changes: 18 additions & 0 deletions .github/workflows/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ jobs:
run: __tests__/verify-go.sh ${{ matrix.go }}
shell: bash

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

setup-versions-from-manifest:
name: Setup ${{ matrix.go }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
node-version: 12
cache: npm

- name: npm install
run: npm install
- name: npm ci
run: npm ci

- name: Lint
run: npm run format-check
Expand Down
2 changes: 1 addition & 1 deletion .licenses/npm/@actions/core.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions .licenses/npm/@actions/http-client-1.0.11.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,25 @@ steps:
- uses: actions/checkout@master
- uses: actions/setup-go@v2
with:
go-version: '1.9.3' # The Go version to download (if necessary) and use.
go-version: '1.16.1' # The Go version to download (if necessary) and use.
- run: go run hello.go
```


Check latest version:
> In basic example, without `check-latest` flag, the action tries to resolve version from local cache firstly and download only if it is not found. Local cache on image is updated with a couple of weeks latency.
`check-latest` flag forces the action to check if the cached version is the latest one. It reduces latency significantly but it is much more likely to incur version downloading.
```yaml
steps:
- uses: actions/checkout@master
- uses: actions/setup-go@v2
with:
go-version: '1.14'
check-latest: true
- run: go run hello.go
```


Matrix Testing:
```yaml
jobs:
Expand All @@ -81,6 +96,16 @@ Specific versions: `1.15`, `1.16.1`, `1.17.0-rc2`, `1.16.0-beta1`
SemVer's version range syntax: `^1.13.1`
For more information about semantic versioning please refer [semver](https://github.com/npm/node-semver) documentation


# Keep in mind: latest, cached go compilers and semver notation.

The `setup-go` action doesn't install the latest matched version if the cached version matches one from WF file.

**For example:**
Currently, there is three go compilers on [Ubuntu 20.04.3 LTS](https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md) virtual environment: `1.15.15`, `1.16.12`, `1.17.5`.
When the `1.17.6` version will be out and there is `1.17.*` in `go-version` field, the cached `1.17.5` version will be used. Not the new one. Until the cached version will be updated to the latest `1.17.6`.
If you will specify fully `1.17.6`, the default installation process begins.

# License

The scripts and documentation in this project are released under the [MIT License](LICENSE)
Expand Down
25 changes: 25 additions & 0 deletions __tests__/data/versions-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
[
{
"version": "1.17.6",
"stable": true,
"release_url": "https://github.com/actions/go-versions/releases/tag/1.17.6-1668090892",
"files": [
{
"filename": "go-1.17.6-darwin-x64.tar.gz",
"arch": "x64",
"platform": "darwin",
"download_url": "https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-darwin-x64.tar.gz"
},
{
"filename": "go-1.17.6-linux-x64.tar.gz",
"arch": "x64",
"platform": "linux",
"download_url": "https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-linux-x64.tar.gz"
},
{
"filename": "go-1.17.6-win32-x64.zip",
"arch": "x64",
"platform": "win32",
"download_url": "https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-win32-x64.zip"
}
]
},
{
"version": "1.12.17",
"stable": true,
Expand Down
180 changes: 174 additions & 6 deletions __tests__/setup-go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('setup-go', () => {
let os = {} as any;

let inSpy: jest.SpyInstance;
let getBooleanInputSpy: jest.SpyInstance;
let findSpy: jest.SpyInstance;
let cnSpy: jest.SpyInstance;
let logSpy: jest.SpyInstance;
Expand All @@ -35,16 +36,19 @@ describe('setup-go', () => {
let execSpy: jest.SpyInstance;
let getManifestSpy: jest.SpyInstance;

beforeAll(() => {
process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
});
beforeAll(async () => {
process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
}, 100000);

beforeEach(() => {
process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out

// @actions/core
inputs = {};
inSpy = jest.spyOn(core, 'getInput');
inSpy.mockImplementation(name => inputs[name]);
getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
getBooleanInputSpy.mockImplementation(name => inputs[name]);

// node
os = {};
Expand Down Expand Up @@ -81,7 +85,7 @@ describe('setup-go', () => {
});
logSpy.mockImplementation(line => {
// uncomment to debug
// process.stderr.write('log:' + line + '\n');
process.stderr.write('log:' + line + '\n');
});
dbgSpy.mockImplementation(msg => {
// uncomment to see debug output
Expand All @@ -96,7 +100,7 @@ describe('setup-go', () => {
});

afterAll(async () => {
console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions
jest.restoreAllMocks();
}, 100000);

it('can find 1.9.7 from manifest on osx', async () => {
Expand Down Expand Up @@ -573,4 +577,168 @@ describe('setup-go', () => {
it('does not convert exact versions', async () => {
expect(im.makeSemver('1.13.1')).toBe('1.13.1');
});

describe('check-latest flag', () => {
it("use local version and don't check manifest if check-latest is not specified", async () => {
os.platform = 'linux';
os.arch = 'x64';

inputs['go-version'] = '1.16';
inputs['check-latest'] = false;

const toolPath = path.normalize('/cache/go/1.16.1/x64');
findSpy.mockReturnValue(toolPath);
await main.run();

expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
expect(logSpy).not.toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...'
);
});

it('check latest version and resolve it from local cache', async () => {
os.platform = 'linux';
os.arch = 'x64';

inputs['go-version'] = '1.16';
inputs['check-latest'] = true;

const toolPath = path.normalize('/cache/go/1.16.1/x64');
findSpy.mockReturnValue(toolPath);
dlSpy.mockImplementation(async () => '/some/temp/path');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);

await main.run();

expect(logSpy).toHaveBeenCalledWith('Setup go stable version spec 1.16');
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
});

it('check latest version and install it from manifest', async () => {
os.platform = 'linux';
os.arch = 'x64';

const versionSpec = '1.17';
const patchVersion = '1.17.6';
inputs['go-version'] = versionSpec;
inputs['stable'] = 'true';
inputs['check-latest'] = true;

findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
const toolPath = path.normalize('/cache/go/1.17.5/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
const expectedUrl =
'https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-darwin-x64.tar.gz';

await main.run();

expect(logSpy).toHaveBeenCalledWith(
`Setup go stable version spec ${versionSpec}`
);
expect(logSpy).toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...'
);
expect(logSpy).toHaveBeenCalledWith(`Resolved as '${patchVersion}'`);
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${patchVersion}...`
);
expect(logSpy).toHaveBeenCalledWith('Extracting Go...');
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
expect(logSpy).toHaveBeenCalledWith('Added go to the path');
expect(logSpy).toHaveBeenCalledWith(
`Successfully setup go version ${versionSpec}`
);
});

it('fallback to dist if version is not found in manifest', async () => {
os.platform = 'linux';
os.arch = 'x64';

// a version which is not in the manifest but is in node dist
let versionSpec = '1.13';

inputs['go-version'] = versionSpec;
inputs['check-latest'] = true;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken';

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

dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.13.7/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);

await main.run();

let expPath = path.join(toolPath, 'bin');

expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...'
);
expect(logSpy).toHaveBeenCalledWith(
`Failed to resolve version ${versionSpec} from manifest`
);
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${versionSpec}...`
);
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});

it('fallback to dist if manifest is not available', async () => {
os.platform = 'linux';
os.arch = 'x64';

// a version which is not in the manifest but is in node dist
let versionSpec = '1.13';

process.env['GITHUB_PATH'] = '';

inputs['go-version'] = versionSpec;
inputs['check-latest'] = true;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken';

// ... but not in the local cache
findSpy.mockImplementation(() => '');
getManifestSpy.mockImplementation(() => {
throw new Error('Unable to download manifest');
});

dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/go/1.13.7/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);

await main.run();

let expPath = path.join(toolPath, 'bin');

expect(logSpy).toHaveBeenCalledWith(
`Failed to resolve version ${versionSpec} from manifest`
);
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
'Attempt to resolve the latest version from manifest...'
);
expect(logSpy).toHaveBeenCalledWith(
'Unable to resolve version from manifest...'
);
expect(logSpy).toHaveBeenCalledWith(
`Failed to resolve version ${versionSpec} from manifest`
);
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${versionSpec}...`
);

expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
});
});
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ author: 'GitHub'
inputs:
go-version:
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.'
check-latest:
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
default: false
stable:
description: 'Whether to download only stable versions'
default: 'true'
Expand Down
Loading