From 5315e55625d1149a89a0fb91d13f0e87a0d76b12 Mon Sep 17 00:00:00 2001 From: Dmitrii Neeman Date: Sun, 27 Oct 2024 18:19:31 +0200 Subject: [PATCH] FMWK-579 Add release automation (#162) --- .github/workflows/release.yml | 29 +++++++++++ .gitignore | 2 + .goreleaser.yaml | 88 ++++++++++++++++++++++++++++++++++ Makefile | 25 +++++++++- cmd/asbackup/.goreleaser.yaml | 40 ---------------- cmd/asbackup/Makefile | 11 ----- cmd/asrestore/.goreleaser.yaml | 40 ---------------- cmd/asrestore/Makefile | 10 ---- 8 files changed, 142 insertions(+), 103 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yaml delete mode 100644 cmd/asbackup/.goreleaser.yaml delete mode 100644 cmd/asrestore/.goreleaser.yaml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..0be43ebf --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: goreleaser + +on: + release: + types: prereleased + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: stable + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: "~> v2" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 66375df6..fc360cb2 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ go.work main backup + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..1178f5a9 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,88 @@ +version: 2 + +before: + hooks: + - go mod tidy + - go install github.com/vektra/mockery/v2@v2.45.0 + - mockery --config=.mockery.yaml + +builds: + - id: "asbackup" + main: cmd/asbackup/main.go + binary: "asbackup" + goos: + - linux + - darwin + - windows + goarch: + - amd64 + - arm64 + env: + - CGO_ENABLED=0 + ldflags: + - -s -w -X 'main.appVersion={{.Version}}' -X 'main.commitHash={{.Commit}}' + - id: "asrestore" + main: cmd/asrestore/main.go + binary: "asrestore" + goos: + - linux + - darwin + - windows + goarch: + - amd64 + - arm64 + env: + - CGO_ENABLED=0 + ldflags: + - -s -w -X 'main.appVersion={{.Version}}' -X 'main.commitHash={{.Commit}}' + +archives: + - id: "asbackup" + format: tar.gz + name_template: >- + {{ .Binary }}_{{ .Version }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + format_overrides: + - goos: windows + format: zip + files: + - LICENSE + builds: + - "asbackup" + - id: "asrestore" + format: tar.gz + name_template: >- + {{ .Binary }}_{{ .Version }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + format_overrides: + - goos: windows + format: zip + files: + - LICENSE + builds: + - "asrestore" + +release: + prerelease: true + make_latest: false + replace_existing_artifacts: true + mode: prepend + header: | + ## Release {{ .Version }} ({{ .Date }}) + - asbackup (CLI tool) + - asrestore (CLI tool) + - backup-go (library) + +changelog: + disable: true + +checksum: + name_template: "checksums.txt" \ No newline at end of file diff --git a/Makefile b/Makefile index b1e34898..a761c3d3 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +VERSION := dev +COMMIT := $(shell git rev-parse --short HEAD) +LDFLAGS := -ldflags "-X 'main.appVersion=$(VERSION)' -X 'main.commitHash=$(COMMIT)'" + .PHONY: test test: go test -v ./... @@ -12,8 +16,9 @@ coverage: .PHONY: clean clean: mocks-clean rm -f coverage.cov + rm -Rf dist -# Install mockery for generating test mocks +# Install mockery for generating test mocks. .PHONY: mockery-install mockery-install: go install github.com/vektra/mockery/v2@v2.45.0 @@ -29,4 +34,20 @@ mocks-generate: mockery-install .PHONY: mocks-clean mocks-clean: @echo "Cleaning up all 'mocks' directories..." - @find . -type d -name 'mocks' -exec rm -rf {} + \ No newline at end of file + @find . -type d -name 'mocks' -exec rm -rf {} + + +# Build release locally. +.PHONY: release-test +release-test: + @echo "Testing release with version $(VERSION)..." + goreleaser build --snapshot + + +# Build CLI tools. +.PHONY: build +build: + mkdir dist + @echo "Building asbackup with version $(VERSION)..." + go build -o dist/asbackup cmd/asbackup/main.go + @echo "Building asrestore with version $(VERSION)..." + go build -o dist/asrestore cmd/asbackup/main.go diff --git a/cmd/asbackup/.goreleaser.yaml b/cmd/asbackup/.goreleaser.yaml deleted file mode 100644 index f0fd5693..00000000 --- a/cmd/asbackup/.goreleaser.yaml +++ /dev/null @@ -1,40 +0,0 @@ -version: 2 - -before: - hooks: - - go mod tidy - -builds: - - id: "asbackup" - main: ./main.go - binary: "asbackup" - goos: - - linux - - darwin - - windows - goarch: - - amd64 - - arm64 - env: - - CGO_ENABLED=0 - ldflags: - - -s -w -X 'main.appVersion={{.Version}}' -X 'main.commitHash={{.Commit}}' - -archives: - - format: tar.gz - name_template: >- - {{ .ProjectName }}_ - {{- title .Os }}_ - {{- if eq .Arch "amd64" }}x86_64 - {{- else if eq .Arch "386" }}i386 - {{- else }}{{ .Arch }}{{ end }} - {{- if .Arm }}v{{ .Arm }}{{ end }} - format_overrides: - - goos: windows - format: zip - -changelog: - sort: asc - filters: - exclude: - - "^Merge pull request" diff --git a/cmd/asbackup/Makefile b/cmd/asbackup/Makefile index d97c543f..72cf3c62 100644 --- a/cmd/asbackup/Makefile +++ b/cmd/asbackup/Makefile @@ -13,14 +13,3 @@ build: # Clean the build clean: rm -f $(OUTPUT) - rm -Rf dist - -# Build release locally -release-test: - @echo "Testing release of $(OUTPUT) with version $(VERSION)..." - goreleaser build --snapshot - -# Releasing -release: - @echo "Releasing $(OUTPUT) with version $(VERSION)..." - goreleaser release diff --git a/cmd/asrestore/.goreleaser.yaml b/cmd/asrestore/.goreleaser.yaml deleted file mode 100644 index d8a0816f..00000000 --- a/cmd/asrestore/.goreleaser.yaml +++ /dev/null @@ -1,40 +0,0 @@ -version: 2 - -before: - hooks: - - go mod tidy - -builds: - - id: "asrestore" - main: ./main.go - binary: "asrestore" - goos: - - linux - - darwin - - windows - goarch: - - amd64 - - arm64 - env: - - CGO_ENABLED=0 - ldflags: - - -s -w -X 'main.appVersion={{.Version}}' -X 'main.commitHash={{.Commit}}' - -archives: - - format: tar.gz - name_template: >- - {{ .ProjectName }}_ - {{- title .Os }}_ - {{- if eq .Arch "amd64" }}x86_64 - {{- else if eq .Arch "386" }}i386 - {{- else }}{{ .Arch }}{{ end }} - {{- if .Arm }}v{{ .Arm }}{{ end }} - format_overrides: - - goos: windows - format: zip - -changelog: - sort: asc - filters: - exclude: - - "^Merge pull request" diff --git a/cmd/asrestore/Makefile b/cmd/asrestore/Makefile index f4adf00c..4b5ca22b 100644 --- a/cmd/asrestore/Makefile +++ b/cmd/asrestore/Makefile @@ -14,13 +14,3 @@ build: clean: rm -f $(OUTPUT) rm -Rf dist - -# Build release locally -release-test: - @echo "Testing release of $(OUTPUT) with version $(VERSION)..." - goreleaser build --snapshot - -# Releasing -release: - @echo "Releasing $(OUTPUT) with version $(VERSION)..." - goreleaser release