mirror of
https://github.com/actions/setup-go.git
synced 2025-04-24 01:50:52 +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
|
6
.github/workflows/check-dist.yml
vendored
6
.github/workflows/check-dist.yml
vendored
|
@ -21,10 +21,10 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set Node.js 16.x
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16.x
|
||||
|
||||
|
@ -44,7 +44,7 @@ jobs:
|
|||
id: diff
|
||||
|
||||
# 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' }}
|
||||
with:
|
||||
name: dist
|
||||
|
|
4
.github/workflows/licensed.yml
vendored
4
.github/workflows/licensed.yml
vendored
|
@ -13,9 +13,9 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
name: Check licenses
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set Node.js 16.x
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16.x
|
||||
- run: npm ci
|
||||
|
|
8
.github/workflows/versions.yml
vendored
8
.github/workflows/versions.yml
vendored
|
@ -22,7 +22,7 @@ jobs:
|
|||
go: [1.12, 1.13, 1.14]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: setup-go ${{ matrix.go }}
|
||||
uses: ./
|
||||
|
@ -41,7 +41,7 @@ jobs:
|
|||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
go-version: [1.16, 1.17]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup Go and check latest
|
||||
uses: ./
|
||||
with:
|
||||
|
@ -60,7 +60,7 @@ jobs:
|
|||
go: [1.12.16, 1.13.11, 1.14.3]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: setup-go ${{ matrix.go }}
|
||||
uses: ./
|
||||
|
@ -81,7 +81,7 @@ jobs:
|
|||
go: [1.9, 1.8.6]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: setup-go ${{ matrix.go }}
|
||||
uses: ./
|
||||
|
|
4
.github/workflows/workflow.yml
vendored
4
.github/workflows/workflow.yml
vendored
|
@ -17,10 +17,10 @@ jobs:
|
|||
operating-system: [ubuntu-latest, windows-latest]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup node 16
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
cache: npm
|
||||
|
|
|
@ -55,7 +55,7 @@ a project may be further defined and clarified by project maintainers.
|
|||
## Enforcement
|
||||
|
||||
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
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
71
README.md
71
README.md
|
@ -1,28 +1,33 @@
|
|||
# setup-go
|
||||
|
||||
<p align="left">
|
||||
<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>
|
||||
|
||||
<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>
|
||||
[](https://github.com/actions/setup-go/actions/workflows/workflow.yml)
|
||||
[](https://github.com/actions/setup-go/actions/workflows/versions.yml)
|
||||
|
||||
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
|
||||
- registering problem matchers for error output
|
||||
- Optionally downloading and caching a version of Go by version and adding to `PATH`.
|
||||
- Registering problem matchers for error output.
|
||||
|
||||
# V3
|
||||
|
||||
The V3 offers:
|
||||
- Adds GOBIN to the PATH
|
||||
- Proxy Support
|
||||
The V3 edition of the action offers:
|
||||
|
||||
- Adds `GOBIN` to the `PATH`
|
||||
- Proxy support
|
||||
- Check latest version
|
||||
<<<<<<< HEAD
|
||||
- Caching packages dependencies
|
||||
- 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).
|
||||
|
||||
**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):
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
@ -42,6 +47,7 @@ steps:
|
|||
```
|
||||
|
||||
Matching an unstable pre-release:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
@ -64,7 +70,8 @@ steps:
|
|||
|
||||
See [action.yml](action.yml)
|
||||
|
||||
## Basic:
|
||||
## Basic
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- 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.
|
||||
|
||||
|
@ -93,38 +100,8 @@ steps:
|
|||
- 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
|
||||
jobs:
|
||||
build:
|
||||
|
@ -143,11 +120,13 @@ jobs:
|
|||
```
|
||||
|
||||
### Supported version 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`
|
||||
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
|
||||
- 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`
|
||||
|
||||
For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver) documentation.
|
||||
|
||||
# License
|
||||
|
||||
|
|
|
@ -105,6 +105,11 @@ describe('setup-go', () => {
|
|||
jest.restoreAllMocks();
|
||||
}, 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 () => {
|
||||
os.platform = 'darwin';
|
||||
os.arch = 'x64';
|
||||
|
|
|
@ -16,6 +16,8 @@ inputs:
|
|||
cache-dependency-path:
|
||||
description: 'Used to specify the path to a dependency file - go.sum'
|
||||
outputs:
|
||||
go-version:
|
||||
description: 'The installed Go version. Useful when given a version range as input.'
|
||||
cache-hit:
|
||||
description: 'A boolean value to indicate if a cache was hit'
|
||||
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();
|
||||
core.info(goVersion);
|
||||
|
||||
core.setOutput('go-version', parseGoVersion(goVersion));
|
||||
|
||||
core.startGroup('go env');
|
||||
let goEnv = (cp.execSync(`${goPath} env`) || '').toString();
|
||||
core.info(goEnv);
|
||||
|
@ -75,7 +77,7 @@ export async function addBinToPath(): Promise<boolean> {
|
|||
}
|
||||
|
||||
let buf = cp.execSync('go env GOPATH');
|
||||
if (buf) {
|
||||
if (buf.length > 1) {
|
||||
let gp = buf.toString().trim();
|
||||
core.debug(`go env GOPATH :${gp}:`);
|
||||
if (!fs.existsSync(gp)) {
|
||||
|
@ -95,3 +97,11 @@ export async function addBinToPath(): Promise<boolean> {
|
|||
}
|
||||
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