Skip to content

Commit 6857e6d

Browse files
feat: harmont GitHub Action with Docker image caching (#2)
1 parent 0f49f4e commit 6857e6d

5 files changed

Lines changed: 79 additions & 361 deletions

File tree

.github/workflows/test-action.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,53 @@ jobs:
8383
run: |
8484
echo "Cache hit: ${{ steps.setup.outputs.cache-hit }}"
8585
hm --version
86+
87+
custom-binary:
88+
name: Custom hm-path (dogfood pattern)
89+
runs-on: ubuntu-latest
90+
timeout-minutes: 15
91+
permissions:
92+
contents: read
93+
packages: write
94+
steps:
95+
- uses: actions/checkout@v4
96+
97+
- name: Create mock hm binary
98+
run: |
99+
mkdir -p /tmp/mock-hm
100+
cat > /tmp/mock-hm/hm << 'SCRIPT'
101+
#!/bin/bash
102+
case "$1" in
103+
--version) echo "mock-0.0.1" ;;
104+
cache)
105+
case "$2" in
106+
save)
107+
mkdir -p "$3"
108+
echo '{"images":{}}' > "$3/manifest.json"
109+
echo "abc123"
110+
;;
111+
restore) echo "restored" ;;
112+
esac
113+
;;
114+
run) echo "ran pipeline: $2" ;;
115+
esac
116+
SCRIPT
117+
chmod +x /tmp/mock-hm/hm
118+
119+
- name: Cache restore (no manifest yet, cold start)
120+
uses: ./cache-restore
121+
with:
122+
working-directory: tests/fixtures
123+
124+
- name: Run with custom binary
125+
working-directory: tests/fixtures
126+
env:
127+
HM_NONINTERACTIVE: '1'
128+
run: /tmp/mock-hm/hm run hello
129+
130+
- name: Cache save with custom binary
131+
if: always()
132+
uses: ./cache-save
133+
with:
134+
working-directory: tests/fixtures
135+
hm-path: /tmp/mock-hm/hm

README.md

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
# actions-hm
22

3-
[![CI](https://img.shields.io/github/actions/workflow/status/harmont-dev/actions-hm/ci.yml?branch=main&logo=github&label=CI)](https://github.com/harmont-dev/actions-hm/actions)
4-
[![GitHub release](https://img.shields.io/github/v/release/harmont-dev/actions-hm?logo=github)](https://github.com/harmont-dev/actions-hm/releases)
5-
[![Marketplace](https://img.shields.io/badge/marketplace-harmont-purple?logo=github)](https://github.com/marketplace/actions/harmont)
3+
> [!WARNING]
4+
>
5+
> This repo is currently considered experimental.
66
7-
Run [harmont](https://harmont.dev) pipelines in GitHub Actions. One step. Automatic Docker image caching via your container registry.
7+
Run [harmont](https://harmont.dev) pipelines in GitHub Actions.
88

99
```yaml
10-
- uses: harmont-dev/actions-hm@v1
10+
- uses: harmont-dev/actions-hm@main
1111
with:
1212
pipeline: ci
1313
```
1414
15-
That's it. This installs `hm`, pulls cached Docker images from GHCR, runs your pipeline, and pushes updated images back — with automatic cleanup of stale cache entries.
16-
17-
## Why
18-
19-
You already define your CI with harmont. This action lets you run it on GitHub Actions without boilerplate:
20-
21-
- **Zero config caching** — Docker images cached in GHCR with native layer deduplication
22-
- **One step** — no separate setup, login, cache-restore, cache-save dance
23-
- **Fast repeat runs** — `hm` binary cached between runs, images pulled only when changed
24-
- **Auto cleanup** — stale registry images pruned automatically (configurable retention)
25-
- **Granular control** — use sub-actions individually when you need custom steps between them
26-
2715
## Usage
2816
2917
### Minimal (all-in-one)
@@ -55,15 +43,15 @@ jobs:
5543
runs-on: ubuntu-latest
5644
steps:
5745
- uses: actions/checkout@v4
58-
- uses: harmont-dev/actions-hm@v1
46+
- uses: harmont-dev/actions-hm@main
5947
with:
6048
pipeline: lint
6149

6250
test:
6351
runs-on: ubuntu-latest
6452
steps:
6553
- uses: actions/checkout@v4
66-
- uses: harmont-dev/actions-hm@v1
54+
- uses: harmont-dev/actions-hm@main
6755
with:
6856
pipeline: test
6957
parallelism: 4
@@ -95,14 +83,6 @@ jobs:
9583
if: always()
9684
```
9785
98-
### Pin to specific version
99-
100-
```yaml
101-
- uses: harmont-dev/actions-hm@v1
102-
with:
103-
version: 0.5.0
104-
```
105-
10686
## Inputs
10787
10888
| Input | Default | Description |
@@ -116,6 +96,7 @@ jobs:
11696
| `cache-registry-prefix` | *(auto)* | Registry path prefix. Default: `ghcr.io/<owner>/<repo>/harmont-cache` |
11797
| `cache-cleanup` | `true` | Delete stale images from registry after save |
11898
| `cache-cleanup-keep` | `2` | Number of old image versions to keep per step |
99+
| `hm-path` | | Path to a locally-built `hm` binary (skips install; used for dogfooding) |
119100
| `extra-args` | | Additional arguments passed to `hm run` |
120101
| `token` | `github.token` | GitHub token (needs `packages:write`, `packages:delete` for cleanup) |
121102

@@ -212,7 +193,7 @@ steps:
212193
```yaml
213194
steps:
214195
- uses: actions/checkout@v4
215-
- uses: harmont-dev/actions-hm@v1
196+
- uses: harmont-dev/actions-hm@main
216197
with:
217198
pipeline: ci
218199
```
@@ -234,7 +215,7 @@ macOS runners have Docker available via colima/lima. Windows runners are not cur
234215
Yes. Set `cache-registry` to your registry hostname and provide a token with push/pull access:
235216

236217
```yaml
237-
- uses: harmont-dev/actions-hm@v1
218+
- uses: harmont-dev/actions-hm@main
238219
with:
239220
pipeline: ci
240221
cache-registry: registry.example.com
@@ -244,7 +225,7 @@ Yes. Set `cache-registry` to your registry hostname and provide a token with pus
244225
### How do I disable caching entirely?
245226

246227
```yaml
247-
- uses: harmont-dev/actions-hm@v1
228+
- uses: harmont-dev/actions-hm@main
248229
with:
249230
pipeline: ci
250231
cache: 'false'

action.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ inputs:
5454
description: Additional arguments passed to 'hm run'
5555
required: false
5656
default: ''
57+
hm-path:
58+
description: >
59+
Path to the hm binary. Use when testing a locally-built binary
60+
instead of an installed release. Overrides setup step.
61+
required: false
62+
default: ''
5763
token:
5864
description: >
5965
GitHub token (needs packages:write for cache, packages:delete for cleanup)
@@ -70,6 +76,7 @@ runs:
7076
steps:
7177
# --- Setup ---
7278
- name: Setup Harmont
79+
if: inputs.hm-path == ''
7380
id: setup
7481
uses: ./setup
7582
with:
@@ -92,6 +99,7 @@ runs:
9299
working-directory: ${{ inputs.working-directory }}
93100
env:
94101
HM_NONINTERACTIVE: '1'
102+
INPUT_HM_PATH: ${{ inputs.hm-path || 'hm' }}
95103
INPUT_PIPELINE: ${{ inputs.pipeline }}
96104
INPUT_PARALLELISM: ${{ inputs.parallelism }}
97105
INPUT_EXTRA_ARGS: ${{ inputs.extra-args }}
@@ -107,7 +115,7 @@ runs:
107115
read -ra extra <<< "$INPUT_EXTRA_ARGS"
108116
args+=("${extra[@]}")
109117
fi
110-
hm run "${args[@]}"
118+
"$INPUT_HM_PATH" run "${args[@]}"
111119
112120
# --- Cache Save ---
113121
- name: Save Docker cache
@@ -119,4 +127,5 @@ runs:
119127
working-directory: ${{ inputs.working-directory }}
120128
cleanup: ${{ inputs.cache-cleanup }}
121129
cleanup-keep: ${{ inputs.cache-cleanup-keep }}
130+
hm-path: ${{ inputs.hm-path || 'hm' }}
122131
token: ${{ inputs.token }}

cache-save/action.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description: >
33
Push Docker images to a container registry after a harmont pipeline run.
44
Automatically cleans up stale images no longer in the current manifest.
55
Use with 'if: always()' to save cache even when the pipeline fails.
6-
76
inputs:
87
registry:
98
description: Container registry to push to
@@ -36,7 +35,12 @@ inputs:
3635
Token for registry auth (needs packages:write, packages:delete for cleanup).
3736
required: false
3837
default: ${{ github.token }}
39-
38+
hm-path:
39+
description: >
40+
Path to the hm binary. Defaults to 'hm' (assumes it's on PATH).
41+
Use './target/debug/hm' or similar when testing a locally-built binary.
42+
required: false
43+
default: hm
4044
runs:
4145
using: composite
4246
steps:
@@ -54,13 +58,14 @@ runs:
5458
env:
5559
INPUT_REGISTRY_PREFIX: ${{ inputs.registry-prefix }}
5660
INPUT_REGISTRY: ${{ inputs.registry }}
61+
INPUT_HM_PATH: ${{ inputs.hm-path }}
5762
GITHUB_REPOSITORY: ${{ github.repository }}
5863
working-directory: ${{ inputs.working-directory }}
5964
run: |
6065
prefix="${INPUT_REGISTRY_PREFIX:-${INPUT_REGISTRY}/${GITHUB_REPOSITORY}/harmont-cache}"
6166
6267
echo "::group::Exporting image manifest"
63-
hm cache save .harmont-cache/ > /dev/null
68+
"$INPUT_HM_PATH" cache save .harmont-cache/ > /dev/null
6469
echo "::endgroup::"
6570
6671
if [ ! -f .harmont-cache/manifest.json ]; then

0 commit comments

Comments
 (0)