Skip to content

Commit

Permalink
Update go version as well as toolchain version.
Browse files Browse the repository at this point in the history
- this is because many of our dependencies have higher versions of go than we do and we would rather keep up to date with them vs supporting older versions of go. Especially because most of our products are binaries and not libraries.
  • Loading branch information
robdimsdale committed Jul 11, 2024
1 parent 95c41f3 commit e55cef0
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 48 deletions.
8 changes: 4 additions & 4 deletions actions/update-go-mod-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ description: |
Updates the versions of go and the go toolchain in a go.mod file
inputs:
toolchain-version:
description: 'Version of the toolchain to write'
go-version:
description: 'Version of go to write for both the go version and the toolchain version'
required: true

runs:
using: 'docker'
image: 'Dockerfile'
args:
- "--toolchain-version"
- "${{ inputs.toolchain-version }}"
- "--go-version"
- "${{ inputs.go-version }}"
40 changes: 11 additions & 29 deletions actions/update-go-mod-version/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ set -euo pipefail
shopt -s inherit_errexit

function main() {
local min_go_version toolchain_version
min_go_version="1.21" # 1.21 is the minimum to use the toolchain directive in go.mod
toolchain_version=""
local go_version
go_version=""

while [[ "${#}" != 0 ]]; do
case "${1}" in
--toolchain-version)
toolchain_version="${2}"
--go-version)
go_version="${2}"
shift 2
;;

Expand All @@ -26,39 +25,22 @@ function main() {
esac
done

if [[ -z "${toolchain_version}" ]]; then
echo "Must provide toolchain version"
if [[ -z "${go_version}" ]]; then
echo "Must provide go version"
exit 1
fi

found_go_version="$(grep -E 'go ([0-9]+\.[0-9]+)' < go.mod | sed 's/go //g')"
echo "Setting go version to: '${go_version}'"
sed -i "s/go .*/go ${go_version}/g" go.mod

if lt "${found_go_version}" "${min_go_version}"; then
echo "Updating go version to the minimum required version '${min_go_version}' (was '${found_go_version}')"
sed -i "s/go ${found_go_version}/go ${min_go_version}/g" go.mod
found_go_version="${min_go_version}"
else
echo "not updating go version as current version (${found_go_version}) is >= minimum required version (${min_go_version})"
fi

echo "setting toolchain to: '${toolchain_version}'"
echo "setting toolchain to: '${go_version}'"
if grep -qE 'toolchain go(.*)' < go.mod; then
sed -i "s/toolchain go.*/toolchain go${toolchain_version}/g" go.mod
sed -i "s/toolchain go.*/toolchain go${go_version}/g" go.mod
else
# Write the toolchain directive two lines below the go version
sed -i "/go ${found_go_version}/r"<(printf "\ntoolchain go%s\n" "${toolchain_version}") go.mod
sed -i "/go ${go_version}/r"<(printf "\ntoolchain go%s\n" "${go_version}") go.mod
fi
}

# returns $1 <= $2
function lte() {
[[ "$(printf '%s\n' "$1" "$2" | sort -V | head -n1)" == "$1" ]]
}

# returns $1 < $2
function lt() {
! lte "$2" "$1"
}

main "${@:-}"

6 changes: 3 additions & 3 deletions builder/.github/workflows/update-go-mod-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
id: current-go-version
uses: paketo-buildpacks/github-config/actions/update-go-mod-version@main
with:
toolchain-version: ${{ steps.setup-go.outputs.go-version }}
go-version: ${{ steps.setup-go.outputs.go-version }}
- name: Go mod tidy
run: |
#!/usr/bin/env bash
Expand All @@ -54,7 +54,7 @@ jobs:
id: commit
uses: paketo-buildpacks/github-config/actions/pull-request/create-commit@main
with:
message: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}"
message: "Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
pathspec: "."
keyid: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY_ID }}
key: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY }}
Expand All @@ -70,7 +70,7 @@ jobs:
uses: paketo-buildpacks/github-config/actions/pull-request/open@main
with:
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
title: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}"
title: "Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
branch: automation/go-mod-update/update-main

failure:
Expand Down
6 changes: 3 additions & 3 deletions implementation/.github/workflows/update-go-mod-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
id: current-go-version
uses: paketo-buildpacks/github-config/actions/update-go-mod-version@main
with:
toolchain-version: ${{ steps.setup-go.outputs.go-version }}
go-version: ${{ steps.setup-go.outputs.go-version }}
- name: Go mod tidy
run: |
#!/usr/bin/env bash
Expand All @@ -54,7 +54,7 @@ jobs:
id: commit
uses: paketo-buildpacks/github-config/actions/pull-request/create-commit@main
with:
message: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}"
message: "Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
pathspec: "."
keyid: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY_ID }}
key: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY }}
Expand All @@ -70,7 +70,7 @@ jobs:
uses: paketo-buildpacks/github-config/actions/pull-request/open@main
with:
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
title: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}"
title: "Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
branch: automation/go-mod-update/update-main

failure:
Expand Down
6 changes: 3 additions & 3 deletions language-family/.github/workflows/update-go-mod-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
id: current-go-version
uses: paketo-buildpacks/github-config/actions/update-go-mod-version@main
with:
toolchain-version: ${{ steps.setup-go.outputs.go-version }}
go-version: ${{ steps.setup-go.outputs.go-version }}
- name: Go mod tidy
run: |
#!/usr/bin/env bash
Expand All @@ -54,7 +54,7 @@ jobs:
id: commit
uses: paketo-buildpacks/github-config/actions/pull-request/create-commit@main
with:
message: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}"
message: "Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
pathspec: "."
keyid: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY_ID }}
key: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY }}
Expand All @@ -70,7 +70,7 @@ jobs:
uses: paketo-buildpacks/github-config/actions/pull-request/open@main
with:
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
title: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}"
title: "Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
branch: automation/go-mod-update/update-main

failure:
Expand Down
6 changes: 3 additions & 3 deletions library/.github/workflows/update-go-mod-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
id: current-go-version
uses: paketo-buildpacks/github-config/actions/update-go-mod-version@main
with:
toolchain-version: ${{ steps.setup-go.outputs.go-version }}
go-version: ${{ steps.setup-go.outputs.go-version }}
- name: Go mod tidy
run: |
#!/usr/bin/env bash
Expand All @@ -54,7 +54,7 @@ jobs:
id: commit
uses: paketo-buildpacks/github-config/actions/pull-request/create-commit@main
with:
message: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}"
message: "Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
pathspec: "."
keyid: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY_ID }}
key: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY }}
Expand All @@ -70,7 +70,7 @@ jobs:
uses: paketo-buildpacks/github-config/actions/pull-request/open@main
with:
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
title: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}"
title: "Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
branch: automation/go-mod-update/update-main

failure:
Expand Down
6 changes: 3 additions & 3 deletions stack/.github/workflows/update-go-mod-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
id: current-go-version
uses: paketo-buildpacks/github-config/actions/update-go-mod-version@main
with:
toolchain-version: ${{ steps.setup-go.outputs.go-version }}
go-version: ${{ steps.setup-go.outputs.go-version }}
- name: Go mod tidy
run: |
#!/usr/bin/env bash
Expand All @@ -54,7 +54,7 @@ jobs:
id: commit
uses: paketo-buildpacks/github-config/actions/pull-request/create-commit@main
with:
message: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}"
message: "Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
pathspec: "."
keyid: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY_ID }}
key: ${{ secrets.PAKETO_BOT_GPG_SIGNING_KEY }}
Expand All @@ -70,7 +70,7 @@ jobs:
uses: paketo-buildpacks/github-config/actions/pull-request/open@main
with:
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
title: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}"
title: "Updates go mod version to ${{ steps.setup-go.outputs.go-version }}"
branch: automation/go-mod-update/update-main

failure:
Expand Down

0 comments on commit e55cef0

Please sign in to comment.