From 2831e1585ccc80588bd2f6c241c9406359f17d1c Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 8 Sep 2024 21:57:52 -0700 Subject: [PATCH] Build and attach release binaries in GH Action (#945) --- .github/workflows/release.yml | 32 ++++++++++++++++++++++++++++++++ .github/workflows/tests.yml | 24 +++++++++++++++++------- Makefile | 16 ++++------------ README.md | 2 +- docker/Dockerfile | 4 +++- package-github-binaries.sh | 26 ++++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100755 package-github-binaries.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..0d4925db --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: Release + +on: + push: + tags: + - 'v*' + +jobs: + release-binaries: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: '1.23' + + - name: Build binaries + run: | + make build-all-binaries + ls -la + ./package-github-binaries.sh + ls -la dist/ + + - name: Add binaries to release + uses: ncipollo/release-action@v1 + with: + artifacts: "dist/*" + allowUpdates: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 03d0ee48..5d5be964 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -42,13 +42,12 @@ jobs: make test - name: Upload coverage to Codecov - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - run: | - curl -Os https://uploader.codecov.io/latest/linux/codecov - chmod +x codecov - ./codecov -t $CODECOV_TOKEN -f coverage.txt - + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true + files: ./coverage.txt + token: ${{ secrets.CODECOV_TOKEN }} # required + verbose: true - name: Upload coverage to Coveralls uses: coverallsapp/github-action@v2 @@ -101,3 +100,14 @@ jobs: - name: Generate mixin run: make mixin + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Test Docker Build + uses: docker/build-push-action@v6 + with: + push: false + tags: user/app:tst + file: docker/Dockerfile + build-args: "GOARCH=amd64" diff --git a/Makefile b/Makefile index d80143e1..f62579c5 100644 --- a/Makefile +++ b/Makefile @@ -13,18 +13,18 @@ docker-all: docker-env-up docker-test docker-env-down .PHONY: docker-env-up docker-env-up: - $(DOCKER_COMPOSE) -f contrib/docker-compose-for-tests.yml up -d + $(DOCKER_COMPOSE) -f docker-compose.yml up -d .PHONY: docker-env-down docker-env-down: - $(DOCKER_COMPOSE) -f contrib/docker-compose-for-tests.yml down + $(DOCKER_COMPOSE) -f docker-compose.yml down .PHONY: docker-test docker-test: - $(DOCKER_COMPOSE) -f contrib/docker-compose-for-tests.yml up -d - $(DOCKER_COMPOSE) -f contrib/docker-compose-for-tests.yml run --rm tests bash -c 'make test' + $(DOCKER_COMPOSE) -f docker-compose.yml up -d + $(DOCKER_COMPOSE) -f docker-compose.yml run --rm tests bash -c 'make test' @@ -68,14 +68,6 @@ mixin: $(MAKE) all && \ cd ../../ -.PHONY: upload-coverage -upload-coverage: - go install github.com/mattn/goveralls@v0.0.11 - which goveralls - echo $PATH - /home/runner/go/bin/goveralls -coverprofile=coverage.txt -service=drone.io - - BUILD_DT:=$(shell date +%F-%T) GO_LDFLAGS:="-s -w -extldflags \"-static\" -X main.BuildVersion=${DRONE_TAG} -X main.BuildCommitSha=${DRONE_COMMIT_SHA} -X main.BuildDate=$(BUILD_DT)" diff --git a/README.md b/README.md index b20f148c..dd1948e1 100644 --- a/README.md +++ b/README.md @@ -335,7 +335,7 @@ With this count, we can take following actions such as Create alerts or dashboar The tests require a variety of real Redis instances to not only verify correctness of the exporter but also compatibility with older versions of Redis and with Redis-like systems like KeyDB or Tile38.\ -The [contrib/docker-compose-for-tests.yml](./contrib/docker-compose-for-tests.yml) file has service definitions for +The [docker-compose.yml](docker-compose.yml) file has service definitions for everything that's needed.\ You can bring up the Redis test instances first by running `make docker-env-up` and then, every time you want to run the tests, you can run `make docker-test`. This will mount the current directory (with the .go source files) into a docker container and kick off the tests.\ Once you're done testing you can bring down the stack by running `make docker-env-down`.\ diff --git a/docker/Dockerfile b/docker/Dockerfile index cbcdc8f7..63843452 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,7 +11,9 @@ ARG SHA1="[no-sha]" ARG TAG="[no-tag]" ARG GOARCH -RUN printf "nameserver 1.1.1.1\nnameserver 8.8.8.8"> /etc/resolv.conf \ && apk --no-cache add ca-certificates git +#RUN printf "nameserver 1.1.1.1\nnameserver 8.8.8.8"> /etc/resolv.conf \ && apk --no-cache add ca-certificates git + +RUN apk --no-cache add ca-certificates git RUN BUILD_DATE=$(date +%F-%T) CGO_ENABLED=0 GOOS=linux GOARCH=$GOARCH go build -o /redis_exporter \ -ldflags "-s -w -extldflags \"-static\" -X main.BuildVersion=$TAG -X main.BuildCommitSha=$SHA1 -X main.BuildDate=$BUILD_DATE" . diff --git a/package-github-binaries.sh b/package-github-binaries.sh new file mode 100755 index 00000000..619b0755 --- /dev/null +++ b/package-github-binaries.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -u -e -o pipefail + +mkdir -p dist + +for build in $(ls .build); do + echo "Creating archive for ${build}" + + cp LICENSE README.md ".build/${build}/" + + if [[ "${build}" =~ windows-.*$ ]] ; then + + # Make sure to clear out zip files to prevent zip from appending to the archive. + rm "dist/${build}.zip" || true + cd ".build/" && zip -r --quiet -9 "../dist/${build}.zip" "${build}" && cd ../ + else + tar -C ".build/" -czf "dist/${build}.tar.gz" "${build}" + fi +done + +cd dist +sha256sum *.gz *.zip > sha256sums.txt +ls -la +cd .. +