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
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
* @0xahzam @ChewingGlass @jt-lumen @ChesterSim @csadminlc @noah-velocity-admin @jtadminlc

/.github/workflows/publish-image.yml @0xahzam @ChewingGlass @jt-lumen @ChesterSim @csadminlc @noah-velocity-admin @jtadminlc

# The dependency gate inspects the pull request that is changing it, so its
# parser deliberately lives outside the repos it gates.
/dependency-gate/ @0xahzam @ChewingGlass @jt-lumen @ChesterSim @csadminlc @noah-velocity-admin
35 changes: 35 additions & 0 deletions .github/workflows/dependency-gate-selfgate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Dependency gate (self)

# This repository gates itself the way a consumer would, so the failure path is
# exercised for real rather than only in tests. tests/fixtures/Cargo.lock is the file
# under watch: adding a package to it must make this job fail until the deps-reviewed
# label is applied.
#
# pull_request_target runs this workflow from the base branch instead of from the pull
# request. Under pull_request it is the pull request's own copy that runs, so a pull
# request could empty the lockfiles input or make enforcement exit 0 in the same diff
# that adds a package. The usual pull_request_target hazard does not apply, because the
# pull request is never checked out: its lockfiles are read as bytes through the
# contents API at a pinned head SHA and parsed by the base branch's parser.
on:
pull_request_target:
types: [opened, synchronize, reopened, labeled, unlabeled]

permissions:
contents: read
issues: write # label removal goes through the issues API
pull-requests: write

jobs:
gate:
name: Dependency gate
runs-on: ubuntu-latest
steps:
# Checks out the base branch, which is what pull_request_target resolves to.
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
fetch-depth: 0
- uses: ./dependency-gate
with:
lockfiles: dependency-gate/tests/fixtures/Cargo.lock
require-pull-request-target: "true"
150 changes: 150 additions & 0 deletions .github/workflows/dependency-gate-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: Dependency gate tests

on:
push:
branches: [master]
paths:
- "dependency-gate/**"
- ".github/workflows/dependency-gate-test.yml"
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
paths:
- "dependency-gate/**"
- ".github/workflows/dependency-gate-test.yml"
# Only the dogfood-prt job below uses this. Under pull_request_target the workflow,
# and `uses: ./`, both come from the base branch, so this exercises the base branch's
# action rather than the pull request's. That is the point of the mode.
pull_request_target:
types: [opened, synchronize, reopened, labeled, unlabeled]
paths:
- "dependency-gate/**"
- ".github/workflows/dependency-gate-test.yml"

permissions:
contents: read

jobs:
parser:
name: Parser tests
# Must run the pull request's own code, so not under pull_request_target.
if: github.event_name != 'pull_request_target'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- run: python3 dependency-gate/tests/test_parser.py

action-yml:
name: action.yml is valid
if: github.event_name != 'pull_request_target'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Parse action.yml and check the declared contract
run: |
python3 - <<'PY'
import re
import yaml
d = yaml.safe_load(open("dependency-gate/action.yml"))
assert d["runs"]["using"] == "composite", d["runs"]["using"]
assert "lockfiles" in d["inputs"], "lockfiles input missing"
assert d["inputs"]["lockfiles"]["required"] is True
assert set(d["outputs"]) == {"count", "digest", "findings"}, set(d["outputs"])
for step in d["runs"]["steps"]:
assert step.get("shell") == "bash", step.get("name")
# Every Actions expression must arrive through env:, never interpolated into
# a run: body, where a crafted value would be pasted straight into bash.
leaked = [
(step["name"], m)
for step in d["runs"]["steps"]
for m in re.findall(r"\$\{\{[^}]*\}\}", step.get("run") or "")
]
assert not leaked, f"expressions interpolated into run bodies: {leaked}"
print(f'ok: {len(d["runs"]["steps"])} composite steps, no leaked expressions')
PY

shell:
name: Shellcheck the composite steps
if: github.event_name != 'pull_request_target'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Extract each run block and shellcheck it
run: |
set -euo pipefail
python3 - <<'PY'
import pathlib, re, yaml
d = yaml.safe_load(open("dependency-gate/action.yml"))
out = pathlib.Path("shell-blocks"); out.mkdir(exist_ok=True)
for i, step in enumerate(d["runs"]["steps"]):
script = step.get("run")
if not script:
continue
# Actions expressions are substituted before bash sees them; replace
# them with a placeholder so shellcheck parses the real structure.
script = re.sub(r"\$\{\{[^}]*\}\}", "PLACEHOLDER", script)
(out / f"step{i}.sh").write_text("#!/usr/bin/env bash\n" + script)
PY
sudo apt-get update -qq && sudo apt-get install -y -qq shellcheck
# SC2086 is noisy here: $LOCKFILES is intentionally word-split.
shellcheck --severity=warning --exclude=SC2086 shell-blocks/*.sh

dogfood-pr:
name: Gate this repository with itself (pull_request mode)
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
fetch-depth: 0
- id: gate
uses: ./dependency-gate
with:
# The stable fixtures never change, so this job stays green. The gate's
# failure path is exercised by .github/workflows/dependency-gate.yml, which
# watches tests/fixtures/Cargo.lock.
lockfiles: dependency-gate/tests/fixtures/stable/Cargo.lock dependency-gate/tests/fixtures/stable/uv.lock
comment: "false"
- name: The stable fixtures are unchanged, so the count must be zero
env:
COUNT: ${{ steps.gate.outputs.count }}
DIGEST: ${{ steps.gate.outputs.digest }}
run: |
set -euo pipefail
test "$COUNT" = "0" || { echo "expected count=0, got '$COUNT'"; exit 1; }
test -n "$DIGEST" || { echo "expected a digest to be reported"; exit 1; }
echo "ok: count=$COUNT digest=$DIGEST"

dogfood-prt:
name: Gate this repository with itself (pull_request_target mode)
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
# Checks out the base branch, which is what pull_request_target resolves to. The
# pull request's own files are never checked out; the gate reads its lockfiles
# through the contents API at a pinned head SHA.
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
fetch-depth: 0
- id: gate
uses: ./dependency-gate
with:
lockfiles: dependency-gate/tests/fixtures/stable/Cargo.lock dependency-gate/tests/fixtures/stable/uv.lock
comment: "false"
require-pull-request-target: "true"
- name: The stable fixtures are unchanged, so the count must be zero
env:
COUNT: ${{ steps.gate.outputs.count }}
DIGEST: ${{ steps.gate.outputs.digest }}
run: |
set -euo pipefail
test "$COUNT" = "0" || { echo "expected count=0, got '$COUNT'"; exit 1; }
test -n "$DIGEST" || { echo "expected a digest to be reported"; exit 1; }
echo "ok: count=$COUNT digest=$DIGEST"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
*.pyc
shell-blocks/
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,55 @@ jobs:

Secrets: `build_secrets`, newline-separated `id=value` docker build secrets.

## `dependency-gate/`

A composite action, not a reusable workflow — used as a step. It flags the
dependencies a pull request newly introduces, and existing ones it repoints at a
new source, then requires a `deps-reviewed` label before the PR can merge. The
sign-off is bound to the exact set of findings it was shown, so adding another
dependency afterwards re-opens the gate.

Version bumps within the same source stay quiet; only new packages and changed
origins are reported. Supports `bun.lock`, `yarn.lock`, `pnpm-lock.yaml`,
`Cargo.lock` and `uv.lock`.

The parser lives here rather than in the repo being gated, so a pull request
cannot weaken the check that is inspecting it. Callers run it under
`pull_request_target` and pass `require-pull-request-target: true`, which makes
the action fail loudly if that is ever downgraded.

```yaml
on:
pull_request_target:
types: [opened, synchronize, reopened, labeled, unlabeled]

permissions:
contents: read
pull-requests: write
issues: write

jobs:
new-dependency-gate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: velocity-exchange/shared-workflows/dependency-gate@<sha>
with:
lockfiles: yarn.lock apps/foo/Cargo.lock
require-pull-request-target: true
```

| input | required | default | notes |
| --- | --- | --- | --- |
| `lockfiles` | yes | — | Space-separated, repo-relative lockfile paths |
| `label` | no | `deps-reviewed` | Label recording human sign-off |
| `comment` | no | `true` | Post/update a sticky comment listing findings |
| `require-pull-request-target` | no | `false` | Fail if not run under `pull_request_target` |

Outputs: `count`, `digest`, `findings`.

## `secret-scan-reusable.yml`

Scans a pull request's own commits (`merge-base..head`) with TruffleHog.
Expand Down
Loading
Loading