diff --git a/.github/Dockerfile b/.github/Dockerfile new file mode 100644 index 00000000..093bbead --- /dev/null +++ b/.github/Dockerfile @@ -0,0 +1,23 @@ +# +# This Dockerfile builds the image in which cross-platform builds are run. +# +# The reason for using a custom image is that the official +# `goreleaser/goreleaser-cross` image at the time of writing used Goreleaser +# v2.4.4, which had a bug breaking the `builds.overrides` section of the +# `.goreleaser.yaml` file (see +# https://github.com/goreleaser/goreleaser/pull/5298). Once a version of +# `goreleaser/goreleaser-cross` is available using Goreleaser >= 2.4.8 we +# should be able to switch back to the official images. +# +# This image was built and pushed to `surjection/goreleaser-cross:v1.23-v2.4.8` +# + +FROM goreleaser/goreleaser-cross:v1.23-v2.4.4 + +WORKDIR /tmp + +RUN wget https://github.com/goreleaser/goreleaser/releases/download/v2.4.8/goreleaser_Linux_x86_64.tar.gz \ + && tar -xvzf goreleaser_Linux_x86_64.tar.gz \ + && mv goreleaser /usr/bin/goreleaser + +WORKDIR / diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 116c3dc3..9d130ec0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,35 @@ permissions: contents: write packages: write jobs: + cross-build: + name: cross-platform build + runs-on: ubuntu-24.04 + container: + image: surjection/goreleaser-cross:v1.23-v2.4.8 + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: 'go.mod' + + # Mark the checkout as 'safe' despite being owned by `root` + - run: git config --global --add safe.directory $GITHUB_WORKSPACE + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: '~> v2' + args: build --snapshot + + - uses: actions/upload-artifact@v4 + with: + name: platform-binaries + path: dist/ + if-no-files-found: error + test: name: 'test (pg: ${{ matrix.pgVersion }}, schema: ${{ matrix.testSchema }})' runs-on: ubuntu-24.04 @@ -192,7 +221,7 @@ jobs: release: runs-on: ubuntu-24.04 - needs: [test, lint, examples-schema-validation, examples, license-check, type-generation, dead-code-check, check-ledger] + needs: [test, lint, examples-schema-validation, examples, license-check, type-generation, dead-code-check, check-ledger, cross-build] if: startsWith(github.ref, 'refs/tags/') env: DOCKER_CLI_EXPERIMENTAL: "enabled" @@ -219,10 +248,10 @@ jobs: go-version-file: 'go.mod' - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v5 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser - version: latest + version: '~> v2' args: release --clean env: # We use two GitHub tokens here: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index ea365ac0..1981ed05 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,3 +1,5 @@ +version: 2 + project_name: pgroll before: @@ -5,12 +7,12 @@ before: - go mod tidy builds: - - id: build_noncgo + - id: build_cgo binary: pgroll ldflags: - -X github.com/xataio/pgroll/cmd.Version={{ .Version }} env: - - CGO_ENABLED=0 + - CGO_ENABLED=1 goos: - linux - windows @@ -21,6 +23,28 @@ builds: ignore: - goos: windows goarch: arm64 + overrides: + - goos: windows + goarch: amd64 + env: + - CC=x86_64-w64-mingw32-gcc + - CGO_LDFLAGS=-lssp -static + - goos: linux + goarch: amd64 + env: + - CC=x86_64-linux-gnu-gcc + - goos: linux + goarch: arm64 + env: + - CC=aarch64-linux-gnu-gcc + - goos: darwin + goarch: amd64 + env: + - CC=o64-clang + - goos: darwin + goarch: arm64 + env: + - CC=oa64-clang release: draft: true