diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..4dd7f61c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: goreleaser + +on: + pull_request: + push: + # run only against tags + tags: + - "*" + +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 }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} \ 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..d975f9ae --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,90 @@ +version: 2 + +before: + hooks: + - go mod tidy + - 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}}' + - id: "backup-go" + skip: true + +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 + - 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 + - id: "backup-go" + format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{ .Version }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + +release: + # for tests, remove this line when everything is ready. + draft: true + skip_upload: true + + header: | + ## Release {{ .Version }} ({{ .Date }}) + - asbackup (CLI tool) + - asrestore (CLI tool) + - backup-go (library) + +changelog: + disable: true \ 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