diff --git a/.github/workflows/app-ci.yml b/.github/workflows/app-ci.yml index f891b10..c93ec95 100644 --- a/.github/workflows/app-ci.yml +++ b/.github/workflows/app-ci.yml @@ -23,7 +23,7 @@ permissions: jobs: ci: - uses: privacykey/gh-workflows/.github/workflows/macos-app-ci.yml@v1 + uses: privacykey/gh-workflows/.github/workflows/macos-app-ci.yml@57d245db16e566c11d6ef66a6bb0bcd010e6bb12 # Apple source provenance with: xcodeproj: privacycommand/privacycommand.xcodeproj scheme: privacycommand diff --git a/.github/workflows/build-identity.yml b/.github/workflows/build-identity.yml index bcbefaa..ec90dd5 100644 --- a/.github/workflows/build-identity.yml +++ b/.github/workflows/build-identity.yml @@ -10,6 +10,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: python3 scripts/test-buildinfo.py - run: python3 scripts/test-build-identity.py - run: ruby scripts/test-fastlane-identity.rb - run: python3 scripts/test-archive-command.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 81f14d1..0f7aac7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,7 @@ permissions: jobs: release: - uses: privacykey/gh-workflows/.github/workflows/macos-sparkle-release.yml@v1 + uses: privacykey/gh-workflows/.github/workflows/macos-sparkle-release.yml@57d245db16e566c11d6ef66a6bb0bcd010e6bb12 # Apple source provenance with: xcodeproj: privacycommand/privacycommand.xcodeproj scheme: privacycommand diff --git a/docs/BUILD-PROVENANCE.md b/docs/BUILD-PROVENANCE.md new file mode 100644 index 0000000..c701353 --- /dev/null +++ b/docs/BUILD-PROVENANCE.md @@ -0,0 +1,35 @@ +# privacycommand build commands and provenance + +Audited 2026-10-01 against `0fc43d4f` plus the provenance corrections in this branch. + +`just info` previews the source identity: UTC build stamp, commit, branch, dirty-file count, tag-at-HEAD and channel. It does not reserve the stamp for a later build. `just archive` captures a fresh stamp, creates an Archive and verifies Organizer/app/extension metadata; exporting or uploading is a separate command. Product → Archive does the capture automatically through the shared scheme. + +Dirty means tracked modifications or non-ignored untracked files. Ignored build products are excluded. A version tag (`vX.Y` or `vX.Y.Z`) at HEAD and dirty files are independent flags: both can be YES. A clean tagged source alone does not prove signing, export or App Store publication. A release-channel Archive may be untagged or dirty. + +GitHub app builds automatically use the `ci` channel; explicit local/testflight/release choices take precedence. Archive defaults to `release` and redacts SHA/branch/describe/diff from binaries, while retaining dirty/tagged/timestamp/channel fields. CI source diagnostics remain in logs. Shared pipelines also report the checkout SHA, branch/detached state, dirty/tag flags and trigger in the job summary. PR jobs may build GitHub's synthetic merge commit; HEAD is reported accurately rather than replaced with the source branch's SHA. + +Tag detection requires fetched tag refs. App build workflows and the updated shared pipelines fetch full history and tags. Shared pipeline consumers use an exact commit pin for these corrections; the moving v1 tag is unchanged. + +Identification is consistent; clean-tree release enforcement is not universal. Do not infer a universal clean/tagged publishing gate from the presence of metadata. + +SPM CI tests the package/CLI; shared App CI builds/tests the macOS Xcode app. just build/test cover the SPM targets, not the Xcode app. Shared Sparkle release uses the exact release tag and checks marketing version; local release-local has no clean-tree/tag gate. + +## Available commands + +```text +Available recipes: + default # List available commands + archive platform="macos" # Regenerate the project, Archive, and verify its app/extension build identity. + info # Show the UTC build preview, commit, dirty files, tag-at-HEAD and channel. + + [dev] + build # Build every SPM target (Core, auditctlKit, auditctl, guest agent, protocol) + test # Run the full SPM test suite (same as CI) + clean # Remove SPM build output + + [ship] + release version # Tag v and push it to trigger the release workflow (tag must match MARKETING_VERSION) + release-local # Build, sign, notarize and package the DMG locally (needs Developer ID + notary env) +``` + +`release`, `beta`, `upload`, `deploy`, Worker secret/deploy commands and `stack-probe` have external effects. The audit listed them without running them. `release-local` signs/notarizes locally; `archive-export` exports but does not upload. diff --git a/justfile b/justfile index fcc633b..d3b5ac3 100644 --- a/justfile +++ b/justfile @@ -31,3 +31,7 @@ clean: # Regenerate the project, Archive, and verify its app/extension build identity. archive platform="macos": python3 scripts/archive-app.py --platform {{quote(platform)}} + +# Show the UTC build preview, commit, dirty files, tag-at-HEAD and channel. +info: + @scripts/banner.sh "privacycommand" diff --git a/scripts/banner.sh b/scripts/banner.sh index ac3fbb0..49e6a6b 100755 --- a/scripts/banner.sh +++ b/scripts/banner.sh @@ -34,8 +34,11 @@ if [ -t 1 ]; then bold=$'\033[1m'; dim=$'\033[2m'; amber=$'\033[33m'; off=$'\033 else bold=""; dim=""; amber=""; off=""; fi printf '%sā–ø %s %s (%s)%s\n' "$bold" "$name" "$version" "$BUILD_NUMBER" "$off" +printf ' channel %s version tag at HEAD %s\n' "$BUILD_CHANNEL" "$BUILD_TAGGED" if [ -n "$BUILD_SHA" ]; then printf ' commit %s branch %s\n' "$BUILD_SHA" "$BUILD_BRANCH" +elif [ "$BUILD_CHANNEL" = release ] || [ "${BUILD_PROVENANCE:-}" = minimal ]; then + printf ' commit %s(redacted)%s\n' "$dim" "$off" else printf ' commit %s(none recorded — no repository)%s\n' "$dim" "$off" fi diff --git a/scripts/buildinfo.sh b/scripts/buildinfo.sh index 58a852c..609e6e3 100755 --- a/scripts/buildinfo.sh +++ b/scripts/buildinfo.sh @@ -9,7 +9,15 @@ # binary carries nothing about a private repo. set -euo pipefail -channel="${BUILD_CHANNEL:-local}" +# Xcode's shared xcconfig uses `xcode` as an automatic-channel sentinel. +# Explicit local/testflight/release choices still win over the CI environment. +channel="${BUILD_CHANNEL:-xcode}" +if [ "$channel" = xcode ]; then + case "${GITHUB_ACTIONS:-false}:${CI:-false}" in + true:*|*:true|*:1|*:yes) channel=ci ;; + *) channel=local ;; + esac +fi provenance="${BUILD_PROVENANCE:-$([ "$channel" = release ] && echo minimal || echo full)}" # Absent or unreadable repository (source export, artefact-only CI job) must @@ -22,7 +30,9 @@ if git rev-parse --git-dir >/dev/null 2>&1 && git rev-parse HEAD >/dev/null 2>&1 branch=$(git rev-parse --abbrev-ref HEAD) n=$(git status --porcelain | wc -l | tr -d ' ') describe=$(git describe --tags --always --dirty 2>/dev/null || echo "") - if git describe --tags --exact-match --match 'v[0-9]*' HEAD >/dev/null 2>&1; then tagged=YES; fi + # A snapshot such as v1-preview is not a marketing-version release tag. + # Keep tag-at-HEAD independent of dirty state and the chosen build channel. + if git tag --points-at HEAD | LC_ALL=C grep -Eq '^v[0-9]+(\.[0-9]+){1,2}$'; then tagged=YES; fi # Hash tracked changes AND untracked content — `git diff HEAD` alone ignores # untracked files, so a tree dirty only with new files would otherwise get # the constant SHA-256 of empty input (e3b0c442) on every build. @@ -34,6 +44,13 @@ if git rev-parse --git-dir >/dev/null 2>&1 && git rev-parse HEAD >/dev/null 2>&1 fi fi +# CI logs identify the actual checkout even when release binaries redact it. +# No second clock capture or build number is generated for this diagnostic. +if [ "${GITHUB_ACTIONS:-false}" = true ]; then + printf 'Source provenance: commit=%s branch=%s dirty=%s files=%s version-tag-at-HEAD=%s channel=%s\n' \ + "${sha:-unknown}" "${branch:-unknown}" "$([ "$n" -gt 0 ] && echo YES || echo NO)" "$n" "$tagged" "$channel" >&2 +fi + # `release` builds ship no repository detail. Keys stay present but empty so # the plist shape is identical across channels; BuildInfo.swift treats an empty # value as absent. diff --git a/scripts/prepare-build-info.py b/scripts/prepare-build-info.py index fc55b44..cfdf8c7 100644 --- a/scripts/prepare-build-info.py +++ b/scripts/prepare-build-info.py @@ -25,7 +25,11 @@ def channel(): requested = os.environ.get("BUILD_CHANNEL", "") if requested and requested != "xcode": return requested - return "release" if os.environ.get("ACTION") == "install" else "local" + if os.environ.get("ACTION") == "install": + return "release" + if os.environ.get("GITHUB_ACTIONS") == "true" or os.environ.get("CI", "").lower() in ("true", "1", "yes"): + return "ci" + return "local" def main(): @@ -37,6 +41,7 @@ def main(): env = dict(os.environ, BUILD_CHANNEL=channel()) result = subprocess.run(["bash", str(Path(__file__).with_name("buildinfo.sh"))], cwd=root, env=env, check=True, capture_output=True, text=True) + sys.stderr.write(result.stderr) values = dict(line.split("=", 1) for line in result.stdout.splitlines()) session.parent.mkdir(parents=True, exist_ok=True) session.write_bytes(plistlib.dumps(values)) @@ -97,6 +102,9 @@ def main(): output.parent.mkdir(parents=True, exist_ok=True) output.write_bytes(plistlib.dumps(info)) print(f"{os.environ.get('PRODUCT_NAME', 'App')} {version} ({build})") + print(f"Build provenance: channel={values['BUILD_CHANNEL']} dirty={values['BUILD_DIRTY']} " + f"files={values['BUILD_DIRTY_FILES']} version-tag-at-HEAD={values['BUILD_TAGGED']} " + f"timestamp={values['BUILD_TIMESTAMP']}") if __name__ == "__main__": diff --git a/scripts/test-build-identity.py b/scripts/test-build-identity.py index b6fe6c9..4ac8491 100644 --- a/scripts/test-build-identity.py +++ b/scripts/test-build-identity.py @@ -37,6 +37,14 @@ assert actual["BuildTimestamp"] == values["BUILD_TIMESTAMP"] assert actual["BuildChannel"] == "release" and actual["BuildSHA"] == "" assert actual["CFBundleExecutable"] == "Fixture" and "UILaunchScreen" in actual + # CI is automatic for ordinary Xcode builds; Archive and explicit choices win. + for action, requested, expected in [("build", "xcode", "ci"), ("install", "xcode", "release"), + ("build", "local", "local"), ("install", "testflight", "testflight")]: + probe = dict(env, ACTION=action, BUILD_CHANNEL=requested, CI="true") + subprocess.run(["python3", str(script), "session"], env=probe, check=True) + captured = plistlib.loads((root / "project/BuildIdentity.plist").read_bytes()) + assert captured["BUILD_CHANNEL"] == expected, (action, requested, captured) + subprocess.run(["python3", str(script), "session"], env=env, check=True) # A complete wrapper stamp wins even when a second platform captures later. env.update(BUILD_NUMBER="2026.0930.0000", CURRENT_PROJECT_VERSION="2026.0930.0000", BUILD_TIMESTAMP="2026-09-30T00:00:00Z", BUILD_CHANNEL="testflight", diff --git a/scripts/test-buildinfo.py b/scripts/test-buildinfo.py new file mode 100644 index 0000000..2128e58 --- /dev/null +++ b/scripts/test-buildinfo.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +"""Run the real reference scripts against isolated repositories and a fixed UTC clock.""" +import os +from pathlib import Path +import shutil +import subprocess +import tempfile + +kit = Path(__file__).resolve().parents[1] + + +def run(args, cwd, env): + return subprocess.check_output(args, cwd=cwd, env=env, text=True) + + +with tempfile.TemporaryDirectory() as temporary: + base = Path(temporary) + repo = base / "app" + repo.mkdir() + shutil.copytree(kit / "scripts", repo / "Scripts") + (repo / "Config").mkdir() + (repo / "Config/Shared.xcconfig").write_text("MARKETING_VERSION = 0.1.0\n") + # Git provenance includes only this fixture, never a caller's worktree/index. + env = {key: value for key, value in os.environ.items() if not key.startswith("GIT_")} + env.update(GIT_CONFIG_NOSYSTEM="1", GIT_CONFIG_GLOBAL=os.devnull) + clock = base / "clock" + clock.mkdir() + date = clock / "date" + date.write_text("#!/bin/sh\n" + "[ \"$1\" = '-u' ] || exit 1\n" + "[ \"$2\" = '+%Y.%m%d.%H%M|%Y-%m-%dT%H:%M:%SZ' ] || exit 1\n" + "echo tick >> \"$CLOCK_CALLS\"\n" + "printf '%s\\n' '2026.1231.2359|2026-12-31T23:59:59Z'\n") + date.chmod(0o755) + env.update(PATH=str(clock) + os.pathsep + env["PATH"], CLOCK_CALLS=str(base / "ticks"), + TZ="Australia/Melbourne", BUILD_CHANNEL="local", BUILD_PROVENANCE="full") + + def stamp(cwd=repo, **overrides): + output = run(["bash", str(repo / "Scripts/buildinfo.sh")], cwd, dict(env, **overrides)) + return dict(line.split("=", 1) for line in output.splitlines()) + + run(["git", "init", "-q"], repo, env) + run(["git", "config", "user.name", "Versioning test"], repo, env) + run(["git", "config", "user.email", "versioning@example.invalid"], repo, env) + run(["git", "add", "."], repo, env) + run(["git", "-c", "commit.gpgsign=false", "commit", "-qm", "Fixture"], repo, env) + + clean = stamp() + assert clean["BUILD_NUMBER"] == "2026.1231.2359" + assert clean["BUILD_TIMESTAMP"] == "2026-12-31T23:59:59Z" + assert (base / "ticks").read_text().splitlines() == ["tick"], "Capture date once" + assert clean["BUILD_DIRTY"] == "NO" and clean["BUILD_DIRTY_FILES"] == "0" + assert len(clean["BUILD_SHA"]) == 8 and clean["BUILD_TAGGED"] == "NO" + + run(["git", "-c", "tag.gpgsign=false", "tag", "-a", "snapshot", "-m", "Snapshot"], repo, env) + assert stamp()["BUILD_TAGGED"] == "NO", "Only a version tag marks a release" + run(["git", "-c", "tag.gpgsign=false", "tag", "v1-preview"], repo, env) + assert stamp()["BUILD_TAGGED"] == "NO", "A v-prefixed snapshot is not a release tag" + run(["git", "-c", "tag.gpgsign=false", "tag", "-a", "v0.1.0", "-m", "Release"], repo, env) + assert stamp()["BUILD_TAGGED"] == "YES" + shallow = base / "shallow" + run(["git", "clone", "-q", "--depth=1", "--no-tags", repo.as_uri(), str(shallow)], base, env) + assert stamp(shallow)["BUILD_TAGGED"] == "NO", "Missing tag refs cannot be inferred from CI ref names" + run(["git", "fetch", "-q", "--tags"], shallow, env) + assert stamp(shallow)["BUILD_TAGGED"] == "YES" + run(["git", "checkout", "-q", "--detach"], shallow, env) + detached = stamp(shallow) + assert detached["BUILD_BRANCH"] == "HEAD" and detached["BUILD_TAGGED"] == "YES" + assert stamp(BUILD_CHANNEL="", CI="true")["BUILD_CHANNEL"] == "ci" + assert stamp(BUILD_CHANNEL="xcode", GITHUB_ACTIONS="true")["BUILD_CHANNEL"] == "ci" + assert stamp(BUILD_CHANNEL="local", CI="true")["BUILD_CHANNEL"] == "local" + assert stamp(BUILD_CHANNEL="release", GITHUB_ACTIONS="true")["BUILD_CHANNEL"] == "release" + + untracked = repo / "new note.txt" + untracked.write_text("first draft") + dirty = stamp() + assert dirty["BUILD_DIRTY"] == "YES" and dirty["BUILD_DIRTY_FILES"] == "1" + assert dirty["BUILD_TAGGED"] == "YES", "Dirty files do not erase a tag at the base commit" + assert dirty["BUILD_DIFF_ID"] and dirty["BUILD_DIFF_ID"] != "e3b0c442" + untracked.write_text("second draft") + assert stamp()["BUILD_DIFF_ID"] != dirty["BUILD_DIFF_ID"] + untracked.unlink() + (repo / "Config/Shared.xcconfig").write_text("MARKETING_VERSION = 0.2.0\n") + assert stamp()["BUILD_DIRTY"] == "YES" + + minimal_env = {key: value for key, value in env.items() if key != "BUILD_PROVENANCE"} + minimal_env["BUILD_CHANNEL"] = "release" + output = run(["bash", str(repo / "Scripts/buildinfo.sh")], repo, minimal_env) + release = dict(line.split("=", 1) for line in output.splitlines()) + for key in ["BUILD_SHA", "BUILD_BRANCH", "BUILD_DESCRIBE", "BUILD_DIFF_ID"]: + assert release[key] == "", key + assert release["BUILD_CHANNEL"] == "release" + + exported = base / "source export" + exported.mkdir() + missing = stamp(exported) + assert missing["BUILD_SHA"] == "" and missing["BUILD_DIRTY"] == "NO" + assert missing["BUILD_NUMBER"] == clean["BUILD_NUMBER"] + + marker = base / "evaluated" + injected = dict(clean, BUILD_BRANCH=f"$(touch {marker})") + info = "\n".join(f"{key}={value}" for key, value in injected.items()) + banner = run(["bash", str(repo / "Scripts/banner.sh"), "Fixture"], repo, dict(env, BUILD_INFO=info)) + assert "Fixture 0.2.0 (2026.1231.2359)" in banner + assert injected["BUILD_BRANCH"] in banner and not marker.exists(), "Provenance is data" + (repo / "Config/Shared.xcconfig").unlink() + banner = run(["bash", str(repo / "Scripts/banner.sh"), "Fixture"], repo, env) + assert "Fixture 0.0.0 (2026.1231.2359)" in banner + +print("Build tracking reference passed: UTC identity, clean/tagged/dirty trees, redaction, exports, safe banner")