Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,46 @@ jobs:
"$h" seal sample --key k.key -q
"$h" check sample --pubkey k.pub --require-signature

action:
name: the GitHub Action (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: A folder to protect
shell: bash
run: mkdir demo && echo hello > demo/a.txt
- uses: ./
with:
command: seal
path: demo
- uses: ./
with:
command: check
path: demo
- name: Tamper with the folder
shell: bash
run: echo evil >> demo/a.txt
- uses: ./
id: tampered
continue-on-error: true
with:
command: check
path: demo
- name: The check must have failed
shell: bash
env:
OUTCOME: ${{ steps.tampered.outcome }}
run: test "$OUTCOME" = failure

# Required status check: one name to protect in the branch rules.
ci-ok:
if: always()
needs: [test, lint, vulncheck, cross-build, dogfood]
needs: [test, lint, vulncheck, cross-build, dogfood, action]
runs-on: ubuntu-latest
steps:
- name: All jobs must have succeeded
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Format: [Keep a Changelog](https://keepachangelog.com/). Versions: [Semantic Ver

## [Unreleased]

## [0.2.0] - 2026-10-16

### Added
- `--fast` for `seal` and `check`: reuse hashes of files whose size and modification time are unchanged (with `--cache-file`). The report says how many hashes were reused.
- `assay completion bash|zsh|fish|powershell` and `assay man`; the `.deb` installs both.
- A GitHub Action (`uses: SandSoftwareSolutions/assay@v0.2.0`) that downloads a release, verifies its checksum and runs `seal` or `check`.

## [0.1.1] - 2026-10-16

### Fixed
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,39 @@ In scripts:
assay check /srv/site -q || { echo "site changed!" | mail -s alert ops@example.com; }
```

### Big folders: `--fast`

`assay check --fast` reuses the hash of every file whose size and modification time have not changed
since the previous run, so a large, mostly unchanged folder is checked in a fraction of the time.
The cache is kept in your user cache directory (override with `--cache-file`). The trade-off: a file
changed *without* touching its modification time is not noticed in fast mode. Use plain `assay check`
when you need certainty; files modified within the last two seconds are always rehashed. The report
says how many hashes were reused.

### Shell completion and manual page

```console
$ assay completion bash > /etc/bash_completion.d/assay # also zsh, fish, powershell
$ assay man | gzip > /usr/local/share/man/man1/assay.1.gz
```

The `.deb` package installs both for you.

### In GitHub Actions

```yaml
- uses: SandSoftwareSolutions/assay@v0.2.0
with:
command: check
path: dist
pubkey: release.pub
require-signature: "true"
```

The action downloads the release archive, verifies it against `SHA256SUMS` and runs `assay`.
Inputs: `command` (`seal` or `check`), `path`, `manifest`, `pubkey`, `require-signature`, `version`
(default `latest`; pin one for reproducible builds) and `args` (extra flags, space separated).

## Sign it, so the manifest cannot be swapped

A hash tells you the files differ from the manifest. It cannot tell you the manifest is genuine:
Expand Down
109 changes: 109 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: "assay"
description: "Seal a folder, or check that it still matches its seal, with assay (https://github.com/SandSoftwareSolutions/assay)"
author: "Sand Software Solutions"
branding:
icon: "shield"
color: "blue"

inputs:
command:
description: "seal or check"
default: "check"
path:
description: "The folder to seal or check"
default: "."
manifest:
description: "Manifest file (default: <path>/.assay.json)"
default: ""
pubkey:
description: "Public key file: verify the signature of the manifest (check only)"
default: ""
require-signature:
description: "Fail when the manifest is not signed and verified (check only): true or false"
default: "false"
version:
description: "assay version to use, such as 0.2.0, or latest"
default: "latest"
args:
description: "Extra flags, separated by spaces (no quoting), for example: --exclude node_modules --fast"
default: ""

outputs:
version:
description: "The assay version that was used"
value: ${{ steps.install.outputs.version }}

runs:
using: composite
steps:
- id: install
shell: bash
env:
ASSAY_VERSION: ${{ inputs.version }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
case "$RUNNER_OS" in
Linux) os=linux; ext=tar.gz ;;
macOS) os=darwin; ext=tar.gz ;;
Windows) os=windows; ext=zip ;;
*) echo "unsupported runner: $RUNNER_OS" >&2; exit 1 ;;
esac
case "$RUNNER_ARCH" in
X64) arch=amd64 ;;
ARM64) arch=arm64 ;;
*) echo "unsupported architecture: $RUNNER_ARCH" >&2; exit 1 ;;
esac
repo="SandSoftwareSolutions/assay"
version="$ASSAY_VERSION"
if [ "$version" = latest ]; then
version="$(curl -fsSL -H "Authorization: Bearer $GH_TOKEN" "https://api.github.com/repos/$repo/releases/latest" \
| sed -n 's/.*"tag_name": *"v\{0,1\}\([^"]*\)".*/\1/p' | head -n 1)"
fi
version="${version#v}"
if ! printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$'; then
echo "not a version number: '$version'" >&2; exit 1
fi
base="https://github.com/$repo/releases/download/v$version"
archive="assay_${version}_${os}_${arch}.${ext}"
dir="$RUNNER_TEMP/assay-$version"
mkdir -p "$dir"
curl -fsSL -o "$dir/$archive" "$base/$archive"
curl -fsSL -o "$dir/SHA256SUMS" "$base/SHA256SUMS"
expected="$(awk -v f="$archive" '$2 == f {print $1}' "$dir/SHA256SUMS" | tr -d '\r')"
[ -n "$expected" ] || { echo "no checksum listed for $archive" >&2; exit 1; }
if command -v sha256sum >/dev/null 2>&1; then actual="$(sha256sum "$dir/$archive" | awk '{print $1}' | tr -d '\r\\')"
else actual="$(shasum -a 256 "$dir/$archive" | awk '{print $1}')"; fi
if [ "$expected" != "$actual" ]; then echo "checksum mismatch for $archive (expected $expected, got $actual); refusing to use it" >&2; exit 1; fi
if [ "$ext" = zip ]; then unzip -q -o "$dir/$archive" -d "$dir"; else tar -xzf "$dir/$archive" -C "$dir"; fi
bin="$dir/assay_${version}_${os}_${arch}"
if command -v cygpath >/dev/null 2>&1; then bin="$(cygpath -w "$bin")"; fi
echo "$bin" >> "$GITHUB_PATH"
echo "version=$version" >> "$GITHUB_OUTPUT"

- id: run
shell: bash
env:
INPUT_COMMAND: ${{ inputs.command }}
INPUT_PATH: ${{ inputs.path }}
INPUT_MANIFEST: ${{ inputs.manifest }}
INPUT_PUBKEY: ${{ inputs.pubkey }}
INPUT_REQUIRE_SIGNATURE: ${{ inputs.require-signature }}
INPUT_ARGS: ${{ inputs.args }}
run: |
set -euo pipefail
case "$INPUT_COMMAND" in
seal|check) ;;
*) echo "command must be seal or check, not '$INPUT_COMMAND'" >&2; exit 2 ;;
esac
args=("$INPUT_COMMAND" "$INPUT_PATH")
if [ -n "$INPUT_MANIFEST" ]; then args+=(-m "$INPUT_MANIFEST"); fi
if [ "$INPUT_COMMAND" = check ]; then
if [ -n "$INPUT_PUBKEY" ]; then args+=(--pubkey "$INPUT_PUBKEY"); fi
if [ "$INPUT_REQUIRE_SIGNATURE" = true ]; then args+=(--require-signature); fi
fi
if [ -n "$INPUT_ARGS" ]; then
read -r -a extra <<< "$INPUT_ARGS"
args+=("${extra[@]}")
fi
assay "${args[@]}"
56 changes: 52 additions & 4 deletions internal/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package check
import (
"context"
"crypto/ed25519"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"io/fs"
Expand Down Expand Up @@ -32,6 +34,10 @@ type SealOptions struct {
Workers int
Now time.Time
Progress func(done, total int)
// Fast reuses hashes of files whose size and modification time did not change since the last run (see
// scan.Cache). CacheFile overrides where that memory is kept.
Fast bool
CacheFile string
}

// SealResult is what Seal produced.
Expand All @@ -41,6 +47,8 @@ type SealResult struct {
Scan *scan.Result
// Previous is the diff against the manifest that was there before, when there was a valid one.
Previous *compare.Diff
// Reused is the number of file hashes taken from the fast-mode cache.
Reused int
}

func manifestPath(dir, given string) string {
Expand Down Expand Up @@ -83,8 +91,14 @@ func Seal(ctx context.Context, o SealOptions) (*SealResult, error) {
patterns = append(patterns, o.Exclude...)
matcher := ignore.New(patterns...)

cachePath := ""
var cache *scan.Cache
if o.Fast {
cachePath = fastCachePath(o.Dir, o.Algorithm, o.CacheFile)
cache = scan.LoadCache(cachePath, o.Algorithm)
}
res, err := scan.Scan(ctx, scan.Options{Root: o.Dir, Algorithm: o.Algorithm, Ignore: matcher,
Skip: skipPaths(o.Dir, mpath), Workers: o.Workers, Progress: o.Progress})
Skip: skipPaths(o.Dir, mpath), Workers: o.Workers, Progress: o.Progress, Cache: cache})
if err != nil {
return nil, err
}
Expand All @@ -105,7 +119,10 @@ func Seal(ctx context.Context, o SealOptions) (*SealResult, error) {
Value: sign.Sign(o.Key, m.Algorithm, m.Root, manifest.IgnoreDigest(m.Ignore)),
}
}
out := &SealResult{Manifest: m, ManifestPath: mpath, Scan: res}
out := &SealResult{Manifest: m, ManifestPath: mpath, Scan: res, Reused: res.Reused}
if o.Fast {
_ = scan.Save(cachePath, o.Algorithm, res.CacheEntries, o.Now) // best effort: a cache only speeds things up
}
if prev, err := manifest.Read(mpath); err == nil {
d := compare.Compare(prev.Files, m.Files)
out.Previous = &d
Expand Down Expand Up @@ -150,6 +167,8 @@ type Options struct {
Workers int
Now time.Time
Progress func(done, total int)
Fast bool
CacheFile string
}

// Result is the outcome of a check.
Expand All @@ -164,6 +183,8 @@ type Result struct {
Signature SignatureStatus
KeyID string
CheckedAt time.Time
// Reused is the number of file hashes taken from the fast-mode cache.
Reused int
}

// OK reports whether the folder matches the manifest and nothing is wrong with the manifest.
Expand All @@ -187,15 +208,24 @@ func Check(ctx context.Context, o Options) (*Result, error) {
if err != nil {
return nil, err
}
cachePath := ""
var cache *scan.Cache
if o.Fast {
cachePath = fastCachePath(o.Dir, m.Algorithm, o.CacheFile)
cache = scan.LoadCache(cachePath, m.Algorithm)
}
res, err := scan.Scan(ctx, scan.Options{Root: o.Dir, Algorithm: m.Algorithm, Ignore: ignore.New(m.Ignore...),
Skip: skipPaths(o.Dir, mpath), Workers: o.Workers, Progress: o.Progress})
Skip: skipPaths(o.Dir, mpath), Workers: o.Workers, Progress: o.Progress, Cache: cache})
if err != nil {
return nil, err
}
if o.Fast {
_ = scan.Save(cachePath, m.Algorithm, res.CacheEntries, o.Now)
}
r := &Result{
ManifestPath: mpath, Manifest: m, Diff: compare.Compare(m.Files, res.Files),
Unreadable: res.Unreadable, Skipped: res.Skipped, RootDamaged: !m.RootMatches(),
Signature: SigNone, CheckedAt: o.Now,
Signature: SigNone, CheckedAt: o.Now, Reused: res.Reused,
}
// Unreadable files must not be reported as removed: they are there, we just cannot see them.
if len(res.Unreadable) > 0 {
Expand Down Expand Up @@ -235,3 +265,21 @@ func dropRemoved(d compare.Diff, unreadable map[string]bool) compare.Diff {
d.Removed = removed
return d
}

// fastCachePath is where the fast-mode memory of a folder lives: the given file, or a file in the user's cache
// folder named after the folder and the algorithm, so different folders never share one.
func fastCachePath(dir, algorithm, explicit string) string {
if explicit != "" {
return explicit
}
abs, err := filepath.Abs(dir)
if err != nil {
abs = dir
}
sum := sha256.Sum256([]byte(abs + "\x00" + algorithm))
base, err := os.UserCacheDir()
if err != nil {
base = os.TempDir()
}
return filepath.Join(base, "assay", hex.EncodeToString(sum[:8])+".json")
}
Loading
Loading