Repository navigation
Expand file tree
/
Copy pathjustfile
More file actions
187 lines (161 loc) · 6.32 KB
/
Copy pathjustfile
File metadata and controls
187 lines (161 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import 'tools.just'
_default:
@just --list --unsorted
[group('dev')]
fmt *args:
cargo fmt {{args}}
[group('dev')]
lint:
cargo clippy --release --locked -- -D warnings
[group('dev')]
test:
cargo test --locked
# Check dependency sources, bans, and licenses against deny.toml
[group('dev')]
deny: (_require "cargo-deny")
cargo deny --locked check sources bans licenses
# Check dependencies against the RustSec advisory database
[group('dev')]
audit: (_require "cargo-deny")
cargo deny --locked check advisories
# Run the unit tests of the Python scripts
[group('dev')]
test-scripts:
python3 -B -m unittest discover -s scripts -p '*_test.py'
# Run all checks (before commit, push, merge, release)
[group('dev')]
@checks: (fmt "--check") lint test-scripts deny test
[group('dev')]
run:
cargo run --locked --bin mujina-minerd
# Pass "baseline" for the full check with the hashrate band. Needs
# the board powered. Set MUJINA_POOL_URL/MUJINA_POOL_USER to mine to
# a pool, or leave them unset to mine to the daemon's dummy source.
#
# Quick mining check on an attached Bitaxe Gamma
[group('hw')]
test-bitaxe-gamma tier='smoke':
cargo test --locked --test bitaxe_gamma -- --ignored --nocapture --test-threads=1 {{tier}}
# Dependency edits use the nightly toolchain until cargo 1.100
# enforces the cooldown in .cargo/config.toml on stable.
CARGO_DEPS := "cargo +nightly"
# Update all dependencies to their newest allowed versions
[group('deps')]
update-deps:
{{CARGO_DEPS}} update
# The single-crate recipes that follow edit the crate's lock entry and let
# cargo re-resolve it. The direct way, `cargo update -p`, also rewrites
# unrelated entries to older versions (rust-lang/cargo#5529).
# Update one crate to its newest allowed version; nothing else moves
[group('deps')]
update-dep crate:
scripts/lock-edit drop {{crate}}
{{CARGO_DEPS}} update --workspace
# Move one crate to an exact version, even inside the cooldown
[group('deps')]
force-dep crate version:
scripts/lock-edit set {{crate}} {{version}}
CARGO_RESOLVER_INCOMPATIBLE_PUBLISH_AGE=allow {{CARGO_DEPS}} update --workspace
# Bring Cargo.lock in line with Cargo.toml after a manifest edit
[group('deps')]
resolve-deps:
{{CARGO_DEPS}} update --workspace
# The fetch resolves the lock, which fills cargo's index cache, where
# the check reads publish times. With the crates already fetched it
# does nothing and needs no network.
#
# Fail if Cargo.lock gained a crates.io version younger than the cooldown
[group('deps')]
check-dep-cooldown base='origin/main':
cargo fetch --locked
scripts/check-dep-cooldown {{base}}
[private]
_require tool:
@command -v {{tool}} >/dev/null || { \
echo "error: {{tool}} is not installed; run 'just setup-tools'" >&2; \
exit 1; }
BUILD_IMAGE := "mujina-build"
# These files decide the build toolchain image's content. tools.just
# qualifies because the image runs setup-tools from it.
IMAGE_INPUTS := "build.Containerfile tools.just"
# Tag with a content hash of the image inputs so we can detect
# staleness without rebuilding. This matters in CI where podman
# save/load doesn't preserve layer cache---podman build would
# rebuild from scratch even with a loaded image. The content-hash
# tag lets `podman image exists` skip the build entirely.
BUILD_TAG := shell('sha256sum ' + IMAGE_INPUTS + ' | sha256sum | cut -c1-12')
# Build the build toolchain image (skips if unchanged)
[group('container')]
build-image:
podman image exists {{BUILD_IMAGE}}:{{BUILD_TAG}} || \
podman build -t {{BUILD_IMAGE}}:{{BUILD_TAG}} -f build.Containerfile .
# Remove stale build toolchain images
[group('container')]
build-image-clean:
podman images --format '{{{{.Repository}}:{{{{.Tag}}' \
| grep '^{{BUILD_IMAGE}}:' \
| grep -v ':{{BUILD_TAG}}$' \
| xargs -r podman rmi
# The git config marks the mounted workspace as trusted, since git
# refuses a repository owned by another user.
#
# Run a just recipe inside the build toolchain image
[group('container')]
in-container *args: build-image
mkdir -p .cache/cargo-registry .cache/cargo-git
podman run --rm \
-v "$(pwd)":/workspace:Z \
-v "$(pwd)/.cache/cargo-registry":/usr/local/cargo/registry \
-v "$(pwd)/.cache/cargo-git":/usr/local/cargo/git \
-w /workspace \
-e GIT_CONFIG_COUNT=1 \
-e GIT_CONFIG_KEY_0=safe.directory \
-e GIT_CONFIG_VALUE_0=/workspace \
{{BUILD_IMAGE}}:{{BUILD_TAG}} \
just {{args}}
# Check every commit from base to HEAD individually inside the build
# toolchain container, or the working tree when there are no new
# commits. The default base prefers a remote named upstream over
# origin and uses that remote's default branch.
# The CI pipeline. This is what GitHub Actions runs.
[group('ci')]
ci base="auto":
#!/usr/bin/env bash
set -euo pipefail
base="{{base}}"
if [ "$base" = "auto" ]; then
remote=$(git remote | grep -qx upstream && echo upstream || echo origin)
base=$(git symbolic-ref -q --short "refs/remotes/$remote/HEAD" \
|| echo "$remote/main")
fi
commits=$(git rev-list --reverse "$base"..HEAD)
if [ -z "$commits" ]; then
exec just in-container checks
fi
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "error: working tree dirty; commit or stash first, or run" >&2
echo "'just in-container checks' to check only the working tree" >&2
exit 1
fi
orig=$(git rev-parse --abbrev-ref HEAD)
[ "$orig" = "HEAD" ] && orig=$(git rev-parse HEAD)
trap 'git checkout --quiet "$orig"' EXIT
for sha in $commits; do
echo "::group::$(git log --oneline --no-decorate -1 "$sha")"
git checkout --quiet "$sha"
just in-container checks
echo "::endgroup::"
done
[group('container')]
container-build tag=`git rev-parse --abbrev-ref HEAD`:
podman build -t mujina-minerd:{{tag}} -f Containerfile .
[group('container')]
container-push tag=`git rev-parse --abbrev-ref HEAD`:
podman tag mujina-minerd:{{tag}} ghcr.io/256foundation/mujina-minerd:{{tag}}
podman push ghcr.io/256foundation/mujina-minerd:{{tag}}
# Configure git to use the project's .githooks directory
[group('setup')]
setup-hooks:
git config core.hooksPath .githooks
@echo "Git hooks configured to use .githooks/"
@ls .githooks/ | sed 's/^/ - /'