Skip to content

Commit

Permalink
Merge branch 'main' into bufmod
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev committed Feb 2, 2024
2 parents cc087de + e8ea03b commit 78a606d
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/buf-binary-size.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: binary-size
on: push
# Prevent writing to the repository using the CI token.
# Ref: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#permissions
permissions: read-all
env:
MAKEFLAGS: "-j 2"
jobs:
buf-binary-size:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: setup-go
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- name: cache
uses: actions/cache@v4
with:
path: |
~/.cache/buf/${{ runner.os }}/x86_64/bin
~/.cache/buf/${{ runner.os }}/x86_64/go/pkg/mod
~/.cache/buf/${{ runner.os }}/x86_64/gocache
~/.cache/buf/${{ runner.os }}/x86_64/include
~/.cache/buf/${{ runner.os }}/x86_64/versions
key: ${{ runner.os }}-buf-${{ hashFiles('**/go.sum', 'make/**') }}
restore-keys: |
${{ runner.os }}-buf-
- name: make-bufbinarysize
run: make bufbinarysize
2 changes: 1 addition & 1 deletion Dockerfile.buf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -ldflags "-s -w" -trimpath -buildvcs=false -o /go/bin/buf ./cmd/buf

FROM --platform=${TARGETPLATFORM} alpine:3.19.0
FROM --platform=${TARGETPLATFORM} alpine:3.19.1

RUN apk add --update --no-cache \
ca-certificates \
Expand Down
4 changes: 4 additions & 0 deletions make/buf/all.mk
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ bufgeneratesteps:: \
bufrelease: $(MINISIGN)
DOCKER_IMAGE=golang:1.21-bullseye bash make/buf/scripts/release.bash

.PHONY: bufbinarysize
bufbinarysize:
@bash make/buf/scripts/binarysize.bash ./cmd/buf

.PHONY: updateversion
updateversion:
ifndef VERSION
Expand Down
32 changes: 32 additions & 0 deletions make/buf/scripts/binarysize.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -eo pipefail

DIR="$(CDPATH= cd "$(dirname "${0}")/../../.." && pwd)"
cd "${DIR}"

TMP="$(mktemp -d )"
trap 'rm -rf "${TMP}"' EXIT

fail() {
echo "error: $@" >&2
exit 1
}

size_bytes() {
case "$(uname -s)" in
Darwin) stat -f%z "${1}" ;;
Linux) stat -c%s "${1}" ;;
*) fail "must be run on darwin or linux" ;;
esac
}

# Build in the same manner as we do in release.bash.
CGO_ENABLED=0 \
GOOS=darwin \
GOARCH=arm64 \
go build -a -ldflags "-s -w" -trimpath -buildvcs=false \
-o "${TMP}/bin" \
"${1}"

echo "$(awk "BEGIN { printf(\"%.2f\", $(size_bytes "${TMP}/bin") / 1048576.0) }") MB"
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM alpine:3.19.0
FROM alpine:3.19.1

RUN echo "success"

0 comments on commit 78a606d

Please sign in to comment.