Skip to content

Commit b9e3773

Browse files
committed
chore: add scripts and workflows for release
1 parent b049aac commit b9e3773

File tree

6 files changed

+171
-0
lines changed

6 files changed

+171
-0
lines changed

.github/workflows/commitlint.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Lint Commit Messages
2+
on: [pull_request]
3+
4+
jobs:
5+
commit_lint:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Check out code
9+
uses: actions/checkout@v4
10+
with:
11+
fetch-depth: 0
12+
13+
- name: Run linter
14+
uses: wagoid/commitlint-github-action@v6

.github/workflows/golangci-lint.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: golangci-lint
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- main
9+
pull_request:
10+
11+
jobs:
12+
golangci_lint:
13+
name: Golang-CI (lint)
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Check out code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5 # action page: <https://github.com/actions/setup-go>
21+
with:
22+
go-version: '1.23'
23+
24+
- name: Run linter
25+
uses: golangci/golangci-lint-action@v6
26+
with:
27+
version: v1.60
28+
args: -v --build-tags=race --timeout=5m

.github/workflows/release.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Releases
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out code
13+
uses: actions/checkout@v4
14+
15+
- name: Create Release
16+
uses: ncipollo/release-action@v1

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
2+
3+
test:
4+
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
5+
echo "go test in $${dir}"; \
6+
(cd "$${dir}" && \
7+
go test && \
8+
go vet); \
9+
done
10+
11+
go_mod_tidy:
12+
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
13+
echo "go mod tidy in $${dir}"; \
14+
(cd "$${dir}" && \
15+
go get -u ./... && \
16+
go mod tidy); \
17+
done
18+
19+
fmt:
20+
gofmt -w -s ./
21+
goimports -w -local github.com/gowool/logwise/v2 ./

scripts/release.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
help() {
6+
cat <<- EOF
7+
Usage: TAG=tag $0
8+
9+
Updates version in go.mod files and pushes a new branch to GitHub.
10+
11+
VARIABLES:
12+
TAG git tag, for example, v1.0.0
13+
EOF
14+
exit 0
15+
}
16+
17+
if [ -z "$TAG" ]
18+
then
19+
printf "TAG is required\n\n"
20+
help
21+
fi
22+
23+
TAG_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
24+
if ! [[ "${TAG}" =~ ${TAG_REGEX} ]]; then
25+
printf "TAG is not valid: %s\n\n" "${TAG}"
26+
exit 1
27+
fi
28+
29+
TAG_FOUND=$(git tag --list "${TAG}")
30+
if [[ ${TAG_FOUND} = ${TAG} ]] ; then
31+
printf "tag %s already exists\n\n" "${TAG}"
32+
exit 1
33+
fi
34+
35+
if ! git diff --quiet
36+
then
37+
printf "working tree is not clean\n\n"
38+
git status
39+
exit 1
40+
fi
41+
42+
git checkout main
43+
make go_mod_tidy
44+
45+
PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; \
46+
| sed 's/^\.\///' \
47+
| sort)
48+
49+
for dir in $PACKAGE_DIRS
50+
do
51+
sed -i '' "s@gowool/logwise/v2\([^ ]*\) v.*@gowool/logwise/v2\1 ${TAG}@" "${dir}/go.mod"
52+
done
53+
54+
git checkout -b "release/${TAG}" main
55+
git add -u
56+
git commit -m "chore: release $TAG (release.sh)"
57+
git push origin "release/${TAG}"

scripts/tag.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
help() {
6+
cat <<- EOF
7+
Usage: TAG=tag $0
8+
9+
Creates git tags for public Go packages.
10+
11+
VARIABLES:
12+
TAG git tag, for example, v1.0.0
13+
EOF
14+
exit 0
15+
}
16+
17+
if [ -z "$TAG" ]
18+
then
19+
printf "TAG env var is required\n\n";
20+
help
21+
fi
22+
23+
PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; \
24+
| sed 's/^\.\///' \
25+
| sort)
26+
27+
git tag "${TAG}"
28+
git push origin "${TAG}"
29+
30+
for dir in $PACKAGE_DIRS
31+
do
32+
printf "tagging %s/%s\n" "${dir}" "${TAG}"
33+
git tag "${dir}/${TAG}"
34+
git push origin "${dir}/${TAG}"
35+
done

0 commit comments

Comments
 (0)