Git Product home page Git Product logo

arnested / go-version-action Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 2.0 3.31 MB

A GitHub action for using the latest released Go version and the minimal support Go version (from go.mod) and a build matrix of them and all versions in between.

Home Page: https://github.com/marketplace/actions/go-version-action

License: MIT License

JavaScript 100.00%
github-actions go go-modules ci golang versions hacktoberfest

go-version-action's Introduction

Go version action

A GitHub action for using the latest released Go version and your projects minimal support Go version (from go.mod), and a build matrix of them, and all versions in between.

Motive

Being consistent is hard.

I used to hard-code the Go versions my projects needed for test and builds in my GitHub Actions workflow files.

Of course, the result was that I used different versions in the go.mod file and my workflow files.

Whenever a new version of Go was released, I forgot to add the new version to my build matrix and my projects weren't tested on the new release(s).

So, I build this action.

The action reads the minimal supported Go version from your go.mod file and exposes it as a variable to your workflow.

It also pulls the list of release tags from https://go.dev/dl/ and exposes the latest released Go version as a variable as well.

From the list of released Go versions and the minimal version, your module supports we also build a "matrix" variable to be used as a build matrix.

While we are at it, we also extract the module path from the go.mod file, even though it hasn't really anything to do with versions ;)

Inputs

If your go mod file is located in a non-standard location, you can specify the working directory where it is located:

working-directory:
  description: Working directory where your go.mod file is located
  required: false
  default: .
unstable:
  description: Include unstable versions of Go (beta, release candidates)
  required: false
  default: 'false'
unsupported:
  description: Include unsupported versions of Go
  required: false
  default: 'true'
patch-level:
  description: Include the patch levels on the versions (default is major.minor)
  required: false
  default: 'false'

Outputs

go-mod-version:
  description: The Go version specified by go.mod
latest:
  description: The latest Go version
minimal:
  description: The minimal Go version
matrix:
  description: A (stringified) array of Go versions from the minimal supported version to the latest released version
module:
  description: The Go module path (as specified by go.mod)

Examples

Let's say your go.mod specifies Go 1.13 as the minimal supported version and you want your workflow to set up Go version 1.13 using the actions/setup-go action:

name: My Go workflow
on: pull_request

jobs:
  my-go-workflow:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: arnested/go-version-action@v1
        id: go-version
      - name: Install Go ${{ steps.go-version.outputs.minimal }}
        uses: actions/setup-go@v3
        with:
          go-version: ${{ steps.go-version.outputs.minimal }}
          check-latest: true

Log of running action

If you want do a matrix test of all Go versions from your minimally supported version up to the latest released version we need to do a bit more.

We have to run the version lookup as a separate job and let the test job depend on it:

on: push
name: Test

jobs:
  go-versions:
    name: Lookup Go versions
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.versions.outputs.matrix }}
    steps:
      - uses: actions/checkout@v3
      - uses: arnested/go-version-action@v1
        id: versions
  test:
    name: Test
    runs-on: ubuntu-latest
    needs: go-versions
    strategy:
      matrix:
        version: ${{ fromJSON(needs.go-versions.outputs.matrix) }}
    steps:
      - uses: actions/checkout@v3
      - name: Install Go
        uses: actions/setup-go@v3
        with:
          go-version: ${{ matrix.version }}
          check-latest: true
      - name: Go test
        run: go test -v -race -cover -covermode=atomic -coverprofile=coverage.txt ./...

The workflow summary

Summary

The action writes a GitHub Actions Job Summary with values it identified.

This example is from running with:

          unsupported: false
          patch-level: true

Job summary

go-version-action's People

Contributors

actions-user avatar alan-cha avatar arnested avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

syllogy alan-cha

go-version-action's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.