mirror of
https://github.com/actions/setup-go.git
synced 2025-04-23 17:40:50 +00:00
Sync branch 'modules-caching' with 'actions/setup-go/main'
This commit is contained in:
commit
eedb42bbf8
11 changed files with 131 additions and 65 deletions
1
.gitattributes
vendored
1
.gitattributes
vendored
|
@ -1 +1,2 @@
|
||||||
|
* text=auto
|
||||||
.licenses/** -diff linguist-generated=true
|
.licenses/** -diff linguist-generated=true
|
6
.github/workflows/check-dist.yml
vendored
6
.github/workflows/check-dist.yml
vendored
|
@ -21,10 +21,10 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set Node.js 16.x
|
- name: Set Node.js 16.x
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
node-version: 16.x
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ jobs:
|
||||||
id: diff
|
id: diff
|
||||||
|
|
||||||
# If index.js was different than expected, upload the expected version as an artifact
|
# If index.js was different than expected, upload the expected version as an artifact
|
||||||
- uses: actions/upload-artifact@v2
|
- uses: actions/upload-artifact@v3
|
||||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||||
with:
|
with:
|
||||||
name: dist
|
name: dist
|
||||||
|
|
4
.github/workflows/licensed.yml
vendored
4
.github/workflows/licensed.yml
vendored
|
@ -13,9 +13,9 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Check licenses
|
name: Check licenses
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Set Node.js 16.x
|
- name: Set Node.js 16.x
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
node-version: 16.x
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
|
|
12
.github/workflows/versions.yml
vendored
12
.github/workflows/versions.yml
vendored
|
@ -22,7 +22,7 @@ jobs:
|
||||||
go: [1.12, 1.13, 1.14]
|
go: [1.12, 1.13, 1.14]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: setup-go ${{ matrix.go }}
|
- name: setup-go ${{ matrix.go }}
|
||||||
uses: ./
|
uses: ./
|
||||||
|
@ -41,7 +41,7 @@ jobs:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
go-version: [1.16, 1.17]
|
go-version: [1.16, 1.17]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Go and check latest
|
- name: Setup Go and check latest
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
|
@ -60,13 +60,13 @@ jobs:
|
||||||
go: [1.12.16, 1.13.11, 1.14.3]
|
go: [1.12.16, 1.13.11, 1.14.3]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: setup-go ${{ matrix.go }}
|
- name: setup-go ${{ matrix.go }}
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go }}
|
go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
- name: verify go
|
- name: verify go
|
||||||
run: __tests__/verify-go.sh ${{ matrix.go }}
|
run: __tests__/verify-go.sh ${{ matrix.go }}
|
||||||
shell: bash
|
shell: bash
|
||||||
|
@ -81,7 +81,7 @@ jobs:
|
||||||
go: [1.9, 1.8.6]
|
go: [1.9, 1.8.6]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: setup-go ${{ matrix.go }}
|
- name: setup-go ${{ matrix.go }}
|
||||||
uses: ./
|
uses: ./
|
||||||
|
|
4
.github/workflows/workflow.yml
vendored
4
.github/workflows/workflow.yml
vendored
|
@ -17,10 +17,10 @@ jobs:
|
||||||
operating-system: [ubuntu-latest, windows-latest]
|
operating-system: [ubuntu-latest, windows-latest]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Setup node 16
|
- name: Setup node 16
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
cache: npm
|
cache: npm
|
||||||
|
|
|
@ -55,7 +55,7 @@ a project may be further defined and clarified by project maintainers.
|
||||||
## Enforcement
|
## Enforcement
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
reported by contacting the project team at opensource@github.com. All
|
reported by contacting the project team at opensource+actions/setup-go@github.com. All
|
||||||
complaints will be reviewed and investigated and will result in a response that
|
complaints will be reviewed and investigated and will result in a response that
|
||||||
is deemed necessary and appropriate to the circumstances. The project team is
|
is deemed necessary and appropriate to the circumstances. The project team is
|
||||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||||
|
@ -73,4 +73,4 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht
|
||||||
[homepage]: https://www.contributor-covenant.org
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
For answers to common questions about this code of conduct, see
|
For answers to common questions about this code of conduct, see
|
||||||
https://www.contributor-covenant.org/faq
|
https://www.contributor-covenant.org/faq
|
75
README.md
75
README.md
|
@ -1,28 +1,33 @@
|
||||||
# setup-go
|
# setup-go
|
||||||
|
|
||||||
<p align="left">
|
[](https://github.com/actions/setup-go/actions/workflows/workflow.yml)
|
||||||
<a href="https://github.com/actions/setup-go/actions"><img alt="GitHub Actions status" src="https://github.com/actions/setup-go/workflows/build-test/badge.svg"></a>
|
[](https://github.com/actions/setup-go/actions/workflows/versions.yml)
|
||||||
|
|
||||||
<a href="https://github.com/actions/setup-go/actions"><img alt="versions status" src="https://github.com/actions/setup-go/workflows/go-versions/badge.svg"></a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
This action sets up a go environment for use in actions by:
|
This action sets up a go environment for use in actions by:
|
||||||
|
|
||||||
- optionally downloading and caching a version of Go by version and adding to PATH
|
- Optionally downloading and caching a version of Go by version and adding to `PATH`.
|
||||||
- registering problem matchers for error output
|
- Registering problem matchers for error output.
|
||||||
|
|
||||||
# V3
|
# V3
|
||||||
|
|
||||||
The V3 offers:
|
The V3 edition of the action offers:
|
||||||
- Adds GOBIN to the PATH
|
|
||||||
- Proxy Support
|
- Adds `GOBIN` to the `PATH`
|
||||||
|
- Proxy support
|
||||||
- Check latest version
|
- Check latest version
|
||||||
|
<<<<<<< HEAD
|
||||||
- Caching packages dependencies
|
- Caching packages dependencies
|
||||||
- Bug Fixes (including issues around version matching and semver)
|
- Bug Fixes (including issues around version matching and semver)
|
||||||
|
=======
|
||||||
|
- Bug fixes (including issues around version matching and semver)
|
||||||
|
>>>>>>> main
|
||||||
|
|
||||||
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).
|
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).
|
||||||
|
|
||||||
|
**Note:** The `setup-go` action uses executable binaries which are built by Golang side. The action does not build golang from source code.
|
||||||
|
|
||||||
Matching by [semver spec](https://github.com/npm/node-semver):
|
Matching by [semver spec](https://github.com/npm/node-semver):
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
@ -42,6 +47,7 @@ steps:
|
||||||
```
|
```
|
||||||
|
|
||||||
Matching an unstable pre-release:
|
Matching an unstable pre-release:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
@ -64,7 +70,8 @@ steps:
|
||||||
|
|
||||||
See [action.yml](action.yml)
|
See [action.yml](action.yml)
|
||||||
|
|
||||||
## Basic:
|
## Basic
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
@ -75,7 +82,7 @@ steps:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Check latest version:
|
## Check latest version
|
||||||
|
|
||||||
The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific Go version is always used.
|
The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific Go version is always used.
|
||||||
|
|
||||||
|
@ -93,38 +100,8 @@ steps:
|
||||||
- run: go run hello.go
|
- run: go run hello.go
|
||||||
```
|
```
|
||||||
|
|
||||||
## Caching dependency files and build outputs:
|
## Matrix testing
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
The action defaults to search for the dependency file - go.sum in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` input for cases when multiple dependency files are used, or they are located in different subdirectories.
|
|
||||||
|
|
||||||
**Caching without specifying dependency file path**
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: '1.17'
|
|
||||||
check-latest: true
|
|
||||||
cache: true
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
**Caching in monorepos**
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: '1.17'
|
|
||||||
check-latest: true
|
|
||||||
cache: true
|
|
||||||
cache-dependency-path: subdir/go.sum
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
## Matrix Testing:
|
|
||||||
```yaml
|
```yaml
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
@ -143,11 +120,13 @@ jobs:
|
||||||
```
|
```
|
||||||
|
|
||||||
### Supported version syntax
|
### Supported version syntax
|
||||||
|
|
||||||
The `go-version` input supports the following syntax:
|
The `go-version` input supports the following syntax:
|
||||||
|
|
||||||
Specific versions: `1.15`, `1.16.1`, `1.17.0-rc.2`, `1.16.0-beta.1`
|
- Specific versions: `1.15`, `1.16.1`, `1.17.0-rc.2`, `1.16.0-beta.1`
|
||||||
SemVer's version range syntax: `^1.13.1`, `>=1.18.0-rc.1`
|
- SemVer's version range syntax: `^1.13.1`, `>=1.18.0-rc.1`
|
||||||
For more information about semantic versioning please refer [semver](https://github.com/npm/node-semver) documentation
|
|
||||||
|
For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver) documentation.
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
|
@ -155,8 +134,8 @@ The scripts and documentation in this project are released under the [MIT Licens
|
||||||
|
|
||||||
# Contributions
|
# Contributions
|
||||||
|
|
||||||
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
|
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
|
||||||
|
|
||||||
## Code of Conduct
|
## Code of Conduct
|
||||||
|
|
||||||
:wave: Be nice. See [our code of conduct](CONDUCT)
|
:wave: Be nice. See [our code of conduct](CONDUCT)
|
||||||
|
|
|
@ -105,6 +105,11 @@ describe('setup-go', () => {
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
|
it('can extract the major.minor.patch version from a given Go version string', async () => {
|
||||||
|
const goVersionOutput = 'go version go1.16.6 darwin/amd64';
|
||||||
|
expect(main.parseGoVersion(goVersionOutput)).toBe('1.16.6');
|
||||||
|
});
|
||||||
|
|
||||||
it('can find 1.9.7 from manifest on osx', async () => {
|
it('can find 1.9.7 from manifest on osx', async () => {
|
||||||
os.platform = 'darwin';
|
os.platform = 'darwin';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
name: 'Setup Go environment'
|
name: 'Setup Go environment'
|
||||||
description: 'Setup a Go environment and add it to the PATH'
|
description: 'Setup a Go environment and add it to the PATH'
|
||||||
author: 'GitHub'
|
author: 'GitHub'
|
||||||
inputs:
|
inputs:
|
||||||
go-version:
|
go-version:
|
||||||
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.'
|
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.'
|
||||||
check-latest:
|
check-latest:
|
||||||
|
@ -16,6 +16,8 @@ inputs:
|
||||||
cache-dependency-path:
|
cache-dependency-path:
|
||||||
description: 'Used to specify the path to a dependency file - go.sum'
|
description: 'Used to specify the path to a dependency file - go.sum'
|
||||||
outputs:
|
outputs:
|
||||||
|
go-version:
|
||||||
|
description: 'The installed Go version. Useful when given a version range as input.'
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate if a cache was hit'
|
description: 'A boolean value to indicate if a cache was hit'
|
||||||
runs:
|
runs:
|
||||||
|
|
69
docs/adrs/0000-caching-dependencies.md
Normal file
69
docs/adrs/0000-caching-dependencies.md
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
# 0. Caching dependencies
|
||||||
|
Date: 2022-04-13
|
||||||
|
|
||||||
|
Status: Accepted
|
||||||
|
|
||||||
|
# Context
|
||||||
|
`actions/setup-go` is the one of the most popular action related to Golang in GitHub Actions. Many customers use it in conjunction with [actions/cache](https://github.com/actions/cache) to speed up dependency installation process.
|
||||||
|
See more examples on proper usage in [actions/cache documentation](https://github.com/actions/cache/blob/main/examples.md#go---modules).
|
||||||
|
|
||||||
|
# Goals & Anti-Goals
|
||||||
|
Integration of caching functionality into `actions/setup-go` action will bring the following benefits for action users:
|
||||||
|
- Decrease the entry threshold for using the cache for Go dependencies and simplify initial configuration
|
||||||
|
- Simplify YAML pipelines because there will be no need for additional steps to enable caching
|
||||||
|
- More users will use cache for Go so more customers will have fast builds!
|
||||||
|
|
||||||
|
We don't pursue the goal to provide wide customization of caching in scope of `actions/setup-go` action. The purpose of this integration is covering ~90% of basic use-cases. If user needs flexible customization, we should advice them to use `actions/cache` directly.
|
||||||
|
|
||||||
|
# Decision
|
||||||
|
- Add `cache` input parameter to `actions/setup-go`. For now, input will accept the following values:
|
||||||
|
- `true` - enable caching for go dependencies
|
||||||
|
- `false`- disable caching for go dependencies. This value will be set as default value
|
||||||
|
- Cache feature will be disabled by default to make sure that we don't break existing customers. We will consider enabling cache by default in next major releases
|
||||||
|
- Action will try to search a go.sum files in the repository and throw error in the scenario that it was not found
|
||||||
|
- The hash of found file will be used as cache key (the same approach like [actions/cache](https://github.com/actions/cache/blob/main/examples.md#go---modules) recommends)
|
||||||
|
- The following key cache will be used `${{ runner.os }}-go${{ go-version }}-${{ hashFiles('<go.sum-path>') }}`
|
||||||
|
- Action will cache global cache from the `go env GOMODCACHE` and `go env GOCACHE` commands.
|
||||||
|
- Add a `cache-dependency-path` input parameter to `actions/setup-go`. The new input will accept an array or regex of dependency files. The field will accept a path (relative to the repository root) to dependency files. If the provided path contains wildcards, the action will search all matching files and calculate a common hash like the ${{ hashFiles('**/go.sum') }} YAML construction does.
|
||||||
|
|
||||||
|
# Example of real use-cases
|
||||||
|
|
||||||
|
- With cache
|
||||||
|
|
||||||
|
```yml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '18'
|
||||||
|
cache: true
|
||||||
|
```
|
||||||
|
|
||||||
|
- With cache-dependency-path
|
||||||
|
|
||||||
|
```yml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '18'
|
||||||
|
cache: true
|
||||||
|
cache-dependency-path: **/go.sum
|
||||||
|
```
|
||||||
|
|
||||||
|
```yml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '18'
|
||||||
|
cache: true
|
||||||
|
cache-dependency-path: |
|
||||||
|
**/go.sum
|
||||||
|
**/go.mod
|
||||||
|
```
|
||||||
|
|
||||||
|
# Release process
|
||||||
|
|
||||||
|
As soon as functionality is implemented, we will release minor update of action. No need to bump major version since there are no breaking changes for existing users.
|
||||||
|
After that, we will update [starter-workflows](https://github.com/actions/starter-workflows/blob/main/ci/go.yml)
|
12
src/main.ts
12
src/main.ts
|
@ -56,6 +56,8 @@ export async function run() {
|
||||||
let goVersion = (cp.execSync(`${goPath} version`) || '').toString();
|
let goVersion = (cp.execSync(`${goPath} version`) || '').toString();
|
||||||
core.info(goVersion);
|
core.info(goVersion);
|
||||||
|
|
||||||
|
core.setOutput('go-version', parseGoVersion(goVersion));
|
||||||
|
|
||||||
core.startGroup('go env');
|
core.startGroup('go env');
|
||||||
let goEnv = (cp.execSync(`${goPath} env`) || '').toString();
|
let goEnv = (cp.execSync(`${goPath} env`) || '').toString();
|
||||||
core.info(goEnv);
|
core.info(goEnv);
|
||||||
|
@ -75,7 +77,7 @@ export async function addBinToPath(): Promise<boolean> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let buf = cp.execSync('go env GOPATH');
|
let buf = cp.execSync('go env GOPATH');
|
||||||
if (buf) {
|
if (buf.length > 1) {
|
||||||
let gp = buf.toString().trim();
|
let gp = buf.toString().trim();
|
||||||
core.debug(`go env GOPATH :${gp}:`);
|
core.debug(`go env GOPATH :${gp}:`);
|
||||||
if (!fs.existsSync(gp)) {
|
if (!fs.existsSync(gp)) {
|
||||||
|
@ -95,3 +97,11 @@ export async function addBinToPath(): Promise<boolean> {
|
||||||
}
|
}
|
||||||
return added;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function parseGoVersion(versionString: string): string {
|
||||||
|
// get the installed version as an Action output
|
||||||
|
// based on go/src/cmd/go/internal/version/version.go:
|
||||||
|
// fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
|
||||||
|
// expecting go<version> for runtime.Version()
|
||||||
|
return versionString.split(' ')[2].slice('go'.length);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue