From dcb4ec94ce957a5303565555e54f942163d41ed8 Mon Sep 17 00:00:00 2001 From: Peter Mescalchin Date: Fri, 1 Apr 2022 06:29:52 +1100 Subject: [PATCH 1/8] Bump GitHub actions, `README.md` cleanups (#202) * Bump `actions/checkout@v3` * Bump `actions/setup-node@v3` * Bump `actions/upload-artifact@v3` * Bump `actions/setup-go@v3` in `README.md` examples * Removed mention of `stable` action argument from `README.md` * Add "new style" workflow build buttons to `README.md` --- .github/workflows/check-dist.yml | 6 +++--- .github/workflows/licensed.yml | 4 ++-- .github/workflows/versions.yml | 12 ++++++------ .github/workflows/workflow.yml | 4 ++-- README.md | 28 +++++++++++++++------------- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index 0816ccb..7be140a 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -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 diff --git a/.github/workflows/licensed.yml b/.github/workflows/licensed.yml index 55402d9..3662014 100644 --- a/.github/workflows/licensed.yml +++ b/.github/workflows/licensed.yml @@ -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 diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index c0bb369..79683ec 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -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,13 +60,13 @@ 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: ./ with: go-version: ${{ matrix.go }} - + - name: verify go run: __tests__/verify-go.sh ${{ matrix.go }} shell: bash @@ -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: ./ diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 9e18f39..df67fa8 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -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 diff --git a/README.md b/README.md index ee5557b..5fa3625 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,26 @@ # setup-go -

- GitHub Actions status - - versions status -

+[![build-test](https://github.com/actions/setup-go/actions/workflows/workflow.yml/badge.svg)](https://github.com/actions/setup-go/actions/workflows/workflow.yml) +[![Validate 'setup-go'](https://github.com/actions/setup-go/actions/workflows/versions.yml/badge.svg)](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 -- Bug Fixes (including issues around version matching and semver) +- 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). Matching by [semver spec](https://github.com/npm/node-semver): + ```yaml steps: - uses: actions/checkout@v3 @@ -64,6 +63,7 @@ steps: See [action.yml](action.yml) ## Basic: + ```yaml steps: - uses: actions/checkout@v3 @@ -74,7 +74,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,6 +93,7 @@ steps: ``` ## Matrix Testing: + ```yaml jobs: build: @@ -111,9 +112,10 @@ 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` +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 From bf7ccf173eb621cba29f5e204628485c22b25c32 Mon Sep 17 00:00:00 2001 From: Peter Mescalchin Date: Sat, 2 Apr 2022 00:27:16 +1100 Subject: [PATCH 2/8] Correct some small `README.md` formatting typos (#213) --- README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5fa3625..8310cff 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ steps: ``` Matching an unstable pre-release: + ```yaml steps: - uses: actions/checkout@v3 @@ -62,7 +63,7 @@ steps: See [action.yml](action.yml) -## Basic: +## Basic ```yaml steps: @@ -74,7 +75,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. @@ -92,7 +93,7 @@ steps: - run: go run hello.go ``` -## Matrix Testing: +## Matrix testing ```yaml jobs: @@ -115,9 +116,10 @@ jobs: 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 @@ -125,8 +127,8 @@ The scripts and documentation in this project are released under the [MIT Licens # Contributions -Contributions are welcome! See [Contributor's Guide](docs/contributors.md) +Contributions are welcome! See [Contributor's Guide](docs/contributors.md) ## Code of Conduct -:wave: Be nice. See [our code of conduct](CONDUCT) +:wave: Be nice. See [our code of conduct](CONDUCT) From 115d6e600482373e6926d06d6bf0197903fa37a9 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Thu, 7 Apr 2022 18:31:36 +0300 Subject: [PATCH 3/8] Set LF for all files (#214) * Set LF for all files * Set gitattr text=auto --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index 541fd55..4994dee 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ +* text=auto .licenses/** -diff linguist-generated=true \ No newline at end of file From 4a4352b33067e47da692b40ea6e19467075219ac Mon Sep 17 00:00:00 2001 From: Nick <50747025+mcdonnnj@users.noreply.github.com> Date: Fri, 8 Apr 2022 12:23:10 -0400 Subject: [PATCH 4/8] Add 'go-version' Output (#85) * Add go-version to action outputs This provides the semver version of Go that has been installed. This is useful if only a major or minor version has been provided as the input go-version value. * Convert version extraction to a function Simplify how the version is extracted and add a simple test at the same time. Co-authored-by: Peter Mescalchin Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com> Co-authored-by: Peter Mescalchin Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com> --- __tests__/setup-go.test.ts | 5 +++++ action.yml | 5 ++++- dist/index.js | 11 ++++++++++- src/main.ts | 10 ++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index bb85dee..8c5033b 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -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'; diff --git a/action.yml b/action.yml index 8bbaebe..ab0fdca 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,7 @@ name: 'Setup Go environment' description: 'Setup a Go environment and add it to the PATH' author: 'GitHub' -inputs: +inputs: go-version: description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.' check-latest: @@ -10,6 +10,9 @@ inputs: token: description: Used to pull node distributions from go-versions. Since there's a default, this is typically not supplied by the user. default: ${{ github.token }} +outputs: + go-version: + description: 'The installed Go version. Useful when given a version range as input.' runs: using: 'node16' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 48ceb03..74206fb 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2058,7 +2058,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.addBinToPath = exports.run = void 0; +exports.parseGoVersion = exports.addBinToPath = exports.run = void 0; const core = __importStar(__webpack_require__(470)); const io = __importStar(__webpack_require__(1)); const installer = __importStar(__webpack_require__(749)); @@ -2100,6 +2100,7 @@ function run() { let goPath = yield io.which('go'); let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString(); core.info(goVersion); + core.setOutput('go-version', parseGoVersion(goVersion)); core.startGroup('go env'); let goEnv = (child_process_1.default.execSync(`${goPath} env`) || '').toString(); core.info(goEnv); @@ -2145,6 +2146,14 @@ function isGhes() { const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; } +function parseGoVersion(versionString) { + // 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 for runtime.Version() + return versionString.split(' ')[2].slice('go'.length); +} +exports.parseGoVersion = parseGoVersion; //# sourceMappingURL=main.js.map /***/ }), diff --git a/src/main.ts b/src/main.ts index 34784c4..a5caf9b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -48,6 +48,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); @@ -94,3 +96,11 @@ function isGhes(): boolean { ); return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; } + +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 for runtime.Version() + return versionString.split(' ')[2].slice('go'.length); +} From ad70bef2ef3d4a69511a3994c9b65a3584bbe653 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Sun, 17 Apr 2022 17:36:51 +0200 Subject: [PATCH 5/8] Fix condition for old go versions --- dist/index.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 74206fb..dd9f2d3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2122,7 +2122,7 @@ function addBinToPath() { return added; } let buf = child_process_1.default.execSync('go env GOPATH'); - if (buf) { + if (buf.length > 1) { let gp = buf.toString().trim(); core.debug(`go env GOPATH :${gp}:`); if (!fs_1.default.existsSync(gp)) { diff --git a/src/main.ts b/src/main.ts index a5caf9b..1023292 100644 --- a/src/main.ts +++ b/src/main.ts @@ -69,7 +69,7 @@ export async function addBinToPath(): Promise { } 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)) { From 07948221bef819e39255ccb730b9ead9f22c5c03 Mon Sep 17 00:00:00 2001 From: IvanZosimov <98037481+IvanZosimov@users.noreply.github.com> Date: Mon, 18 Apr 2022 10:45:36 +0200 Subject: [PATCH 6/8] Rename CONDUCT.md and change email inside (#218) --- CONDUCT => CODE_OF_CONDUCT.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename CONDUCT => CODE_OF_CONDUCT.md (96%) diff --git a/CONDUCT b/CODE_OF_CONDUCT.md similarity index 96% rename from CONDUCT rename to CODE_OF_CONDUCT.md index 517657b..1f045f4 100644 --- a/CONDUCT +++ b/CODE_OF_CONDUCT.md @@ -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. @@ -73,4 +73,4 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see -https://www.contributor-covenant.org/faq \ No newline at end of file +https://www.contributor-covenant.org/faq From 333235845452e808872d02ff54724c813b6735d6 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Wed, 20 Apr 2022 16:11:14 +0200 Subject: [PATCH 7/8] Add note about go building --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8310cff..20440a4 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ The V3 edition of the action offers: 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 From 56a61c9834b4a4950dbbf4740af0b8a98c73b768 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Tue, 26 Apr 2022 11:38:01 +0200 Subject: [PATCH 8/8] Create ADR for integrating cache functionality to setup-go action (#217) --- docs/adrs/0000-caching-dependencies.md | 69 ++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 docs/adrs/0000-caching-dependencies.md diff --git a/docs/adrs/0000-caching-dependencies.md b/docs/adrs/0000-caching-dependencies.md new file mode 100644 index 0000000..dc8d858 --- /dev/null +++ b/docs/adrs/0000-caching-dependencies.md @@ -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('') }}` +- 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) \ No newline at end of file