From d42979eea1014acae780832c208cc9e0c02dad05 Mon Sep 17 00:00:00 2001 From: priya-kinthali Date: Mon, 11 Dec 2023 18:01:39 +0530 Subject: [PATCH 1/2] setup go in local --- src/cache-save.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cache-save.ts b/src/cache-save.ts index 5baefde..f873527 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -15,6 +15,7 @@ process.on('uncaughtException', e => { // Added early exit to resolve issue with slow post action step: // - https://github.com/actions/setup-node/issues/878 // https://github.com/actions/cache/pull/1217 + export async function run(earlyExit?: boolean) { try { const cacheInput = core.getBooleanInput('cache'); From 4faced9210f85a3c895244a7db0c83696dc3560d Mon Sep 17 00:00:00 2001 From: priya-kinthali Date: Fri, 24 Oct 2025 16:20:41 +0530 Subject: [PATCH 2/2] add .tool-versions file support --- .github/workflows/versions.yml | 40 ++++++++++++++++++++++++---------- README.md | 11 +++++++++- __tests__/data/.tool-versions | 1 + __tests__/setup-go.test.ts | 15 +++++++++++++ action.yml | 2 +- dist/setup/index.js | 4 ++++ src/installer.ts | 3 +++ 7 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 __tests__/data/.tool-versions diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 89f4c42..198e82e 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] steps: - uses: actions/checkout@v5 - name: Setup Go Stable @@ -33,7 +33,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] steps: - uses: actions/checkout@v5 - name: Setup Go oldStable @@ -48,13 +48,13 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] version: [stable, oldstable] architecture: [x64, x32] exclude: - os: macos-latest architecture: x32 - - os: macos-13 + - os: macos-latest-large architecture: x32 steps: - uses: actions/checkout@v5 @@ -72,7 +72,7 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-latest, windows-latest, ubuntu-latest, macos-13] + os: [macos-latest, windows-latest, ubuntu-latest, macos-latest-large] go: [1.21.13, 1.22.8, 1.23.2] include: - os: windows-latest @@ -98,7 +98,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] go-version: ['1.20', '1.21', '1.22', '1.23'] steps: - uses: actions/checkout@v5 @@ -115,7 +115,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] steps: - uses: actions/checkout@v5 - name: Setup Go and check latest @@ -131,7 +131,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] steps: - uses: actions/checkout@v5 - name: Setup Go and check latest @@ -142,12 +142,28 @@ jobs: run: __tests__/verify-go.sh 1.21 shell: bash + go-version-file-with-tool-versions: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] + steps: + - uses: actions/checkout@v5 + - name: Setup Go and check latest + uses: ./ + with: + go-version-file: __tests__/data/.tool-versions + - name: verify go + run: __tests__/verify-go.sh 1.23.2 + shell: bash + setup-versions-from-manifest: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - os: [macos-latest, windows-latest, ubuntu-latest, macos-13] + os: [macos-latest, windows-latest, ubuntu-latest, macos-latest-large] go: [1.20.14, 1.21.10, 1.22.8, 1.23.2] steps: - name: Checkout @@ -167,7 +183,7 @@ jobs: strategy: fail-fast: false matrix: - os: [windows-latest, ubuntu-latest, macos-13] + os: [windows-latest, ubuntu-latest, macos-latest-large] go: [1.11.12] steps: - name: Checkout @@ -187,7 +203,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest, macos-13] + os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large] go-version: [1.20.14, 1.21, 1.22, 1.23] include: - os: macos-latest @@ -196,7 +212,7 @@ jobs: architecture: x64 - os: windows-latest architecture: x64 - - os: macos-13 + - os: macos-latest-large architecture: x64 steps: - uses: actions/checkout@v5 diff --git a/README.md b/README.md index 564d55f..14187a4 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ steps: ## Getting go version from the go.mod file -The `go-version-file` input accepts a path to a `go.mod` file or a `go.work` +The `go-version-file` input accepts a path to a `go.mod` file, `.tool-versions` file or a `go.work` file that contains the version of Go to be used by a project. The version taken from thils file will be: @@ -203,6 +203,15 @@ steps: go-version-file: 'path/to/go.mod' - run: go version ``` +```yaml +steps: + - uses: actions/checkout@v5 + - uses: actions/setup-go@v6 + with: + go-version-file: '.tool-versions' + - run: go version +``` +> The [.tool-versions file](https://asdf-vm.com/manage/configuration.html#tool-versions) supports version specifications in accordance with asdf standards, adhering to Semantic Versioning ([semver](https://semver.org)). ## Matrix testing diff --git a/__tests__/data/.tool-versions b/__tests__/data/.tool-versions new file mode 100644 index 0000000..f0e1c18 --- /dev/null +++ b/__tests__/data/.tool-versions @@ -0,0 +1 @@ +golang 1.23.2 \ No newline at end of file diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index b89c08f..d7e1498 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -866,6 +866,9 @@ exclude example.com/thismodule v1.3.0 use . +`; + + const toolVersionsContents = `golang 1.23 `; it('reads version from go.mod', async () => { @@ -892,6 +895,18 @@ use . expect(logSpy).toHaveBeenCalledWith('matching 1.19...'); }); + it('reads version from .tool-versions', async () => { + inputs['go-version-file'] = '.tool-versions'; + existsSpy.mockImplementation(() => true); + readFileSpy.mockImplementation(() => Buffer.from(toolVersionsContents)); + + await main.run(); + + expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.23'); + expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.23...'); + expect(logSpy).toHaveBeenCalledWith('matching 1.23...'); + }); + it('reads version from .go-version', async () => { inputs['go-version-file'] = '.go-version'; existsSpy.mockImplementation(() => true); diff --git a/action.yml b/action.yml index 9946e47..6a345b3 100644 --- a/action.yml +++ b/action.yml @@ -5,7 +5,7 @@ inputs: go-version: description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges. Be sure to enclose this option in single quotation marks.' go-version-file: - description: 'Path to the go.mod or go.work file.' + description: 'Path to the go.mod, .tool-versions, or go.work file.' check-latest: description: 'Set this option to true if you want the action to always check for the latest available version that satisfies the version spec' default: false diff --git a/dist/setup/index.js b/dist/setup/index.js index 96f4ef9..0407a41 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -94679,6 +94679,10 @@ function parseGoVersionFile(versionFilePath) { const matchGo = contents.match(/^go (\d+(\.\d+)*)/m); return matchGo ? matchGo[1] : ''; } + else if (path.basename(versionFilePath) === '.tool-versions') { + const match = contents.match(/^golang\s+([^\n#]+)/m); + return match ? match[1].trim() : ''; + } return contents.trim(); } function resolveStableVersionDist(versionSpec, arch) { diff --git a/src/installer.ts b/src/installer.ts index 6dcd729..3013c8e 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -513,6 +513,9 @@ export function parseGoVersionFile(versionFilePath: string): string { // go directive: https://go.dev/ref/mod#go-mod-file-go const matchGo = contents.match(/^go (\d+(\.\d+)*)/m); return matchGo ? matchGo[1] : ''; + } else if (path.basename(versionFilePath) === '.tool-versions') { + const match = contents.match(/^golang\s+([^\n#]+)/m); + return match ? match[1].trim() : ''; } return contents.trim();