Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMWK-579 Add release automation #162

Merged
merged 17 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ go.work

main
backup

dist/
88 changes: 88 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
version: 2

before:
hooks:
- go mod tidy
- go install github.com/vektra/mockery/[email protected]
- 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"
25 changes: 23 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 ./...
Expand All @@ -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/[email protected]
Expand All @@ -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 {} +
@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
40 changes: 0 additions & 40 deletions cmd/asbackup/.goreleaser.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions cmd/asbackup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 0 additions & 40 deletions cmd/asrestore/.goreleaser.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions cmd/asrestore/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading