consul/.github/workflows/reusable-get-go-version.yml

52 lines
2.2 KiB
YAML

name: get-go-version
on:
workflow_call:
inputs:
ref:
description: |
The Consul ref/branch (e.g. release/1.18.x) for which to determine the Go version.
If not provided, the default actions/checkout value (current ref) is used.
type: string
outputs:
go-version:
description: "The Go version detected by this workflow"
value: ${{ jobs.get-go-version.outputs.go-version }}
go-version-previous:
description: "The Go version (MAJOR.MINOR) prior to the current one, used for backwards compatibility testing"
value: ${{ jobs.get-go-version.outputs.go-version-previous }}
jobs:
get-go-version:
name: "Determine Go toolchain version"
runs-on: ubuntu-latest
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
go-version-previous: ${{ steps.get-go-version.outputs.go-version-previous }}
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
# If not set, will default to current branch.
ref: ${{ inputs.ref }}
- name: Determine Go version
id: get-go-version
# We use .go-version as our source of truth for current Go
# version, because "goenv" can react to it automatically.
#
# In the future, we can transition from .go-version and goenv to
# Go 1.21 `toolchain` directives by updating this workflow rather
# than individually setting `go-version-file` in each `setup-go`
# job (as of 2024-01-03, `setup-go` does not support `toolchain`).
#
# When changing the method of Go version detection, also update
# GOLANG_VERSION detection in the root Makefile; this is used for
# setting the Dockerfile Go version.
run: |
GO_VERSION=$(head -n 1 .go-version)
echo "Building with Go ${GO_VERSION}"
echo "go-version=${GO_VERSION}" >> $GITHUB_OUTPUT
GO_MINOR_VERSION=${GO_VERSION%.*}
GO_VERSION_PREVIOUS="${GO_MINOR_VERSION%.*}.$((${GO_MINOR_VERSION#*.}-1))"
echo "Previous version ${GO_VERSION_PREVIOUS}"
echo "go-version-previous=${GO_VERSION_PREVIOUS}" >> $GITHUB_OUTPUT