Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: go-version-file for other use cases #295

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 41 additions & 10 deletions README.md
Expand Up @@ -59,11 +59,11 @@ steps:
```

> **Note**: Due to the peculiarities of YAML parsing, it is recommended to wrap the version in single quotation marks:
>
>
> ```yaml
> go-version: '1.20'
> ```
>
>
> The recommendation is based on the YAML parser's behavior, which interprets non-wrapped values as numbers and, in the case of version 1.20, trims it down to 1.2, which may not be very obvious.
Matching an unstable pre-release:

Expand Down Expand Up @@ -161,7 +161,7 @@ The action defaults to search for the dependency file - go.sum in the repository
the cache key. Use `cache-dependency-path` input for cases when multiple dependency files are used, or they are located
in different subdirectories.

If some problem that prevents success caching happens then the action issues the warning in the log and continues the execution of the pipeline.
If some problem that prevents success caching happens then the action issues the warning in the log and continues the execution of the pipeline.

**Caching in monorepos**

Expand All @@ -175,16 +175,19 @@ steps:
cache-dependency-path: subdir/go.sum
- run: go run hello.go
```
## Getting go version from a file

## Getting go version from the go.mod file
If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used.

The `go-version-file` input accepts a path to a `go.mod` file or a `go.work` file that contains the version of Go to be
used by a project. As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will search for the
latest available patch version sequentially in the runner's directory with the cached tools, in
the [versions-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go
servers.
If the file contains only major and minor (e.g. 1.18) tags, the action will search for the latest available patch version
sequentially in the runner's directory with the cached tools, in the [version-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json)
file or at the go servers.

### If the go.mod or .tool-versions files

The `go-version-file` input accepts a path to a `go.mod` file, [.tool-versions](https://asdf-vm.com/manage/configuration.html#tool-versions) file or a `go.work` file that contains the version of Go to be used by a project.
As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will follow the above-mentioned approach.

If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used.
> The action will search for the `go.mod` file relative to the repository root

```yaml
Expand All @@ -196,6 +199,34 @@ steps:
- run: go version
```

The `go-version` output contains the resolved Golang version from the `go.mod` file.

> The action will search for the `.tool-versions` file relative to the repository root

```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: '.tool-versions'
- run: go version
```

### If a different file

The `go-version-file` input accepts a path to a file that contains the version of Go to be used by a project. It supports either major and minor (e.g 1.18) or major, minor and patch (e.g 1.18.7) tags. If the file contains only major and minor (e.g. 1.18) tags, the action will follow the above-mentioned approach.

> The action will search for the `.go-version` file relative to the repository root

```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: 'path/to/.go-version'
- run: go version
```

## Matrix testing

```yaml
Expand Down