• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

actions/setup-go: Set up your GitHub Actions workflow with a specific version of ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

actions/setup-go

开源软件地址:

https://github.com/actions/setup-go

开源编程语言:

TypeScript 99.2%

开源软件介绍:

setup-go

build-test Validate 'setup-go'

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.

V3

The V3 edition of the action offers:

  • Adds GOBIN to the PATH
  • Proxy support
  • Check latest version
  • Caching packages dependencies
  • 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 repository. On miss or failure, it will fall back to downloading directly from go dist. To change the default behavior, please use the check-latest input.

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:

steps:
  - uses: actions/checkout@v3
  - uses: actions/setup-go@v3
    with:
      go-version: '^1.13.1' # The Go version to download (if necessary) and use.
  - run: go version
steps:
  - uses: actions/checkout@v3
  - uses: actions/setup-go@v3
    with:
      go-version: '>=1.17.0'
  - run: go version

Matching an unstable pre-release:

steps:
  - uses: actions/checkout@v3
  - uses: actions/setup-go@v3
    with:
      go-version: '1.18.0-rc.1' # The Go version to download (if necessary) and use.
  - run: go version
steps:
  - uses: actions/checkout@v3
  - uses: actions/setup-go@v3
    with:
      go-version: '1.16.0-beta.1' # The Go version to download (if necessary) and use.
  - run: go version

Usage

See action.yml

Basic

steps:
  - uses: actions/checkout@v3
  - uses: actions/setup-go@v3
    with:
      go-version: '1.16.1' # The Go version to download (if necessary) and use.
  - run: go run hello.go

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.

If check-latest is set to true, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a Go version will then be downloaded. Set check-latest to true if you want the most up-to-date Go version to always be used.

Setting check-latest to true has performance implications as downloading Go versions is slower than using cached versions.

steps:
  - uses: actions/checkout@v3
  - uses: actions/setup-go@v3
    with:
      go-version: '1.14'
      check-latest: true
  - run: go run hello.go

Caching dependency files and build outputs:

The action has a built-in functionality for caching and restoring go modules and build outputs. It uses 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

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

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

Getting go version from the go.mod file

The go-version-file input accepts a path to a go.mod file containing 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 version-manifest.json file or at the go servers.

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

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

Matrix testing

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        go: [ '1.14', '1.13' ]
    name: Go ${{ matrix.go }} sample
    steps:
      - uses: actions/checkout@v3
      - name: Setup go
        uses: actions/setup-go@v3
        with:
          go-version: ${{ matrix.go }}
      - run: go run hello.go

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 to semver documentation.

License

The scripts and documentation in this project are released under the MIT License

Contributions

Contributions are welcome! See Contributor's Guide

Code of Conduct


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
gosnmp/gosnmp: An SNMP library written in Go发布时间:2022-06-13
下一篇:
huandu/facebook: A Facebook Graph API SDK For Go.发布时间:2022-06-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap