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
97 changes: 97 additions & 0 deletions .github/workflows/actions-selftest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Actions self-test

on:
push:
branches: [main, "cursor/**"]
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@3d3c42e5aac5ba805825da76410c181273ba90b1 # 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@3d3c42e5aac5ba805825da76410c181273ba90b1 # 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@3d3c42e5aac5ba805825da76410c181273ba90b1 # 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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions actions/check/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
53 changes: 53 additions & 0 deletions actions/diff-logs/action.yml
Original file line number Diff line number Diff line change
@@ -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"
69 changes: 69 additions & 0 deletions actions/drift/action.yml
Original file line number Diff line number Diff line change
@@ -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"
83 changes: 83 additions & 0 deletions actions/generate/action.yml
Original file line number Diff line number Diff line change
@@ -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@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v4.6.2
with:
name: ${{ inputs.artifact-name }}
path: |
${{ steps.out.outputs.policy-path }}
${{ steps.out.outputs.providers-path }}
if-no-files-found: ignore
Loading
Loading