mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-05 04:55:22 +00:00
main branch will read go version from go.mod's go primitive, and only keep major and minor version, because we want the actions to use the lastest patch version automatically, even the go.mod specify version like 1.24.0. release branch can read the go version from go.mod file by setup-go action's own logic. Refactor the get Go version to reusable workflow. Signed-off-by: Xun Jiang <xun.jiang@broadcom.com>
34 lines
1.0 KiB
YAML
34 lines
1.0 KiB
YAML
on:
|
|
workflow_call:
|
|
inputs:
|
|
ref:
|
|
description: "The target branch's ref"
|
|
required: true
|
|
type: string
|
|
outputs:
|
|
version:
|
|
description: "The expected Go version"
|
|
value: ${{ jobs.extract.outputs.version }}
|
|
|
|
jobs:
|
|
extract:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
version: ${{ steps.pick-version.outputs.version }}
|
|
steps:
|
|
- name: Check out the code
|
|
uses: actions/checkout@v5
|
|
|
|
- id: pick-version
|
|
run: |
|
|
if [ "${{ inputs.ref }}" == "main" ]; then
|
|
version=$(grep '^go ' go.mod | awk '{print $2}' | cut -d. -f1-2)
|
|
else
|
|
goDirectiveVersion=$(grep '^go ' go.mod | awk '{print $2}')
|
|
toolChainVersion=$(grep '^toolchain ' go.mod | awk '{print $2}')
|
|
version=$(printf "%s\n%s\n" "$goDirectiveVersion" "$toolChainVersion" | sort -V | tail -n1)
|
|
fi
|
|
|
|
echo "version=$version"
|
|
echo "version=$version" >> $GITHUB_OUTPUT
|