Skip to content
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
25 changes: 25 additions & 0 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Tag

on:
push:
branches:
- main

jobs:
tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'

- name: Tag
run: hack/tag-release.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 changes: 37 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: 2

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
- arm
main: ./cmd/cs

changelog:
sort: asc
filters:
exclude:
- "^docs"
- "^test"
- "^devx"
- "^chore"

archives:
- formats: binary

release:
footer: >-

---

Released by [GoReleaser](https://github.com/goreleaser/goreleaser).
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@ test-cli:

test-service:
go test -count=1 -v ./service/...

format:
go fmt ./...

lint: install-build-deps
golangci-lint run

install-build-deps:
ifeq (, $(shell which mockery))
go install github.com/vektra/mockery/v3@v3.2.1
endif
ifeq (, $(shell which golangci-lint))
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.2
endif

generate: install-build-deps
go generate ./...
56 changes: 56 additions & 0 deletions hack/tag-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
# Copyright (c) Codesphere Inc.
# SPDX-License-Identifier: Apache-2.0


set -eu
BRANCH=$(git branch --show-current)
if [[ "$BRANCH" != "main" ]]; then
echo "This script should only run on main branch, not $BRANCH"
exit 1
fi
TAG=$(git tag | sort -uV | tail -n 1 | xargs echo -n)
LIST="HEAD"
if [[ "$TAG" != "" ]]; then
LIST="$TAG..HEAD"
fi
echo $LIST
LOG=$(git log "$LIST" --pretty=format:%s)
BREAK=$(grep -e '!' >/dev/null <<< "$LOG"; echo $?)
FEAT=$(grep -e '^feat' >/dev/null <<< "$LOG"; echo $?)
FIX=$(grep -e '^fix' >/dev/null <<< "$LOG"; echo $?)

echo "Latest tag: $TAG"
echo "------"
echo "Relevant changes:"
echo "$LOG"
echo "------"

if [[ "$TAG" == "" ]]; then
TAG=v0.0.0
fi
NEWTAG="$TAG"

if [[ $BREAK -eq 0 ]]; then
echo "Breaking change! Increasing major."
NEWTAG=$(sed -r 's/v([0-9]+)\.[0-9]+\.[0-9]+/echo "v$((\1+1)).0.0"/e' <<< "$TAG")
elif [[ $FEAT -eq 0 ]]; then
echo "New feature! Increasing minor."
NEWTAG=$(sed -r 's/v([0-9])+\.([0-9]+)\.[0-9]+/echo "v\1.$((\2+1)).0"/e' <<< "$TAG")
elif [[ $FIX -eq 0 ]]; then
echo "New fix! Increasing patch."
NEWTAG=$(sed -r 's/v([0-9])+\.([0-9]+)\.([0-9]+)/echo "v\1.\2.$((\3+1))"/e' <<< "$TAG")
fi

if [[ $NEWTAG == $TAG ]]; then
echo "Nothing to tag."
exit 0
fi

echo "Tagging $NEWTAG"
git tag "$NEWTAG"
git push origin "$NEWTAG"

echo "Triggering release of version $NEWTAG"
go install github.com/goreleaser/goreleaser/v2@latest
goreleaser release --clean