Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v4

- name: Check Dockerfile Go version sync
run: ./tools/sync-go-version.sh --check

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Check Dockerfile Go version sync
run: ./tools/sync-go-version.sh --check

- name: Docker build
run: docker build -t gibo:latest .
8 changes: 7 additions & 1 deletion .runny.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ commands:
run: go test ./...

update-deps:
run: go get -u . && go mod tidy
run: |
go get -u .
go mod tidy
./tools/sync-go-version.sh

check-go-version-sync:
run: ./tools/sync-go-version.sh --check

check-goreleaser:
run: goreleaser check .goreleaser.yaml .goreleaser.windows.yaml
56 changes: 56 additions & 0 deletions tools/sync-go-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

set -euo pipefail

mode="${1:-sync}"

go_version=$(awk '/^go / { print $2; exit }' go.mod)

if [ -z "$go_version" ]; then
echo "Unable to determine Go version from go.mod" >&2
exit 1
fi

go_image_version=$(echo "$go_version" | awk -F. '{ print $1 "." $2 }')
expected_image="golang:${go_image_version}-alpine"
expected_from="FROM ${expected_image} AS build"
current_from=$(awk '/^FROM golang:[^ ]+ AS build$/ { print; exit }' Dockerfile)

if [ -z "$current_from" ]; then
echo "Unable to determine Go build image from Dockerfile" >&2
exit 1
fi

if [ "$mode" = "--check" ]; then
if [ "$current_from" != "$expected_from" ]; then
echo "Dockerfile Go image is out of sync with go.mod" >&2
echo "Expected: ${expected_from}" >&2
echo "Found: ${current_from}" >&2
exit 1
fi

exit 0
fi

if [ "$mode" != "sync" ]; then
echo "Usage: $0 [sync|--check]" >&2
exit 1
fi

if [ "$current_from" = "$expected_from" ]; then
exit 0
fi

tmp_file=$(mktemp)

awk -v expected_from="$expected_from" '
BEGIN { updated = 0 }
/^FROM golang:[^ ]+ AS build$/ && !updated {
print expected_from
updated = 1
next
}
{ print }
' Dockerfile > "$tmp_file"

mv "$tmp_file" Dockerfile
Loading