From d37eeae0f9e99092e53c17b307bb4c3604d3bb99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mudrini=C4=87?= Date: Thu, 6 Mar 2025 12:03:46 +0100 Subject: [PATCH 1/2] Add goreleaser-based release GitHub Action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marko Mudrinić --- .github/workflows/release.yml | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..93dba91 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,59 @@ +name: goreleaser + +on: + pull_request: + paths: + - .github/workflows/release.yml + - .goreleaser.yaml + push: + tags: + - 'v*' + +permissions: + contents: read + +jobs: + release: + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-go@v5 + with: + go-version: v1.22.10 + + - name: Delete non-semver tags + run: 'git tag -d $(git tag -l | grep -v "^v")' + + - name: Run GoReleaser on tag + if: github.event_name != 'pull_request' + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: latest + args: release --timeout 60m + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Run GoReleaser on pull request + if: github.event_name == 'pull_request' + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: latest + args: release --timeout 60m --snapshot + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/upload-artifact@v4 + if: ${{ always() }} + with: + name: binaries + path: dist/*.tar.gz From c4a88646aeceabd4f166852a78c0a1e98df0d7b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mudrini=C4=87?= Date: Thu, 6 Mar 2025 13:16:25 +0100 Subject: [PATCH 2/2] Add GoReleaser config file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marko Mudrinić --- .github/workflows/release.yml | 11 +++++++---- .gitignore | 1 + .goreleaser.yaml | 37 +++++++++++++++++++++++++++++++++++ Makefile | 3 +++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 93dba91..211c866 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,11 +3,11 @@ name: goreleaser on: pull_request: paths: - - .github/workflows/release.yml - - .goreleaser.yaml + - .github/workflows/release.yml + - .goreleaser.yaml push: tags: - - 'v*' + - 'v*' permissions: contents: read @@ -31,6 +31,9 @@ jobs: - name: Delete non-semver tags run: 'git tag -d $(git tag -l | grep -v "^v")' + + - name: Set LDFLAGS + run: echo LDFLAGS="$(make ldflags)" >> $GITHUB_ENV - name: Run GoReleaser on tag if: github.event_name != 'pull_request' @@ -53,7 +56,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: actions/upload-artifact@v4 - if: ${{ always() }} + if: github.event_name == 'pull_request' with: name: binaries path: dist/*.tar.gz diff --git a/.gitignore b/.gitignore index db758ac..9526eb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /_build/ +/dist/ /_tools/ /vendor/ /.kcp.e2e/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..55476a3 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,37 @@ +# Copyright 2025 The KCP Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +builds: + - id: "api-syncagent" + main: ./cmd/api-syncagent + binary: api-syncagent + ldflags: + - "{{ .Env.LDFLAGS }}" + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + env: + - CGO_ENABLED=0 + +archives: + - id: api-syncagent + builds: + - api-syncagent + +release: + draft: true + mode: keep-existing diff --git a/Makefile b/Makefile index 504a8f3..b81fc7d 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,9 @@ GOOS ?= $(shell go env GOOS) .PHONY: all all: build test +ldflags: + @echo $(LDFLAGS) + .PHONY: build build: $(CMD)