Skip to content

Commit b8ebdc7

Browse files
committed
add examples
1 parent 84bf60b commit b8ebdc7

109 files changed

Lines changed: 1258 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Harmont examples
2+
3+
Minimal idiomatic starter projects, each wired up to a Harmont CI pipeline. Every example lives in its own subdirectory with a `.harmont/pipeline.py` you can read, copy, and run via `hm run <slug> --local`.
4+
5+
| Example | Toolchain | Pipeline |
6+
|---|---|---|
7+
| [react](./react) | npm + Vite + Vitest + ESLint | `hm.npm(...)` |
8+
| [nextjs](./nextjs) | npm + Jest + ESLint | `hm.npm(...)` |
9+
| [typescript](./typescript) | tsc + Vitest + ESLint | `hm.npm(...)` |
10+
| [rust](./rust) | cargo + clippy + rustfmt | `hm.rust(...)` |
11+
| [haskell](./haskell) | cabal + hlint + fourmolu | `hm.haskell(ghc="9.6.7")` |
12+
| [python-uv](./python-uv) | uv + pytest + ruff + mypy | `hm.python(...)` |
13+
| [go](./go) | go build/test/vet/fmt | `hm.go(...)` |
14+
| [java](./java) | Gradle + JUnit 5 | `hm.gradle(jdk="21")` |
15+
| [kotlin](./kotlin) | Gradle + kotlin.test | `hm.gradle(jdk="21", kotlin=True)` |
16+
| [c](./c) | CMake + CTest + clang-format | `hm.cmake(lang="c")` |
17+
| [cpp](./cpp) | CMake + CTest + clang-format | `hm.cmake(lang="cpp")` |
18+
| [csharp](./csharp) | dotnet + xunit + dotnet-format | `hm.dotnet(channel="8.0")` |
19+
| [ruby](./ruby) | Bundler + RSpec + Rubocop | `hm.ruby(...)` |
20+
| [perl](./perl) | cpanm + Test::More + Perl::Critic | `hm.perl(...)` |
21+
| [php-laravel](./php-laravel) | Composer + Laravel test + PHPStan | `hm.composer(laravel=True)` |
22+
| [ocaml](./ocaml) | opam + Dune + Alcotest | `hm.ocaml(compiler="5.1.1")` |
23+
| [zig](./zig) | zig build/test/fmt | `hm.zig(version="0.13.0")` |
24+
25+
## How to run an example locally
26+
27+
1. Install the Harmont CLI (`cli/` in this repo, or `cargo install harmont-cli` once published).
28+
2. `cd examples/<lang>` and run `hm run ci --local`. The CLI uses the project's `.harmont/pipeline.py` and executes each step in a local Docker container, sharing caches across runs.
29+
30+
Every pipeline uses `default_image="ubuntu:24.04"` and the apt-base / language-install steps are cached forever — only the action leaves (`test`, `lint`, etc.) re-run after a code change.
31+
32+
## What to copy
33+
34+
The shape every pipeline shares: a single `@hm.target()` builds the toolchain object once; the `@hm.pipeline("ci")` body returns a tuple of leaves (`build`, `test`, `lint`). Each leaf forks off the shared install step, so adding a fifth check costs you the action — never the install.

examples/c/.harmont/pipeline.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""C example pipeline."""
2+
from __future__ import annotations
3+
4+
import harmont as hm
5+
6+
7+
@hm.pipeline(
8+
"ci",
9+
env={"CI": "true"},
10+
default_image="ubuntu:24.04",
11+
triggers=[hm.push(branch="main")],
12+
)
13+
def ci() -> tuple[hm.Step, ...]:
14+
project = hm.cmake(path=".", lang="c")
15+
return (
16+
project.build(),
17+
project.test(),
18+
project.fmt(),
19+
)

examples/c/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
project(harmont_example_c C)
3+
set(CMAKE_C_STANDARD 11)
4+
5+
add_library(addlib src/main.c)
6+
7+
enable_testing()
8+
add_executable(test_main tests/test_main.c)
9+
target_link_libraries(test_main PRIVATE addlib)
10+
add_test(NAME test_main COMMAND test_main)

examples/c/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# C example
2+
3+
CMake + CTest hello-add C library. Pipeline runs cmake configure + build + ctest + clang-format check.
4+
5+
## Run the pipeline
6+
7+
```sh
8+
cd examples/c
9+
hm run ci --local
10+
```
11+
12+
See `.harmont/pipeline.py` for the definition; `examples/README.md` for the full index.

examples/c/src/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "main.h"
2+
3+
int add(int a, int b) {
4+
return a + b;
5+
}

examples/c/src/main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#pragma once
2+
int add(int a, int b);

examples/c/tests/test_main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "../src/main.h"
2+
3+
int main(void) {
4+
return add(2, 3) == 5 ? 0 : 1;
5+
}

examples/cpp/.harmont/pipeline.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""C++ example pipeline."""
2+
from __future__ import annotations
3+
4+
import harmont as hm
5+
6+
7+
@hm.pipeline(
8+
"ci",
9+
env={"CI": "true"},
10+
default_image="ubuntu:24.04",
11+
triggers=[hm.push(branch="main")],
12+
)
13+
def ci() -> tuple[hm.Step, ...]:
14+
project = hm.cmake(path=".", lang="cpp")
15+
return (
16+
project.build(),
17+
project.test(),
18+
project.fmt(),
19+
)

examples/cpp/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
project(harmont_example_cpp CXX)
3+
set(CMAKE_CXX_STANDARD 20)
4+
5+
add_library(addlib src/main.cpp)
6+
7+
enable_testing()
8+
add_executable(test_main tests/test_main.cpp)
9+
target_link_libraries(test_main PRIVATE addlib)
10+
add_test(NAME test_main COMMAND test_main)

examples/cpp/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# C++ example
2+
3+
CMake + CTest hello-add C++ library. Pipeline uses `hm.cmake(lang="cpp")` to label steps `:cpp:` and runs configure + build + ctest + clang-format check.
4+
5+
## Run the pipeline
6+
7+
```sh
8+
cd examples/cpp
9+
hm run ci --local
10+
```
11+
12+
See `.harmont/pipeline.py` for the definition; `examples/README.md` for the full index.

0 commit comments

Comments
 (0)