From 3f8b96ecedaaca32eb76f8f53dbc6580973772dd Mon Sep 17 00:00:00 2001 From: eminano Date: Wed, 10 Jul 2024 14:29:53 +0200 Subject: [PATCH 1/2] Add build and release steps to CI --- .github/workflows/build.yml | 71 +++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e90c812..e7755ba 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,3 +73,74 @@ jobs: - name: Ensure .go files have a license reference run: make license-check + + build: + runs-on: ubuntu-latest + needs: [test, lint, integration-test] + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.22" + + - name: Build pgstream (Linux amd64) + run: GOOS=linux GOARCH=amd64 go build -o pgstream.linux.amd64 + + - name: Build pgstream (Linux arm64) + run: GOOS=linux GOARCH=arm64 go build -o pgstream.linux.arm64 + + - name: Build pgstream (MacOS amd64) + run: GOOS=darwin GOARCH=amd64 go build -o pgstream.macos.amd64 + + - name: Build pgstream (MacOS arm64) + run: GOOS=darwin GOARCH=arm64 go build -o pgstream.macos.arm64 + + - name: Build pgstream (Windows) + run: GOOS=windows GOARCH=amd64 go build -o pgstream.win.amd64 + + - uses: actions/upload-artifact@v3 + with: + name: pgstream.linux.amd64 + path: pgstream.linux.amd64 + + - uses: actions/upload-artifact@v3 + with: + name: pgstream.linux.arm64 + path: pgstream.linux.arm64 + + - uses: actions/upload-artifact@v3 + with: + name: pgstream.macos.amd64 + path: pgstream.macos.amd64 + + - uses: actions/upload-artifact@v3 + with: + name: pgstream.macos.arm64 + path: pgstream.macos.arm64 + + - uses: actions/upload-artifact@v3 + with: + name: pgstream.win.amd64 + path: pgstream.win.amd64 + + release: + runs-on: ubuntu-latest + needs: [build] + if: startsWith(github.ref, 'refs/tags/') + steps: + - uses: actions/download-artifact@v3 + with: + path: artifacts + + - name: Release + uses: softprops/action-gh-release@v1 + with: + fail_on_unmatched_files: true + files: | + artifacts/pgstream.linux.amd64/pgstream.linux.amd64 + artifacts/pgstream.linux.arm64/pgstream.linux.arm64 + artifacts/pgstream.macos.amd64/pgstream.macos.amd64 + artifacts/pgstream.macos.arm64/pgstream.macos.arm64 + artifacts/pgstream.win.amd64/pgstream.win.amd64 From 7e5261a34b50759bd72085b3d91f29dcb5ef346e Mon Sep 17 00:00:00 2001 From: eminano Date: Wed, 10 Jul 2024 14:59:44 +0200 Subject: [PATCH 2/2] Use goreleaser --- .github/workflows/build.yml | 89 +++++++++++++------------------------ .goreleaser.yaml | 86 +++++++++++++++++++++++++++++++++++ Dockerfile | 3 ++ 3 files changed, 120 insertions(+), 58 deletions(-) create mode 100644 .goreleaser.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e7755ba..2e3f908 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -74,73 +74,46 @@ jobs: - name: Ensure .go files have a license reference run: make license-check - build: + release: runs-on: ubuntu-latest - needs: [test, lint, integration-test] + needs: [test, integration-test, lint, license-check] + if: startsWith(github.ref, 'refs/tags/') + env: + DOCKER_CLI_EXPERIMENTAL: "enabled" steps: - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 with: - go-version: "1.22" - - - name: Build pgstream (Linux amd64) - run: GOOS=linux GOARCH=amd64 go build -o pgstream.linux.amd64 + fetch-depth: 0 - - name: Build pgstream (Linux arm64) - run: GOOS=linux GOARCH=arm64 go build -o pgstream.linux.arm64 + - run: git fetch --force --tags - - name: Build pgstream (MacOS amd64) - run: GOOS=darwin GOARCH=amd64 go build -o pgstream.macos.amd64 - - - name: Build pgstream (MacOS arm64) - run: GOOS=darwin GOARCH=arm64 go build -o pgstream.macos.arm64 - - - name: Build pgstream (Windows) - run: GOOS=windows GOARCH=amd64 go build -o pgstream.win.amd64 - - - uses: actions/upload-artifact@v3 - with: - name: pgstream.linux.amd64 - path: pgstream.linux.amd64 - - - uses: actions/upload-artifact@v3 - with: - name: pgstream.linux.arm64 - path: pgstream.linux.arm64 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - uses: actions/upload-artifact@v3 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 with: - name: pgstream.macos.amd64 - path: pgstream.macos.amd64 + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/upload-artifact@v3 - with: - name: pgstream.macos.arm64 - path: pgstream.macos.arm64 - - - uses: actions/upload-artifact@v3 - with: - name: pgstream.win.amd64 - path: pgstream.win.amd64 - - release: - runs-on: ubuntu-latest - needs: [build] - if: startsWith(github.ref, 'refs/tags/') - steps: - - uses: actions/download-artifact@v3 + - name: Set up Go + uses: actions/setup-go@v5 with: - path: artifacts + go-version-file: "go.mod" - - name: Release - uses: softprops/action-gh-release@v1 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 with: - fail_on_unmatched_files: true - files: | - artifacts/pgstream.linux.amd64/pgstream.linux.amd64 - artifacts/pgstream.linux.arm64/pgstream.linux.arm64 - artifacts/pgstream.macos.amd64/pgstream.macos.amd64 - artifacts/pgstream.macos.arm64/pgstream.macos.arm64 - artifacts/pgstream.win.amd64/pgstream.win.amd64 + distribution: goreleaser + version: latest + args: release --clean + env: + # We use two github tokens here: + # * The actions-bound `GITHUB_TOKEN` with permissions to write packages. + # * The org level `GIT_TOKEN` to be able to publish the brew tap file. + # See: https://goreleaser.com/errors/resource-not-accessible-by-integration/ + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAP_GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} + GITHUB_USERNAME: ${{ github.repository_owner }} + DOCKER_USERNAME: ghcr.io/${{ github.repository_owner }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..9d888cb --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,86 @@ +project_name: pgstream + +before: + hooks: + - go mod tidy + +builds: + - id: build_noncgo + binary: pgstream + ldflags: + - -X github.com/xataio/pgstream/cmd.Version={{ .Version }} + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + ignore: + - goos: windows + goarch: arm64 + +release: + draft: true + +brews: + - name: pgstream + homepage: "https://www.xata.io" + description: "PostgreSQL replication with DDL changes" + license: "Apache-2.0" + repository: + token: "{{ .Env.TAP_GITHUB_TOKEN }}" + owner: "{{ .Env.GITHUB_USERNAME }}" + name: homebrew-pgstream + +archives: + - format: binary + name_template: >- + {{ .ProjectName }}.{{ if eq .Os "windows" }}win{{ else if eq .Os "darwin" }}macos{{ else }}{{ .Os }}{{ end }}.{{ .Arch }} + files: + - LICENSE* + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +dockers: + - image_templates: + - "{{ .Env.DOCKER_USERNAME }}/{{ .ProjectName }}:{{ .Tag }}-amd64" + dockerfile: Dockerfile + use: buildx + build_flag_templates: + - --platform=linux/amd64 + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://github.com/{{ .Env.GITHUB_USERNAME }}/{{ .ProjectName }} + - --label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_USERNAME }}/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.created={{ .Date }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=AL2.0 + - image_templates: + - "{{ .Env.DOCKER_USERNAME }}/{{ .ProjectName }}:{{ .Tag }}-arm64v8" + goarch: arm64 + dockerfile: Dockerfile + use: buildx + build_flag_templates: + - --platform=linux/arm64/v8 + - --label=org.opencontainers.image.title={{ .ProjectName }} + - --label=org.opencontainers.image.description={{ .ProjectName }} + - --label=org.opencontainers.image.url=https://github.com/{{ .Env.GITHUB_USERNAME }}/{{ .ProjectName }} + - --label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_USERNAME }}/{{ .ProjectName }} + - --label=org.opencontainers.image.version={{ .Version }} + - --label=org.opencontainers.image.created={{ .Date }} + - --label=org.opencontainers.image.revision={{ .FullCommit }} + - --label=org.opencontainers.image.licenses=AL2.0 +docker_manifests: + - name_template: "{{ .Env.DOCKER_USERNAME }}/{{ .ProjectName }}:{{ .Tag }}" + image_templates: + - "{{ .Env.DOCKER_USERNAME }}/{{ .ProjectName }}:{{ .Tag }}-amd64" + - "{{ .Env.DOCKER_USERNAME }}/{{ .ProjectName }}:{{ .Tag }}-arm64v8" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7258195 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM scratch +COPY pgstream /usr/bin/pgstream +ENTRYPOINT [ "/usr/bin/pgstream" ]