diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..7eedcf93 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,55 @@ +name: Build + +on: + push: + branches: + - main + - release-0.1x + tags: + - v[0-9]+.[0-9]+.[0-9]+* + pull_request: + +permissions: + contents: read + +jobs: + build: + name: Build + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + with: + go-version-file: ${{ github.workspace }}/go.mod + + - name: Set up QEMU + uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 + + - name: Dry-run GoReleaser + run: | + make release-dry-run + + - name: Run debug commands on failure + if: ${{ failure() }} + run: | + echo "--- Environment variables ---" + env | sort + echo "--- GO Environment ---" + go env | sort + echo "--- Git status ---" + git status + echo "--- Docker logs ---" + docker compose logs + echo "--- Docker ps ---" + docker compose ps -a diff --git a/.github/workflows/go.yml b/.github/workflows/test.yml similarity index 100% rename from .github/workflows/go.yml rename to .github/workflows/test.yml diff --git a/.goreleaser.yml b/.goreleaser.yml index 966c5c92..8fe5e9f9 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -4,6 +4,7 @@ builds: - binary: mongodb_exporter id: mongodb_exporter env: + - CGO_ENABLED=0 goos: - linux - darwin diff --git a/Makefile b/Makefile index e19f35ec..585b87cc 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all build clean default help init test format check-license +.PHONY: all build clean default help init test format check-license release-dry-run default: help GO_TEST_PATH ?= ./... @@ -83,6 +83,21 @@ release: ## Build the binaries using goreleaser -w /go/src/github.com/user/repo \ goreleaser/goreleaser release --snapshot --skip=publish --clean +release-dry-run: ## Build cross-platform binaries locally without publishing + @echo "Building cross-platform binaries with GoReleaser..." + @if command -v goreleaser >/dev/null 2>&1; then \ + goreleaser build --snapshot --clean; \ + else \ + echo "GoReleaser not found. Installing via Docker..."; \ + docker run --rm --privileged \ + -v ${PWD}:/go/src/github.com/percona/mongodb_exporter \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -w /go/src/github.com/percona/mongodb_exporter \ + goreleaser/goreleaser build --snapshot --clean; \ + fi + @find build -name mongodb_exporter -type f | sort + + FILES = $(shell find . -type f -name '*.go' -not -path "./vendor/*") format: ## Format source code