Skip to content

Commit 2cfb384

Browse files
authored
devx(release): Add release automation (#7)
* Adds automation for release generation * Adds some convenient make targets
1 parent 5c800ad commit 2cfb384

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

.github/workflows/tag-release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Tag
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
tag:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-tags: true
15+
fetch-depth: 0
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: '1.24'
21+
22+
- name: Tag
23+
run: hack/tag-release.sh
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: 2
2+
3+
before:
4+
hooks:
5+
- go mod tidy
6+
7+
builds:
8+
- env:
9+
- CGO_ENABLED=0
10+
goos:
11+
- linux
12+
- windows
13+
- darwin
14+
goarch:
15+
- amd64
16+
- arm64
17+
- arm
18+
main: ./cmd/cs
19+
20+
changelog:
21+
sort: asc
22+
filters:
23+
exclude:
24+
- "^docs"
25+
- "^test"
26+
- "^devx"
27+
- "^chore"
28+
29+
archives:
30+
- formats: binary
31+
32+
release:
33+
footer: >-
34+
35+
---
36+
37+
Released by [GoReleaser](https://github.com/goreleaser/goreleaser).

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,20 @@ test-cli:
1414

1515
test-service:
1616
go test -count=1 -v ./service/...
17+
18+
format:
19+
go fmt ./...
20+
21+
lint: install-build-deps
22+
golangci-lint run
23+
24+
install-build-deps:
25+
ifeq (, $(shell which mockery))
26+
go install github.com/vektra/mockery/v3@v3.2.1
27+
endif
28+
ifeq (, $(shell which golangci-lint))
29+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.2
30+
endif
31+
32+
generate: install-build-deps
33+
go generate ./...

hack/tag-release.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# Copyright (c) Codesphere Inc.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
6+
set -eu
7+
BRANCH=$(git branch --show-current)
8+
if [[ "$BRANCH" != "main" ]]; then
9+
echo "This script should only run on main branch, not $BRANCH"
10+
exit 1
11+
fi
12+
TAG=$(git tag | sort -uV | tail -n 1 | xargs echo -n)
13+
LIST="HEAD"
14+
if [[ "$TAG" != "" ]]; then
15+
LIST="$TAG..HEAD"
16+
fi
17+
echo $LIST
18+
LOG=$(git log "$LIST" --pretty=format:%s)
19+
BREAK=$(grep -e '!' >/dev/null <<< "$LOG"; echo $?)
20+
FEAT=$(grep -e '^feat' >/dev/null <<< "$LOG"; echo $?)
21+
FIX=$(grep -e '^fix' >/dev/null <<< "$LOG"; echo $?)
22+
23+
echo "Latest tag: $TAG"
24+
echo "------"
25+
echo "Relevant changes:"
26+
echo "$LOG"
27+
echo "------"
28+
29+
if [[ "$TAG" == "" ]]; then
30+
TAG=v0.0.0
31+
fi
32+
NEWTAG="$TAG"
33+
34+
if [[ $BREAK -eq 0 ]]; then
35+
echo "Breaking change! Increasing major."
36+
NEWTAG=$(sed -r 's/v([0-9]+)\.[0-9]+\.[0-9]+/echo "v$((\1+1)).0.0"/e' <<< "$TAG")
37+
elif [[ $FEAT -eq 0 ]]; then
38+
echo "New feature! Increasing minor."
39+
NEWTAG=$(sed -r 's/v([0-9])+\.([0-9]+)\.[0-9]+/echo "v\1.$((\2+1)).0"/e' <<< "$TAG")
40+
elif [[ $FIX -eq 0 ]]; then
41+
echo "New fix! Increasing patch."
42+
NEWTAG=$(sed -r 's/v([0-9])+\.([0-9]+)\.([0-9]+)/echo "v\1.\2.$((\3+1))"/e' <<< "$TAG")
43+
fi
44+
45+
if [[ $NEWTAG == $TAG ]]; then
46+
echo "Nothing to tag."
47+
exit 0
48+
fi
49+
50+
echo "Tagging $NEWTAG"
51+
git tag "$NEWTAG"
52+
git push origin "$NEWTAG"
53+
54+
echo "Triggering release of version $NEWTAG"
55+
go install github.com/goreleaser/goreleaser/v2@latest
56+
goreleaser release --clean

0 commit comments

Comments
 (0)