feat: support mise.toml for Go versions

pull/787/head
Leif Arriens 2 weeks ago
parent fba3fb4ead
commit 0979d1074a

@ -174,6 +174,22 @@ jobs:
run: __tests__/verify-go.sh 1.22.4
shell: bash
go-version-file-with-mise:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Go from mise.toml
uses: ./
with:
go-version-file: __tests__/data/mise.toml
- name: verify go
run: __tests__/verify-go.sh 1.23.2
shell: bash
setup-versions-from-manifest:
runs-on: ${{ matrix.os }}
strategy:

@ -0,0 +1,35 @@
---
name: smol-toml
version: 1.8.0
type: npm
summary: A small, fast, and correct TOML parser/serializer
homepage:
license: bsd-3-clause
licenses:
- sources: LICENSE
text: |
Copyright (c) Squirrel Chat et al., All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
notices: []

@ -40,7 +40,7 @@ See [action.yml](action.yml).
# Version or version range of Go to use
go-version: '1.23'
# Path to go.mod, go.work, .go-version, or .tool-versions file
# Path to go.mod, go.work, .go-version, .tool-versions, or mise.toml file
# Note: if both go-version and go-version-file are provided, go-version takes precedence.
go-version-file: 'go.mod'

@ -0,0 +1,2 @@
[tools]
go = "1.23.2"

@ -952,6 +952,9 @@ use .
`;
const toolVersionsContents = `golang 1.23
`;
const miseTomlContents = `[tools]
go = "1.24"
`;
it('reads version from go.mod', async () => {
@ -990,6 +993,32 @@ use .
expect(logSpy).toHaveBeenCalledWith('matching 1.23...');
});
it('reads version from mise.toml', async () => {
inputs['go-version-file'] = 'mise.toml';
existsSpy.mockImplementation(() => true);
readFileSpy.mockImplementation(() => Buffer.from(miseTomlContents));
await main.run();
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.24');
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.24...');
expect(logSpy).toHaveBeenCalledWith('matching 1.24...');
});
it('reads an object version from mise.toml', async () => {
inputs['go-version-file'] = 'mise.toml';
existsSpy.mockImplementation(() => true);
readFileSpy.mockImplementation(() =>
Buffer.from('[tools]\ngo = { version = "1.25" }\n')
);
await main.run();
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.25');
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.25...');
expect(logSpy).toHaveBeenCalledWith('matching 1.25...');
});
it('reads version from .go-version', async () => {
inputs['go-version-file'] = '.go-version';
existsSpy.mockImplementation(() => true);

@ -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, go.work, .go-version, or .tool-versions file.'
description: 'Path to the go.mod, go.work, .go-version, .tool-versions, or mise.toml 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

1181
dist/setup/index.js vendored

File diff suppressed because it is too large Load Diff

@ -164,9 +164,9 @@ jobs:
## Using the `go-version-file` input
`setup-go` action can read the Go version from a version file. `go-version-file` input is used for specifying the path to the version file. If the file supplied to the `go-version-file` input doesn't exist, the action will fail with an error. This input supports go.mod, go.work, .go-version, and .tool-versions files.
`setup-go` action can read the Go version from a version file. `go-version-file` input is used for specifying the path to the version file. If the file supplied to the `go-version-file` input doesn't exist, the action will fail with an error. This input supports go.mod, go.work, .go-version, .tool-versions, and mise.toml files.
If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used. The `.tool-versions` file supports version specifications in accordance with asdf standards, adhering to Semantic Versioning ([semver](https://semver.org)).
If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used. The `.tool-versions` file supports version specifications in accordance with asdf standards, adhering to Semantic Versioning ([semver](https://semver.org)). For `mise.toml`, the Go version is read from the `go` entry in the `[tools]` table.
```yaml
steps:
@ -194,6 +194,15 @@ steps:
- run: go version
```
```yaml
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: 'mise.toml' # Read Go version from mise.toml
- run: go version
```
```yaml
steps:
- uses: actions/checkout@v7

15
package-lock.json generated

@ -16,7 +16,8 @@
"@actions/http-client": "^4.0.1",
"@actions/io": "^3.0.2",
"@actions/tool-cache": "^4.0.0",
"semver": "^7.8.5"
"semver": "^7.8.5",
"smol-toml": "^1.8.0"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
@ -5644,6 +5645,18 @@
"node": ">=8"
}
},
"node_modules/smol-toml": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/smol-toml/-/smol-toml-1.8.0.tgz",
"integrity": "sha512-kCZr2V3ch9i00x8zXRhjUNVcjG9ijES5dDudkXvUVCT5QlJNQWElSJdZqyPemffHoLNUYwOcou0Fy+ojN0uHSQ==",
"license": "BSD-3-Clause",
"engines": {
"node": ">= 18"
},
"funding": {
"url": "https://github.com/sponsors/cyyynthia"
}
},
"node_modules/source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",

@ -36,7 +36,8 @@
"@actions/http-client": "^4.0.1",
"@actions/io": "^3.0.2",
"@actions/tool-cache": "^4.0.0",
"semver": "^7.8.5"
"semver": "^7.8.5",
"smol-toml": "^1.8.0"
},
"devDependencies": {
"@eslint/js": "^10.0.1",

@ -11,6 +11,7 @@ import os from 'os';
import {StableReleaseAlias, isSelfHosted} from './utils.js';
import {Architecture} from './types.js';
import {getVersionsDist} from './go-version-fetch.js';
import {parse} from 'smol-toml';
export const GOTOOLCHAIN_ENV_VAR = 'GOTOOLCHAIN';
export const GOTOOLCHAIN_LOCAL_VAL = 'local';
@ -667,6 +668,23 @@ export function parseGoVersionFile(versionFilePath: string): string {
} else if (path.basename(versionFilePath) === '.tool-versions') {
const match = contents.match(/^golang\s+([^\n#]+)/m);
return match ? match[1].trim() : '';
} else if (path.basename(versionFilePath) === 'mise.toml') {
try {
const manifest: Record<string, any> = parse(contents);
const go = manifest?.tools?.go;
if (typeof go === 'object' && go?.version) {
return go.version;
}
if (typeof go === 'string') {
return go;
}
return '';
} catch {
// Fall through to the plain-text parser for invalid TOML.
}
}
return contents.trim();

Loading…
Cancel
Save