Skip to content

Commit 5fff9b7

Browse files
committed
chore(ci): set up CI tests
1 parent 44b0920 commit 5fff9b7

File tree

5 files changed

+125
-28
lines changed

5 files changed

+125
-28
lines changed

.github/workflows/test.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
name: Test
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
permissions:
13+
pull-requests: write
14+
contents: read
15+
16+
jobs:
17+
tests:
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 5
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
lfs: true
27+
28+
- name: Fetch and checkout LFS objects
29+
run: |
30+
git lfs fetch --all
31+
git lfs checkout
32+
33+
- uses: jdx/mise-action@v3
34+
with:
35+
install: true
36+
37+
- name: Install deps
38+
run: mise run install
39+
40+
- name: Run post-commit
41+
run: mise run post-commit
42+
43+
- name: Format
44+
run: |
45+
mise run fmt
46+
git diff --exit-code || (echo "Code is not formatted, run 'mise run fmt' locally" && exit 1)
47+
48+
- name: Lint
49+
run: mise run lint
50+
51+
- name: Unit tests
52+
run: mise run test_unit
53+
54+
- name: End to end tests
55+
run: mise run test_e2e
56+
57+
- name: Create coverage artifact
58+
run: mise run coverage
59+
60+
- name: Generate code coverage report
61+
uses: irongut/[email protected]
62+
with:
63+
filename: coverage.xml
64+
badge: false
65+
fail_below_min: false
66+
format: markdown
67+
hide_branch_rate: false
68+
hide_complexity: true
69+
indicators: true
70+
output: both
71+
72+
- name: Add Coverage PR Comment
73+
uses: marocchino/sticky-pull-request-comment@v2
74+
if: github.event_name == 'pull_request'
75+
with:
76+
recreate: true
77+
path: code-coverage-results.md

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ repos:
2626
rev: v1.35.6
2727
hooks:
2828
- id: typos
29+
- repo: https://github.com/ComPWA/taplo-pre-commit
30+
rev: v0.9.3
31+
hooks:
32+
- id: taplo-format
33+
- id: taplo-lint

mise-tasks/test_e2e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
#MISE description="Run go e2e tests"
33
#MISE outputs="integration.txt"
4-
#MISE depends="bin"
4+
#MISE depends=["bin"]
55
set -euo pipefail
66

77
if [ "${GITHUB_ACTIONS:-}" = "true" ]; then

mise.toml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
21
[env]
32
_.path = ['{{config_root}}/node_modules/.bin']
43
_.python.venv = { path = "venv", create = true }
54

5+
[settings]
6+
python.compile = false
7+
experimental = true
8+
9+
[hooks]
10+
postinstall = "mise run install"
11+
612
[tools]
713
go = "1.25.3"
814
node = "24.6.0"
9-
python = "3.9.0"
15+
python = "3.9.14"
1016
golangci-lint = "2.4.0"
1117

1218
[tasks."init"]
@@ -39,65 +45,59 @@ depends = ["install:*"]
3945

4046
[tasks."commit-msg"]
4147
description = "Run commit-msg hooks"
42-
run = [
43-
"npx commitlint --edit $1",
44-
]
48+
run = ["npx commitlint --edit $1"]
4549

4650
[tasks."pre-commit"]
4751
description = "Run pre-commit tasks"
48-
run = "pre-commit"
52+
run = "python -m pre_commit"
53+
54+
[tasks."post-commit"]
55+
description = "Run post-commit tasks"
56+
run = "{{config_root}}/scripts/post-commit"
4957

5058
[tasks."lint"]
51-
run = [
52-
"golangci-lint run",
53-
]
59+
run = ["golangci-lint run"]
5460

5561
[tasks."fmt"]
56-
run = [
57-
"go mod tidy",
58-
"env GOFUMPT_SPLIT_LONG_LINES=on golangci-lint fmt ./...",
59-
]
62+
run = ["go mod tidy", "env GOFUMPT_SPLIT_LONG_LINES=on golangci-lint fmt ./..."]
6063

6164
[tasks."prepush"]
6265
depends = ["fmt", "lint", "test"]
6366

6467
[tasks."test:config"]
65-
run = [
66-
"golangci-lint config verify",
67-
]
68+
run = ["golangci-lint config verify"]
6869

6970
[tasks."regenerate:e2e"]
70-
run = [
71-
"go tool gotestsum -- -v ./test/... --count=1 -update",
72-
]
71+
run = ["go tool gotestsum -- -v ./test/... --count=1 -update"]
7372

7473
[tasks."test"]
7574
depends = ["test:*", "test_unit", "test_e2e"]
7675

7776
[tasks."coverage"]
7877
run = [
79-
"go tool gocovmerge integration.txt unit.txt > coverage.txt",
80-
"go tool cover -html=coverage.txt -o coverage.html",
81-
"go tool gocover-cobertura <coverage.txt >coverage.xml"
78+
"go tool gocovmerge integration.txt unit.txt > coverage.txt",
79+
"go tool cover -html=coverage.txt -o coverage.html",
80+
"go tool gocover-cobertura <coverage.txt >coverage.xml",
8281
]
83-
sources = [ "integration.txt", "unit.txt"]
82+
sources = ["integration.txt", "unit.txt"]
8483
outputs = ["coverage.html", "coverage.xml"]
8584

8685
[tasks.bin-package]
8786
description = "Build bubbletea example package"
8887
run = [
8988
"cd bin/${PACKAGE} && go build -o ./dist/${PACKAGE}",
9089
"mkdir -p ./dist",
91-
"cp bin/${PACKAGE}/dist/${PACKAGE} ./dist/${PACKAGE}"
90+
"cp bin/${PACKAGE}/dist/${PACKAGE} ./dist/${PACKAGE}",
9291
]
93-
outputs = [ "dist/${PACKAGE}" ]
94-
sources = [ "bin/${PACKAGE}/**" ]
92+
outputs = ["dist/${PACKAGE}"]
93+
sources = ["bin/${PACKAGE}/**"]
9594

9695
[tasks.bin]
9796
description = "Build all bubbletea example packages"
9897
run = [
98+
"mkdir -p ./dist/",
9999
"PACKAGE=editors mise run bin-package",
100-
"PACKAGE=list mise run bin-package"
100+
"PACKAGE=list mise run bin-package",
101101
]
102102
outputs = ["dist/editors", "dist/list"]
103103
sources = ["bin/**"]

scripts/post-commit

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
FROM_REF=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-HEAD~1}
5+
TO_REF=HEAD
6+
7+
if git rev-parse --verify "$FROM_REF" >/dev/null 2>&1; then
8+
echo "Running pre-commit between $FROM_REF and $TO_REF"
9+
else
10+
echo "Fetching origin/$FROM_REF..."
11+
git fetch origin "$FROM_REF"
12+
FROM_REF="origin/$FROM_REF"
13+
fi
14+
15+
pre-commit run --from-ref "$FROM_REF" --to-ref "$TO_REF"

0 commit comments

Comments
 (0)