From af665207c8cc74ac0e2eadf8f2840b452b0d6d94 Mon Sep 17 00:00:00 2001 From: Nguyen Marc Date: Fri, 1 Dec 2023 22:31:55 +0100 Subject: [PATCH] feat(ci): add binary releases --- .github/workflows/golang.yml | 45 +++++++++++++++++++++++-- Makefile | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 2 deletions(-) diff --git a/.github/workflows/golang.yml b/.github/workflows/golang.yml index edff923..b9ffd24 100644 --- a/.github/workflows/golang.yml +++ b/.github/workflows/golang.yml @@ -66,8 +66,8 @@ jobs: - name: Run tests run: go test -race -covermode=atomic -timeout=30s ./... - build-go: - name: Build Go + build-go-docker: + name: Build Docker runs-on: ubuntu-latest @@ -125,3 +125,44 @@ jobs: ${{ steps.get_version.outputs.VERSION }} cache-from: type=gha cache-to: type=gha,mode=max + + build: + name: Build Go + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Download build-essential + run: | + sudo apt update -y + sudo apt install -y make build-essential + + - uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + check-latest: true + cache-dependency-path: go.mod + + - name: Build + run: | + make build-all + + - name: Get the version + if: startsWith(github.ref, 'refs/tags/') + id: get_version + run: | + VERSION=$(echo ${GITHUB_REF#refs/*/} + echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT + + - uses: sersoft-gmbh/setup-gh-cli-action@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + version: stable + + - name: Create release and upload binaries + if: startsWith(github.ref, 'refs/tags/') + run: gh release create ${{ steps.branch_name.outputs.VERSION }} -t ${{ steps.branch_name.outputs.VERSION }} -F bin/checksums.md --prerelease=${{ contains(steps.get_version.outputs.VERSION, '-') }} bin/dpsproxy-* bin/checksums.txt + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile index fee5437..15d7ea2 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,70 @@ bin/dpsproxy-server: $(GO_SRCS) bin/dpsproxy: $(GO_SRCS) go build -trimpath -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go + +bin/checksums.txt: $(addprefix bin/,$(bins)) + sha256sum -b $(addprefix bin/,$(bins)) | sed 's/bin\///' > $@ + +bin/checksums.md: bin/checksums.txt + @echo "### SHA256 Checksums" > $@ + @echo >> $@ + @echo "\`\`\`" >> $@ + @cat $< >> $@ + @echo "\`\`\`" >> $@ + +bin/dpsproxy-server-darwin-amd64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go + +bin/dpsproxy-server-darwin-arm64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go + +bin/dpsproxy-server-freebsd-amd64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go + +bin/dpsproxy-server-freebsd-arm64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go + +bin/dpsproxy-server-linux-amd64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go + +bin/dpsproxy-server-linux-arm64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go + +bin/dpsproxy-server-linux-riscv64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=linux GOARCH=riscv64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go + +bin/dpsproxy-server-windows-amd64.exe: $(GO_SRCS) + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy-server/main.go + +bin/dpsproxy-darwin-amd64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go + +bin/dpsproxy-darwin-arm64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go + +bin/dpsproxy-freebsd-amd64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go + +bin/dpsproxy-freebsd-arm64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go + +bin/dpsproxy-linux-amd64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go + +bin/dpsproxy-linux-arm64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go + +bin/dpsproxy-linux-riscv64: $(GO_SRCS) + CGO_ENABLED=0 GOOS=linux GOARCH=riscv64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go + +bin/dpsproxy-windows-amd64.exe: $(GO_SRCS) + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -o "$@" ./cmd/dpsproxy/main.go + +bins := dpsproxy-server-darwin-amd64 dpsproxy-server-darwin-arm64 dpsproxy-server-freebsd-arm64 dpsproxy-server-freebsd-arm64 dpsproxy-server-linux-amd64 dpsproxy-server-linux-arm64 dpsproxy-server-linux-riscv64 dpsproxy-server-windows-amd64.exe dpsproxy-darwin-amd64 dpsproxy-darwin-arm64 dpsproxy-freebsd-arm64 dpsproxy-freebsd-arm64 dpsproxy-linux-amd64 dpsproxy-linux-arm64 dpsproxy-linux-riscv64 dpsproxy-windows-amd64.exe + +.PHONY: build-all +build-all: $(addprefix bin/,$(bins)) bin/checksums.md + .PHONY: run run: bin/dpsproxy-server @bin/dpsproxy-server