Skip to content

Commit 1a8399a

Browse files
committed
chore: add CI, release workflow, Justfile, golangci-lint, version tracking
- CI: lint (golangci-lint) + test (ubuntu/macos matrix) + build - Release: tag-triggered release PR + auto GitHub Release via git-cliff - Justfile: fmt, lint, test, build, version management, release helpers - .golangci.yml: curated linter set adapted from 1money-go-sdk - version.go: embedded version constant, updated by release workflow - cliff.toml: conventional commit changelog generation - .editorconfig: consistent formatting across editors
1 parent f753ff4 commit 1a8399a

File tree

9 files changed

+716
-2
lines changed

9 files changed

+716
-2
lines changed

.editorconfig

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# EditorConfig configuration
2+
# https://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.go]
13+
indent_style = tab
14+
indent_size = 4
15+
16+
[*.{yml,yaml}]
17+
indent_style = space
18+
indent_size = 2
19+
20+
[*.{md,markdown}]
21+
indent_style = space
22+
indent_size = 2
23+
trim_trailing_whitespace = false
24+
25+
[*.json]
26+
indent_style = space
27+
indent_size = 2
28+
29+
[*.toml]
30+
indent_style = space
31+
indent_size = 2
32+
33+
[Justfile]
34+
indent_style = space
35+
indent_size = 4

.github/workflows/ci.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
pull-requests: read
12+
13+
env:
14+
GO_VERSION: "1.26.0"
15+
16+
jobs:
17+
lint:
18+
name: Lint
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: ${{ env.GO_VERSION }}
27+
cache: true
28+
29+
- name: Verify go.mod is tidy
30+
run: |
31+
go mod tidy
32+
git diff --exit-code go.mod go.sum
33+
34+
- name: Run golangci-lint
35+
uses: golangci/golangci-lint-action@v8
36+
with:
37+
version: latest
38+
args: --timeout 5m --config .golangci.yml
39+
40+
- name: Run go vet
41+
run: go vet ./...
42+
43+
test:
44+
name: Test
45+
runs-on: ${{ matrix.os }}
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
os: [ubuntu-latest, macos-latest]
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- name: Set up Go
54+
uses: actions/setup-go@v5
55+
with:
56+
go-version: ${{ env.GO_VERSION }}
57+
cache: true
58+
59+
- name: Download dependencies
60+
run: go mod download
61+
62+
- name: Verify dependencies
63+
run: go mod verify
64+
65+
- name: Run tests
66+
run: go test -v -race -coverprofile=coverage.out ./...
67+
68+
build:
69+
name: Build
70+
runs-on: ${{ matrix.os }}
71+
needs: [lint, test]
72+
strategy:
73+
matrix:
74+
os: [ubuntu-latest, macos-latest]
75+
steps:
76+
- uses: actions/checkout@v4
77+
78+
- name: Set up Go
79+
uses: actions/setup-go@v5
80+
with:
81+
go-version: ${{ env.GO_VERSION }}
82+
cache: true
83+
84+
- name: Build CLI
85+
run: |
86+
mkdir -p bin
87+
go build -v -ldflags="-s -w" -o bin/devkit .
88+
89+
- name: Test CLI runs
90+
run: ./bin/devkit --help
91+
92+
- name: Upload CLI artifact
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: devkit-${{ matrix.os }}
96+
path: bin/devkit
97+
retention-days: 7

.github/workflows/release.yml

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "v[0-9]*"
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
prepare-release-pr:
16+
name: Prepare release PR
17+
if: startsWith(github.ref, 'refs/tags/')
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Extract version from tag
21+
id: version
22+
run: |
23+
TAG="${GITHUB_REF#refs/tags/}"
24+
VERSION="${TAG#v}"
25+
echo "tag=$TAG" >> $GITHUB_OUTPUT
26+
echo "version=$VERSION" >> $GITHUB_OUTPUT
27+
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Update version.go
34+
run: |
35+
VERSION="${{ steps.version.outputs.version }}"
36+
sed -i "s/const Version = \".*\"/const Version = \"$VERSION\"/" version.go
37+
38+
- name: Generate changelog
39+
uses: orhun/git-cliff-action@v4
40+
with:
41+
config: cliff.toml
42+
args: --tag ${{ steps.version.outputs.tag }}
43+
env:
44+
OUTPUT: CHANGELOG.md
45+
46+
- name: Check for modifications
47+
id: changes
48+
run: |
49+
if git diff --quiet; then
50+
echo "changes=false" >> $GITHUB_OUTPUT
51+
else
52+
echo "changes=true" >> $GITHUB_OUTPUT
53+
fi
54+
55+
- name: Create release PR
56+
if: steps.changes.outputs.changes == 'true'
57+
uses: peter-evans/create-pull-request@v6
58+
with:
59+
token: ${{ secrets.GITHUB_TOKEN }}
60+
base: main
61+
commit-message: "chore(release): bump version to ${{ steps.version.outputs.version }}"
62+
branch: release/${{ steps.version.outputs.tag }}
63+
title: "chore(release): ${{ steps.version.outputs.tag }}"
64+
body: |
65+
## Release `${{ steps.version.outputs.tag }}`
66+
67+
Automated release preparation triggered by tag push.
68+
69+
### Changes
70+
- Update `version.go` to `${{ steps.version.outputs.version }}`
71+
- Refresh `CHANGELOG.md`
72+
73+
### What happens after merge?
74+
Merging this PR will automatically:
75+
1. Create a GitHub Release for `${{ steps.version.outputs.tag }}`
76+
2. Update the release tag to point to the merge commit
77+
add-paths: |
78+
version.go
79+
CHANGELOG.md
80+
labels: release
81+
82+
publish-release:
83+
name: Publish GitHub release
84+
if: github.ref == 'refs/heads/main'
85+
runs-on: ubuntu-latest
86+
steps:
87+
- name: Checkout
88+
uses: actions/checkout@v4
89+
with:
90+
fetch-depth: 0
91+
92+
- name: Detect release commit
93+
id: release
94+
run: |
95+
set -euo pipefail
96+
BEFORE="${{ github.event.before }}"
97+
AFTER="${{ github.sha }}"
98+
if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
99+
BEFORE="$(git rev-parse "${AFTER}^" 2>/dev/null || echo "")"
100+
fi
101+
102+
if [ -z "$BEFORE" ]; then
103+
echo "run=false" >> $GITHUB_OUTPUT
104+
exit 0
105+
fi
106+
107+
if git diff --quiet "$BEFORE" "$AFTER" -- version.go; then
108+
echo "run=false" >> $GITHUB_OUTPUT
109+
exit 0
110+
fi
111+
112+
VERSION=$(sed -n 's/^const Version = "\(.*\)"/\1/p' version.go)
113+
if [ -z "$VERSION" ]; then
114+
echo "Unable to determine version from version.go" >&2
115+
exit 1
116+
fi
117+
118+
echo "run=true" >> $GITHUB_OUTPUT
119+
echo "version=$VERSION" >> $GITHUB_OUTPUT
120+
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
121+
122+
- name: Configure git
123+
if: steps.release.outputs.run == 'true'
124+
run: |
125+
git config user.name "github-actions[bot]"
126+
git config user.email "github-actions[bot]@users.noreply.github.com"
127+
128+
- name: Update release tag
129+
if: steps.release.outputs.run == 'true'
130+
run: |
131+
TAG="${{ steps.release.outputs.tag }}"
132+
git fetch origin --tags
133+
git tag -a "$TAG" -f -m "Release $TAG"
134+
git push origin "$TAG" --force
135+
136+
- name: Get previous tag
137+
if: steps.release.outputs.run == 'true'
138+
id: prev_tag
139+
run: |
140+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
141+
echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT
142+
143+
- name: Generate changelog
144+
if: steps.release.outputs.run == 'true'
145+
id: changelog
146+
uses: orhun/git-cliff-action@v4
147+
with:
148+
config: cliff.toml
149+
args: >-
150+
${{ steps.prev_tag.outputs.tag && format('{0}..{1}', steps.prev_tag.outputs.tag, steps.release.outputs.tag) || steps.release.outputs.tag }}
151+
env:
152+
OUTPUT: /tmp/RELEASE_CHANGELOG.md
153+
154+
- name: Create GitHub Release
155+
if: steps.release.outputs.run == 'true'
156+
uses: softprops/action-gh-release@v2
157+
with:
158+
tag_name: ${{ steps.release.outputs.tag }}
159+
body: ${{ steps.changelog.outputs.content }}
160+
draft: false
161+
prerelease: ${{ contains(steps.release.outputs.tag, '-alpha') || contains(steps.release.outputs.tag, '-beta') || contains(steps.release.outputs.tag, '-rc') }}
162+
generate_release_notes: false
163+
env:
164+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
devkit
33
bin/
44

5+
# Coverage
6+
coverage*.out
7+
coverage*.html
8+
59
# IDE
610
.idea/
711
.vscode/

0 commit comments

Comments
 (0)