From 86971a5691dbbec9e41d5fa1a07cf20c0b982992 Mon Sep 17 00:00:00 2001 From: eikendev Date: Mon, 11 Apr 2022 18:05:30 +0200 Subject: [PATCH] Publish using GoReleaser --- .github/workflows/publish.yml | 53 ++++++++++++++++++++---- .github/workflows/{main.yml => test.yml} | 5 ++- .goreleaser.yml | 19 +++++++++ Makefile | 2 +- cmd/pushbits/main.go | 6 +-- 5 files changed, 71 insertions(+), 14 deletions(-) rename .github/workflows/{main.yml => test.yml} (91%) create mode 100644 .goreleaser.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3d7eeac..6a3a141 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,17 +5,10 @@ on: tags: - 'v[0-9]+.[0-9]+.[0-9]+' -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - jobs: - test_build_publish: - name: Test, build, and publish + test: + name: Test runs-on: ubuntu-latest - permissions: - contents: read - packages: write steps: - name: Checkout code uses: actions/checkout@v2 @@ -36,6 +29,24 @@ jobs: source $(poetry env info --path)/bin/activate make test + publish_docker_image: + name: Publish Docker image + needs: test + runs-on: ubuntu-latest + permissions: + packages: write + env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Export GOBIN + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - name: Set up QEMU uses: docker/setup-qemu-action@v1 @@ -69,3 +80,27 @@ jobs: platforms: linux/amd64,linux/arm64 cache-from: type=gha cache-to: type=gha,mode=max + + publish_github_release: + name: Publish GitHub Release + needs: test + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Export GOBIN + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/main.yml b/.github/workflows/test.yml similarity index 91% rename from .github/workflows/main.yml rename to .github/workflows/test.yml index 167b31b..742ceed 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Main +name: Test on: push: @@ -32,3 +32,6 @@ jobs: run: | source $(poetry env info --path)/bin/activate make test + + - name: Build + run: make build diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..646a62e --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,19 @@ +builds: + - id: pushbits + main: ./cmd/pushbits + goos: + - linux + goarch: + - amd64 + - arm64 + ldflags: + - -s -w -X main.version=v{{.Version}} + +checksum: + algorithm: sha256 + +archives: + - id: pushbits + builds: + - pushbits + format: tar.gz diff --git a/Makefile b/Makefile index 4ed7ae8..6f99f62 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ SEMGREP_MODFILE := $(TESTS_DIR)/semgrep-rules/go.mod .PHONY: build build: mkdir -p $(OUT_DIR) - go build -ldflags="-w -s -X main.Version=$(VERSION)" -o $(OUT_DIR)/pushbits ./cmd/pushbits + go build -ldflags="-w -s -X main.version=$(VERSION)" -o $(OUT_DIR)/pushbits ./cmd/pushbits .PHONY: clean clean: diff --git a/cmd/pushbits/main.go b/cmd/pushbits/main.go index 5bf37e3..dc36fec 100644 --- a/cmd/pushbits/main.go +++ b/cmd/pushbits/main.go @@ -14,7 +14,7 @@ import ( "github.com/pushbits/server/internal/runner" ) -var Version string +var version string func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) { c := make(chan os.Signal) @@ -44,10 +44,10 @@ func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) { // @securityDefinitions.basic BasicAuth func main() { - if len(Version) == 0 { + if len(version) == 0 { log.Panic("Version not set") } else { - log.Printf("Starting PushBits %s", Version) + log.Printf("Starting PushBits %s", version) } c := configuration.Get()