From 92fa4f2e24d1beebf7e4ffa31dd967af94333ce7 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 05:33:36 +0000 Subject: [PATCH 1/6] feat(actions): reusable GitHub Actions for CI drift, lint, generate, and diff-logs Add composite actions (setup, drift, lint, generate, diff-logs, check) that install release binaries via install.sh, emit lint findings as workflow annotations, and document consumer usage. Include actions-selftest workflow on ubuntu and macos with an expected drift failure. Closes #61 Co-authored-by: IlanReshet --- .github/workflows/actions-selftest.yml | 97 ++++++++++++++ README.md | 13 ++ actions/check/action.yml | 64 +++++++++ actions/diff-logs/action.yml | 53 ++++++++ actions/drift/action.yml | 69 ++++++++++ actions/generate/action.yml | 83 ++++++++++++ actions/lib/diff-logs-summary.sh | 18 +++ actions/lib/drift-summary.sh | 25 ++++ actions/lib/lint-report.sh | 83 ++++++++++++ actions/lint/action.yml | 68 ++++++++++ actions/setup/action.yml | 109 ++++++++++++++++ docs/GITHUB_ACTIONS.md | 172 +++++++++++++++++++++++++ 12 files changed, 854 insertions(+) create mode 100644 .github/workflows/actions-selftest.yml create mode 100644 actions/check/action.yml create mode 100644 actions/diff-logs/action.yml create mode 100644 actions/drift/action.yml create mode 100644 actions/generate/action.yml create mode 100755 actions/lib/diff-logs-summary.sh create mode 100755 actions/lib/drift-summary.sh create mode 100755 actions/lib/lint-report.sh create mode 100644 actions/lint/action.yml create mode 100644 actions/setup/action.yml create mode 100644 docs/GITHUB_ACTIONS.md diff --git a/.github/workflows/actions-selftest.yml b/.github/workflows/actions-selftest.yml new file mode 100644 index 0000000..6be7c89 --- /dev/null +++ b/.github/workflows/actions-selftest.yml @@ -0,0 +1,97 @@ +name: Actions self-test + +on: + push: + branches: [main] + paths: + - "actions/**" + - ".github/workflows/actions-selftest.yml" + - "install.sh" + pull_request: + paths: + - "actions/**" + - ".github/workflows/actions-selftest.yml" + - "install.sh" + - "docs/GITHUB_ACTIONS.md" + - "README.md" + +permissions: + contents: read + +concurrency: + group: actions-selftest-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + release-setup-smoke: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@11bd719010b57f4849f8b6fb4f9b486b8e0e8f4 # v4.2.2 + - name: Install from release + uses: ./actions/setup + with: + version: v0.1.0-rc.2 + cache: "true" + - name: Print version + run: openshell-annotate --version + + integration: + name: integration (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-24.04, macos-15] + steps: + - uses: actions/checkout@11bd719010b57f4849f8b6fb4f9b486b8e0e8f4 # v4.2.2 + - name: Check (setup + drift + lint) + uses: ./actions/check + with: + version: source + root: examples/polyglot + policy: openshell/policy.yaml + providers: openshell/providers.json + failure-threshold: warning + - name: Generate + id: gen + uses: ./actions/generate + with: + root: examples/polyglot + policy-out: openshell/ci-policy.yaml + providers-out: openshell/ci-providers.json + - name: Assert generate outputs + run: test -f "${{ steps.gen.outputs.policy-path }}" + - name: diff-logs (expect findings) + uses: ./actions/diff-logs + continue-on-error: true + id: difflogs + with: + root: tests/fixtures/sample + logs: ${{ github.workspace }}/tests/fixtures/logs/shorthand.log + - name: diff-logs should report missing directives + run: test "${{ steps.difflogs.outcome }}" = failure + + drift-failure: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@11bd719010b57f4849f8b6fb4f9b486b8e0e8f4 # v4.2.2 + - uses: ./actions/setup + with: + version: source + cache: "false" + - name: Copy example and tamper policy + id: prep + run: | + dir="$RUNNER_TEMP/polyglot-drift" + cp -a examples/polyglot "$dir" + sed -i 's/enforcement: enforce/enforcement: audit/' "$dir/openshell/policy.yaml" + echo "dir=$dir" >>"$GITHUB_OUTPUT" + - name: Drift must fail + uses: ./actions/drift + continue-on-error: true + id: drift + with: + root: ${{ steps.prep.outputs.dir }} + policy: openshell/policy.yaml + - name: Assert drift failed + run: test "${{ steps.drift.outcome }}" = failure diff --git a/README.md b/README.md index 8d27f14..4cc1b3e 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,19 @@ un-annotated calls, and gates CI on drift. Status: early prototype (version 0.1.0). Targets OpenShell policy schema v1 (`openshell-policy-schema` @ v0.1.6). Licensed under Apache-2.0. +## GitHub Actions + +Downstream repositories can run drift, lint, generate, and diff-logs in CI with composite actions under +[`actions/`](actions/). Pin a release tag on every `uses:` line (same ref for all steps). See +[docs/GITHUB_ACTIONS.md](docs/GITHUB_ACTIONS.md) for inputs, outputs, and copy-paste workflows. + +```yaml +- uses: ilanh/openshell-annotate/actions/check@v0.1.0-rc.2 + with: + policy: openshell/policy.yaml + providers: openshell/providers.json +``` + ## Install Prebuilt binaries (Linux and macOS, x86_64 and arm64) and a container image are attached to each diff --git a/actions/check/action.yml b/actions/check/action.yml new file mode 100644 index 0000000..2e2ff9e --- /dev/null +++ b/actions/check/action.yml @@ -0,0 +1,64 @@ +name: openshell-annotate check +description: Install openshell-annotate, then run drift and lint (common CI gate). +branding: + icon: shield + color: blue + +inputs: + version: + description: Release tag for setup (`latest`, a tag, or `source` to build this repository). + required: false + default: v0.1.0-rc.2 + root: + description: Repository root for drift and lint. + required: false + default: . + policy: + description: Committed policy.yaml. + required: true + providers: + description: Optional committed providers JSON for drift. + required: false + default: "" + profiles-dir: + description: Provider profiles directory. + required: false + default: "" + failure-threshold: + description: Lint failure threshold (`error`, `warning`, or `never`). + required: false + default: error + strict-drift: + description: Pass `--strict` to drift. + required: false + default: "false" + +outputs: + version: + description: Installed openshell-annotate version. + value: ${{ steps.setup.outputs.version }} + +runs: + using: composite + steps: + - name: Setup + id: setup + uses: ./actions/setup + with: + version: ${{ inputs.version }} + + - name: Drift + uses: ./actions/drift + with: + root: ${{ inputs.root }} + policy: ${{ inputs.policy }} + providers: ${{ inputs.providers }} + profiles-dir: ${{ inputs.profiles-dir }} + strict: ${{ inputs.strict-drift }} + + - name: Lint + uses: ./actions/lint + with: + root: ${{ inputs.root }} + policy: ${{ inputs.policy }} + failure-threshold: ${{ inputs.failure-threshold }} diff --git a/actions/diff-logs/action.yml b/actions/diff-logs/action.yml new file mode 100644 index 0000000..bb2ac41 --- /dev/null +++ b/actions/diff-logs/action.yml @@ -0,0 +1,53 @@ +name: openshell-annotate diff-logs +description: Compare sandbox logs against directives and report gaps in the job summary. +branding: + icon: search + color: purple + +inputs: + root: + description: Repository root (`--root`). + required: false + default: . + logs: + description: Space-separated log file paths (shorthand or OCSF JSONL). + required: true + write: + description: Insert suggested directives (`--write`). + required: false + default: "false" + deny-stale: + description: Fail when logs show no traffic for a declared egress (`--deny-stale`). + required: false + default: "false" + +runs: + using: composite + steps: + - name: Run diff-logs + shell: bash + working-directory: ${{ inputs.root }} + run: | + set -euo pipefail + root_abs="$(pwd)" + args=(diff-logs --root "$root_abs" --no-icons) + if [ "${{ inputs.write }}" = "true" ]; then + args+=(--write) + fi + if [ "${{ inputs.deny-stale }}" = "true" ]; then + args+=(--deny-stale) + fi + # shellcheck disable=SC2206 + log_files=(${{ inputs.logs }}) + if [ "${#log_files[@]}" -eq 0 ]; then + echo "::error::inputs.logs is required" + exit 2 + fi + args+=("${log_files[@]}") + out="$RUNNER_TEMP/diff-logs.txt" + set +e + openshell-annotate "${args[@]}" | tee "$out" + code=$? + set -e + bash "${{ github.action_path }}/../lib/diff-logs-summary.sh" "$out" + exit "$code" diff --git a/actions/drift/action.yml b/actions/drift/action.yml new file mode 100644 index 0000000..2028d9b --- /dev/null +++ b/actions/drift/action.yml @@ -0,0 +1,69 @@ +name: openshell-annotate drift +description: Fail when the committed policy no longer matches @openshell directives in the tree. +branding: + icon: stop + color: red + +inputs: + root: + description: Repository root passed to openshell-annotate (`--root`). + required: false + default: . + policy: + description: Committed policy.yaml (`--policy`). + required: true + providers: + description: Optional committed providers JSON (`--providers`). + required: false + default: "" + profiles-dir: + description: Provider profiles directory (`--profiles-dir`), when not set in config. + required: false + default: "" + strict: + description: Treat unmanaged committed sections as drift (`--strict`). + required: false + default: "false" + paths: + description: Space-separated paths to scan (default entire root). + required: false + default: "" + +runs: + using: composite + steps: + - name: Run drift + id: run + shell: bash + working-directory: ${{ inputs.root }} + run: | + set -euo pipefail + root_abs="$(pwd)" + policy="${{ inputs.policy }}" + args=(drift --root "$root_abs" --policy "$policy" --json) + if [ -n "${{ inputs.providers }}" ]; then + args+=(--providers "${{ inputs.providers }}") + fi + if [ -n "${{ inputs.profiles-dir }}" ]; then + args+=(--profiles-dir "${{ inputs.profiles-dir }}") + fi + if [ "${{ inputs.strict }}" = "true" ]; then + args+=(--strict) + fi + # shellcheck disable=SC2206 + extra=(${{ inputs.paths }}) + if [ "${#extra[@]}" -gt 0 ]; then + args+=("${extra[@]}") + fi + report="$RUNNER_TEMP/drift.json" + set +e + openshell-annotate "${args[@]}" >"$report" 2> "$RUNNER_TEMP/drift.stderr" + code=$? + set -e + cat "$RUNNER_TEMP/drift.stderr" >&2 + bash "${{ github.action_path }}/../lib/drift-summary.sh" "$report" + if [ "$code" -ne 0 ]; then + echo "::error::Policy drift detected (exit $code). See the job summary and logs." + exit "$code" + fi + echo "no drift" diff --git a/actions/generate/action.yml b/actions/generate/action.yml new file mode 100644 index 0000000..94179ca --- /dev/null +++ b/actions/generate/action.yml @@ -0,0 +1,83 @@ +name: openshell-annotate generate +description: Regenerate policy.yaml and optional providers from @openshell directives. +branding: + icon: file-code + color: green + +inputs: + root: + description: Repository root (`--root`). + required: false + default: . + policy-out: + description: Output path for policy.yaml (`-o`). + required: true + providers-out: + description: Output path for providers JSON or shell script (`--providers-out`). + required: false + default: "" + profiles-dir: + description: Provider profiles directory (`--profiles-dir`). + required: false + default: "" + scaffold-profiles: + description: Directory for `--scaffold-profiles` (creates missing provider profile stubs). + required: false + default: "" + upload-artifact: + description: Upload policy and providers outputs as a workflow artifact. + required: false + default: "false" + artifact-name: + description: Artifact name when upload-artifact is true. + required: false + default: openshell-policy + +outputs: + policy-path: + description: Absolute path to the generated policy file. + value: ${{ steps.out.outputs.policy-path }} + providers-path: + description: Absolute path to the generated providers file, if any. + value: ${{ steps.out.outputs.providers-path }} + +runs: + using: composite + steps: + - name: Generate policy + id: out + shell: bash + working-directory: ${{ inputs.root }} + run: | + set -euo pipefail + root_abs="$(pwd)" + policy_rel="${{ inputs.policy-out }}" + policy_abs="$root_abs/$policy_rel" + mkdir -p "$(dirname "$policy_abs")" + args=(generate --root "$root_abs" -o "$policy_rel") + providers_rel="${{ inputs.providers-out }}" + if [ -n "$providers_rel" ]; then + mkdir -p "$(dirname "$root_abs/$providers_rel")" + args+=(--providers-out "$providers_rel") + fi + if [ -n "${{ inputs.profiles-dir }}" ]; then + args+=(--profiles-dir "${{ inputs.profiles-dir }}") + fi + if [ -n "${{ inputs.scaffold-profiles }}" ]; then + args+=(--scaffold-profiles "${{ inputs.scaffold-profiles }}") + fi + openshell-annotate "${args[@]}" + echo "policy-path=$policy_abs" >>"$GITHUB_OUTPUT" + if [ -n "$providers_rel" ]; then + echo "providers-path=$root_abs/$providers_rel" >>"$GITHUB_OUTPUT" + fi + + - name: Upload artifact + if: inputs.upload-artifact == 'true' + uses: actions/upload-artifact@ea165f8d6b58e6d428a90ab3e4a8f78e3e262899 # v4.6.2 + with: + name: ${{ inputs.artifact-name }} + path: | + ${{ steps.out.outputs.policy-path }} + ${{ steps.out.outputs.providers-path }} + if-no-files-found: ignore diff --git a/actions/lib/diff-logs-summary.sh b/actions/lib/diff-logs-summary.sh new file mode 100755 index 0000000..55fb52b --- /dev/null +++ b/actions/lib/diff-logs-summary.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# Append human-readable diff-logs output (from a log file) to the job summary. +set -euo pipefail + +LOG="${1:?path to captured diff-logs stdout}" +summary="${GITHUB_STEP_SUMMARY:-/dev/stdout}" + +{ + echo "## openshell-annotate diff-logs" + echo "" + if [ ! -s "$LOG" ]; then + echo "_No diff-logs output._" + else + echo '```text' + head -c 120000 "$LOG" + echo '```' + fi +} >>"$summary" diff --git a/actions/lib/drift-summary.sh b/actions/lib/drift-summary.sh new file mode 100755 index 0000000..51b9445 --- /dev/null +++ b/actions/lib/drift-summary.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Append a drift report JSON file to GITHUB_STEP_SUMMARY. +set -euo pipefail + +REPORT="${1:?drift json path}" +summary="${GITHUB_STEP_SUMMARY:-/dev/stdout}" + +{ + echo "## openshell-annotate drift" + echo "" + if [ ! -s "$REPORT" ]; then + echo "_No drift report (clean or command did not emit JSON)._" + exit 0 + fi + count=$(jq '.findings | length' "$REPORT") + if [ "$count" -eq 0 ]; then + echo "_No drift: committed policy matches directives._" + exit 0 + fi + echo "**${count}** finding(s). Regenerate with \`openshell-annotate generate\`." + echo "" + echo "| Change | Section | Item | Detail |" + echo "| --- | --- | --- | --- |" + jq -r '.findings[] | "| \(.change) | \(.section) | \(.item | gsub("\\|"; "/")) | \(.detail | gsub("\\|"; "/")) |"' "$REPORT" +} >>"$summary" diff --git a/actions/lib/lint-report.sh b/actions/lib/lint-report.sh new file mode 100755 index 0000000..8416256 --- /dev/null +++ b/actions/lib/lint-report.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +# Parse `openshell-annotate lint --format json` stdout into GitHub annotations and a job summary. +# Usage: lint-report.sh FINDINGS.json [failure-threshold] +# failure-threshold: error (default) | warning | never — only affects whether this script exits non-zero; +# the caller should pass --deny-warnings to the CLI when threshold is warning. +set -euo pipefail + +FINDINGS="${1:?findings json path}" +THRESHOLD="${2:-error}" + +if [ ! -s "$FINDINGS" ]; then + echo '[]' >"$FINDINGS" +fi + +emit_annotation() { + local sev="$1" file="$2" line="$3" msg="$4" + [ -z "$file" ] || [ "$file" = "." ] && file="" + local loc="" + if [ -n "$file" ] && [ "$line" -gt 0 ] 2>/dev/null; then + loc="file=${file},line=${line}" + elif [ -n "$file" ]; then + loc="file=${file}" + fi + case "$sev" in + error) echo "::error ${loc}::${msg}" ;; + warning) echo "::warning ${loc}::${msg}" ;; + info) echo "::notice ${loc}::${msg}" ;; + *) echo "::notice ${loc}::[${sev}] ${msg}" ;; + esac +} + +if ! command -v jq >/dev/null 2>&1; then + die() { echo "$*" >&2; exit 1; } + die "lint-report.sh requires jq" +fi + +count_err=0 count_warn=0 count_info=0 +while IFS= read -r row; do + sev=$(jq -r '.severity' <<<"$row") + file=$(jq -r '.file' <<<"$row") + line=$(jq -r '.line' <<<"$row") + cat=$(jq -r '.category' <<<"$row") + msg=$(jq -r '.message' <<<"$row") + full="[${cat}] ${msg}" + emit_annotation "$sev" "$file" "$line" "$full" + case "$sev" in + error) count_err=$((count_err + 1)) ;; + warning) count_warn=$((count_warn + 1)) ;; + info) count_info=$((count_info + 1)) ;; + esac +done < <(jq -c '.[]' "$FINDINGS") + +summary="${GITHUB_STEP_SUMMARY:-/dev/stdout}" +{ + echo "## openshell-annotate lint" + echo "" + echo "| Severity | Count |" + echo "| --- | ---: |" + echo "| error | ${count_err} |" + echo "| warning | ${count_warn} |" + echo "| info | ${count_info} |" + echo "" + if [ "$count_err" -gt 0 ] || [ "$count_warn" -gt 0 ] || [ "$count_info" -gt 0 ]; then + echo "
Findings" + echo "" + echo "| File | Line | Severity | Category | Message |" + echo "| --- | ---: | --- | --- | --- |" + jq -r '.[] | "| \(.file) | \(.line) | \(.severity) | \(.category) | \(.message | gsub("\\|"; "/")) |"' "$FINDINGS" + echo "" + echo "
" + else + echo "_No findings._" + fi +} >>"$summary" + +exit_code=0 +case "$THRESHOLD" in + error) [ "$count_err" -eq 0 ] || exit_code=1 ;; + warning) [ "$count_err" -eq 0 ] && [ "$count_warn" -eq 0 ] || exit_code=1 ;; + never) exit_code=0 ;; + *) echo "::warning::unknown failure-threshold '$THRESHOLD'; treating as error" >&2; [ "$count_err" -eq 0 ] || exit_code=1 ;; +esac +exit "$exit_code" diff --git a/actions/lint/action.yml b/actions/lint/action.yml new file mode 100644 index 0000000..5a51b09 --- /dev/null +++ b/actions/lint/action.yml @@ -0,0 +1,68 @@ +name: openshell-annotate lint +description: Lint directives and call sites; surface findings as workflow annotations and a job summary. +branding: + icon: check-circle + color: yellow + +inputs: + root: + description: Repository root (`--root`). + required: false + default: . + policy: + description: Policy file to sanity-check (`--policy`); leave empty to skip policy checks. + required: false + default: "" + paths: + description: Space-separated paths to lint (default entire root). + required: false + default: "" + failure-threshold: + description: When to fail the step — `error` (default), `warning` (also fail on warnings), or `never`. + required: false + default: error + +runs: + using: composite + steps: + - name: Run lint + shell: bash + working-directory: ${{ inputs.root }} + run: | + set -euo pipefail + root_abs="$(pwd)" + args=(lint --root "$root_abs" --format json) + if [ -n "${{ inputs.policy }}" ]; then + args+=(--policy "${{ inputs.policy }}") + fi + threshold="${{ inputs.failure-threshold }}" + if [ "$threshold" = "warning" ]; then + args+=(--deny-warnings) + fi + # shellcheck disable=SC2206 + extra=(${{ inputs.paths }}) + if [ "${#extra[@]}" -gt 0 ]; then + args+=("${extra[@]}") + fi + findings="$RUNNER_TEMP/lint.json" + stderr="$RUNNER_TEMP/lint.stderr" + set +e + openshell-annotate "${args[@]}" >"$findings" 2>"$stderr" + cli_code=$? + set -e + cat "$stderr" >&2 + bash "${{ github.action_path }}/../lib/lint-report.sh" "$findings" "$threshold" + report_code=$? + if [ "$threshold" = "never" ]; then + if [ "$cli_code" -ne 0 ]; then + echo "::notice::lint reported findings but failure-threshold=never (step succeeds)." + fi + exit 0 + fi + if [ "$report_code" -ne 0 ]; then + exit "$report_code" + fi + if [ "$cli_code" -eq 2 ]; then + echo "::error::openshell-annotate lint failed with a usage or I/O error (exit 2)." + exit 2 + fi diff --git a/actions/setup/action.yml b/actions/setup/action.yml new file mode 100644 index 0000000..13d45a5 --- /dev/null +++ b/actions/setup/action.yml @@ -0,0 +1,109 @@ +name: openshell-annotate setup +description: Install a pinned openshell-annotate release (or build from source) and add it to PATH with caching. +branding: + icon: package + color: blue + +inputs: + version: + description: > + Release tag to install (e.g. v0.1.0-rc.2), `latest`, or `source` to build from the checked-out + repository with cargo (Rust 1.94+ required; for this repo's CI only). + required: false + default: v0.1.0-rc.2 + install-dir: + description: Directory for the openshell-annotate binary (added to PATH). + required: false + default: "" + verify-attestation: + description: Run `gh attestation verify` after download (needs GitHub CLI + contents:read). + required: false + default: "false" + cache: + description: Cache the installed binary between runs. + required: false + default: "true" + +outputs: + version: + description: Installed openshell-annotate version string (from `openshell-annotate --version`). + value: ${{ steps.meta.outputs.version }} + install-dir: + description: Directory containing the `openshell-annotate` binary. + value: ${{ steps.meta.outputs.install-dir }} + +runs: + using: composite + steps: + - name: Resolve install directory + id: dir + shell: bash + run: | + if [ -n "${{ inputs.install-dir }}" ]; then + dir="${{ inputs.install-dir }}" + else + dir="${RUNNER_TOOL_CACHE}/openshell-annotate" + fi + mkdir -p "$dir" + echo "dir=$dir" >>"$GITHUB_OUTPUT" + + - name: Restore cache + if: inputs.cache == 'true' && inputs.version != 'source' + id: cache + uses: actions/cache@684422466c4ff5064819fbae0ca35530fd955c5 # v4.3.0 + with: + path: ${{ steps.dir.outputs.dir }}/openshell-annotate + key: openshell-annotate-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }} + + - name: Install from release + if: inputs.version != 'source' && steps.cache.outputs.cache-hit != 'true' + shell: bash + env: + INSTALL_DIR: ${{ steps.dir.outputs.dir }} + OPENSHELL_ANNOTATE_VERSION: ${{ inputs.version }} + VERIFY: ${{ inputs.verify-attestation }} + run: | + set -euo pipefail + install_sh="${{ github.action_path }}/../../install.sh" + if [ ! -f "$install_sh" ]; then + ref="${GITHUB_ACTION_REPOSITORY#*/}" + ref_repo="ilanh/openshell-annotate" + tag="${GITHUB_ACTION_REF:-main}" + curl -fsSL "https://raw.githubusercontent.com/${ref_repo}/${tag}/install.sh" -o "$install_sh" + fi + args=(--dir "$INSTALL_DIR") + if [ -n "${OPENSHELL_ANNOTATE_VERSION}" ]; then + args+=(--version "$OPENSHELL_ANNOTATE_VERSION") + fi + if [ "$VERIFY" = "true" ]; then + args+=(--verify) + fi + sh "$install_sh" "${args[@]}" + + - name: Build from source + if: inputs.version == 'source' + shell: bash + env: + INSTALL_DIR: ${{ steps.dir.outputs.dir }} + run: | + set -euo pipefail + if ! command -v cargo >/dev/null 2>&1; then + rustup toolchain install 1.94 --profile minimal + rustup default 1.94 + fi + cargo build --release --locked + install -m 0755 target/release/openshell-annotate "$INSTALL_DIR/openshell-annotate" + + - name: Add to PATH + shell: bash + run: echo "${{ steps.dir.outputs.dir }}" >>"$GITHUB_PATH" + + - name: Record version + id: meta + shell: bash + run: | + bin="${{ steps.dir.outputs.dir }}/openshell-annotate" + ver="$("$bin" --version 2>/dev/null || true)" + echo "version=$ver" >>"$GITHUB_OUTPUT" + echo "install-dir=${{ steps.dir.outputs.dir }}" >>"$GITHUB_OUTPUT" + echo "openshell-annotate $ver at $bin" diff --git a/docs/GITHUB_ACTIONS.md b/docs/GITHUB_ACTIONS.md new file mode 100644 index 0000000..f1cfa16 --- /dev/null +++ b/docs/GITHUB_ACTIONS.md @@ -0,0 +1,172 @@ +# GitHub Actions + +Reusable composite actions install a [release](https://github.com/ilanh/openshell-annotate/releases) of +`openshell-annotate` and run the usual CI gates (`drift`, `lint`, `generate`, `diff-logs`). They work on `ubuntu-*` +and `macos-*` runners (linux/darwin, x86_64 and arm64). + +## Versioning + +Pin the **same ref** for every action in a workflow, for example a release tag: + +```yaml +uses: ilanh/openshell-annotate/actions/check@v0.1.0-rc.2 +``` + +Tags track [releases](https://github.com/ilanh/openshell-annotate/releases). You may also pin a commit SHA for +maximum stability. The `setup` action’s `version` input is the **CLI** version (defaults to `v0.1.0-rc.2`; `latest` is +supported). That is independent of the `@ref` on `uses:` — keep the action ref on a tag/SHA you trust. + +Do not rely on `@main` in production workflows; it moves with every merge. + +## Quick start (drift + lint) + +```yaml +permissions: + contents: read + +jobs: + openshell: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@11bd719010b57f4849f8b6fb4f9b486b8e0e8f4 # v4.2.2 + - uses: ilanh/openshell-annotate/actions/check@v0.1.0-rc.2 + with: + root: . + policy: openshell/policy.yaml + providers: openshell/providers.json + failure-threshold: warning +``` + +## Actions + +| Path | Purpose | +| --- | --- | +| [`actions/setup`](../actions/setup/action.yml) | Install CLI (release or `source`) and add to `PATH` | +| [`actions/drift`](../actions/drift/action.yml) | Fail when committed policy ≠ directives | +| [`actions/lint`](../actions/lint/action.yml) | Annotations + job summary from `lint --format json` | +| [`actions/generate`](../actions/generate/action.yml) | Regenerate policy / providers; optional artifact | +| [`actions/diff-logs`](../actions/diff-logs/action.yml) | Compare sandbox logs to directives | +| [`actions/check`](../actions/check/action.yml) | `setup` + `drift` + `lint` | + +### `actions/setup` + +| Input | Default | Description | +| --- | --- | --- | +| `version` | `v0.1.0-rc.2` | Release tag, `latest`, or `source` (build with cargo; needs checkout + Rust 1.94) | +| `install-dir` | `$RUNNER_TOOL_CACHE/openshell-annotate` | Install location | +| `verify-attestation` | `false` | `gh attestation verify` (needs GitHub CLI) | +| `cache` | `true` | Cache the binary between runs | + +| Output | Description | +| --- | --- | +| `version` | `openshell-annotate --version` | +| `install-dir` | Directory on `PATH` | + +### `actions/drift` + +| Input | Required | Description | +| --- | --- | --- | +| `policy` | yes | Committed `policy.yaml` (relative to `root`) | +| `root` | no | Repository root (default `.`) | +| `providers` | no | Optional providers JSON | +| `profiles-dir` | no | `--profiles-dir` override | +| `strict` | no | `--strict` | +| `paths` | no | Space-separated scan paths | + +### `actions/lint` + +| Input | Default | Description | +| --- | --- | --- | +| `root` | `.` | Repository root | +| `policy` | _(empty)_ | Policy file for sanity checks | +| `paths` | _(empty)_ | Space-separated paths | +| `failure-threshold` | `error` | `error`, `warning` (`--deny-warnings`), or `never` | + +Findings use GitHub workflow commands (`::error` / `::warning` / `::notice` with `file` and `line`) and a Markdown job +summary table. + +### `actions/generate` + +| Input | Required | Description | +| --- | --- | --- | +| `policy-out` | yes | `-o` path (relative to `root`) | +| `root` | no | Repository root | +| `providers-out` | no | `--providers-out` | +| `profiles-dir` | no | `--profiles-dir` | +| `scaffold-profiles` | no | `--scaffold-profiles` | +| `upload-artifact` | `false` | Upload policy (+ providers) | +| `artifact-name` | `openshell-policy` | Artifact name | + +| Output | Description | +| --- | --- | +| `policy-path` | Absolute path to generated policy | +| `providers-path` | Absolute path to providers (if requested) | + +### `actions/diff-logs` + +| Input | Required | Description | +| --- | --- | --- | +| `logs` | yes | Space-separated log files | +| `root` | no | Repository root | +| `write` | no | `--write` | +| `deny-stale` | no | `--deny-stale` | + +### `actions/check` + +Combines `setup`, `drift`, and `lint`. Inputs: `version`, `root`, `policy`, `providers`, `profiles-dir`, +`failure-threshold`, `strict-drift`. Output: `version` (installed CLI). + +## CD: regenerate policy in CI + +```yaml + - uses: ilanh/openshell-annotate/actions/setup@v0.1.0-rc.2 + - uses: ilanh/openshell-annotate/actions/generate@v0.1.0-rc.2 + id: policy + with: + policy-out: openshell/policy.yaml + providers-out: openshell/providers.json + upload-artifact: true +``` + +## Example: Policy Playground (`openspell-python-tester`) + +```yaml +permissions: + contents: read + +jobs: + policy: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@11bd719010b57f4849f8b6fb4f9b486b8e0e8f4 # v4.2.2 + - uses: ilanh/openshell-annotate/actions/check@v0.1.0-rc.2 + with: + root: . + policy: openshell/policy.yaml + providers: openshell/providers.json + failure-threshold: warning +``` + +Split steps (same pins): + +```yaml + - uses: ilanh/openshell-annotate/actions/setup@v0.1.0-rc.2 + - uses: ilanh/openshell-annotate/actions/drift@v0.1.0-rc.2 + with: + policy: openshell/policy.yaml + providers: openshell/providers.json + - uses: ilanh/openshell-annotate/actions/lint@v0.1.0-rc.2 + with: + policy: openshell/policy.yaml + failure-threshold: warning +``` + +## Permissions + +These actions need `contents: read` only. No secrets. Optional attestation verify uses the GitHub CLI with the +default `GITHUB_TOKEN`. + +## Self-test + +The repository runs [`.github/workflows/actions-selftest.yml`](../.github/workflows/actions-selftest.yml) on changes +to `actions/` (Ubuntu and macOS, including an expected drift failure). From e18c429295c8d56c6601eccd7c7780aec78db13f Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 05:33:52 +0000 Subject: [PATCH 2/6] ci: run actions self-test on cursor branches Co-authored-by: IlanReshet --- .github/workflows/actions-selftest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions-selftest.yml b/.github/workflows/actions-selftest.yml index 6be7c89..bf6a5b2 100644 --- a/.github/workflows/actions-selftest.yml +++ b/.github/workflows/actions-selftest.yml @@ -2,7 +2,7 @@ name: Actions self-test on: push: - branches: [main] + branches: [main, "cursor/**"] paths: - "actions/**" - ".github/workflows/actions-selftest.yml" From 89f54c88022fe491a211c1b9a626f2cda3c8c0d7 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 05:34:21 +0000 Subject: [PATCH 3/6] ci: fix pinned third-party action SHAs Co-authored-by: IlanReshet --- .github/workflows/actions-selftest.yml | 6 +++--- actions/generate/action.yml | 2 +- docs/GITHUB_ACTIONS.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/actions-selftest.yml b/.github/workflows/actions-selftest.yml index bf6a5b2..3dc835a 100644 --- a/.github/workflows/actions-selftest.yml +++ b/.github/workflows/actions-selftest.yml @@ -26,7 +26,7 @@ jobs: release-setup-smoke: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@11bd719010b57f4849f8b6fb4f9b486b8e0e8f4 # v4.2.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4.2.2 - name: Install from release uses: ./actions/setup with: @@ -43,7 +43,7 @@ jobs: matrix: os: [ubuntu-24.04, macos-15] steps: - - uses: actions/checkout@11bd719010b57f4849f8b6fb4f9b486b8e0e8f4 # v4.2.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4.2.2 - name: Check (setup + drift + lint) uses: ./actions/check with: @@ -74,7 +74,7 @@ jobs: drift-failure: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@11bd719010b57f4849f8b6fb4f9b486b8e0e8f4 # v4.2.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4.2.2 - uses: ./actions/setup with: version: source diff --git a/actions/generate/action.yml b/actions/generate/action.yml index 94179ca..2bb0134 100644 --- a/actions/generate/action.yml +++ b/actions/generate/action.yml @@ -74,7 +74,7 @@ runs: - name: Upload artifact if: inputs.upload-artifact == 'true' - uses: actions/upload-artifact@ea165f8d6b58e6d428a90ab3e4a8f78e3e262899 # v4.6.2 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v4.6.2 with: name: ${{ inputs.artifact-name }} path: | diff --git a/docs/GITHUB_ACTIONS.md b/docs/GITHUB_ACTIONS.md index f1cfa16..154f451 100644 --- a/docs/GITHUB_ACTIONS.md +++ b/docs/GITHUB_ACTIONS.md @@ -28,7 +28,7 @@ jobs: openshell: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@11bd719010b57f4849f8b6fb4f9b486b8e0e8f4 # v4.2.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4.2.2 - uses: ilanh/openshell-annotate/actions/check@v0.1.0-rc.2 with: root: . @@ -138,7 +138,7 @@ jobs: policy: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@11bd719010b57f4849f8b6fb4f9b486b8e0e8f4 # v4.2.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v4.2.2 - uses: ilanh/openshell-annotate/actions/check@v0.1.0-rc.2 with: root: . From 8b8ce9563ba5904ddbd27ec9693c3e8afcd08cd8 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 05:35:04 +0000 Subject: [PATCH 4/6] ci: fix actions/cache pin Co-authored-by: IlanReshet --- actions/setup/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/setup/action.yml b/actions/setup/action.yml index 13d45a5..8ed0702 100644 --- a/actions/setup/action.yml +++ b/actions/setup/action.yml @@ -50,7 +50,7 @@ runs: - name: Restore cache if: inputs.cache == 'true' && inputs.version != 'source' id: cache - uses: actions/cache@684422466c4ff5064819fbae0ca35530fd955c5 # v4.3.0 + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.2.2 with: path: ${{ steps.dir.outputs.dir }}/openshell-annotate key: openshell-annotate-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }} From dc34f100df23844c7160b6b2971e1977d882e440 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 05:40:22 +0000 Subject: [PATCH 5/6] ci: retry release install on transient download errors Co-authored-by: IlanReshet --- actions/setup/action.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/actions/setup/action.yml b/actions/setup/action.yml index 8ed0702..5efcca0 100644 --- a/actions/setup/action.yml +++ b/actions/setup/action.yml @@ -78,7 +78,14 @@ runs: if [ "$VERIFY" = "true" ]; then args+=(--verify) fi - sh "$install_sh" "${args[@]}" + attempt=0 + max=5 + until sh "$install_sh" "${args[@]}"; do + attempt=$((attempt + 1)) + [ "$attempt" -ge "$max" ] && exit 1 + echo "install.sh failed (attempt $attempt/$max); retrying in ${attempt}0s..." >&2 + sleep $((attempt * 10)) + done - name: Build from source if: inputs.version == 'source' From 08e2b15d045a258d73cc8269bac0820c994d6fb7 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Nov 2026 05:46:37 +0000 Subject: [PATCH 6/6] fix(install): stronger curl retries for release assets Co-authored-by: IlanReshet --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 8b948fd..6c74f7d 100755 --- a/install.sh +++ b/install.sh @@ -35,7 +35,7 @@ done have() { command -v "$1" > /dev/null 2>&1; } if have curl; then - fetch() { curl -fsSL --proto '=https,http' --retry 3 -o "$2" "$1"; } + fetch() { curl -fsSL --proto '=https,http' --retry 8 --retry-delay 3 --retry-all-errors -o "$2" "$1"; } resolve() { curl -fsSLI -o /dev/null -w '%{url_effective}' "$1"; } elif have wget; then fetch() { wget -q -O "$2" "$1"; }