Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139name: forbidden-strings
on: pull_request: branches: ['main'] merge_group: branches: ['main'] push: branches: ['main']
concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true
permissions: contents: read attestations: read
jobs: scan: runs-on: ubuntu-latest steps: - name: Checkout (full history) uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd with: fetch-depth: 0
- name: Download prebuilt forbidden-strings binary # The cargo-publish.yml workflow uploads SLSA-attested binaries for # x86_64-unknown-linux-gnu (and six other targets) on every # Cargo.toml version bump merged to main. We try the Cargo.toml # version first so the scanner matches the source tree, then fall # back to the latest release to cover the window between a # version-bump PR merging and cargo-publish.yml finishing. env: GH_TOKEN: ${{ github.token }} REPO: ${{ github.repository }} run: | set -euo pipefail
cargo_toml='package/cli/forbidden-strings/Cargo.toml' version=$(awk -F'"' '/^version = / { print $2; exit }' "$cargo_toml") tag="forbidden-strings-v${version}" if ! gh release view "$tag" --repo "$REPO" >/dev/null 2>&1; then echo "::notice::Release $tag not yet published; falling back to latest forbidden-strings-v* release." tag=$(gh release list --repo "$REPO" --limit 50 --json tagName \ --jq '[.[].tagName | select(startswith("forbidden-strings-v"))][0] // ""') if [ -z "$tag" ]; then echo "::error::No forbidden-strings-v* release found in $REPO." >&2 exit 1 fi version="${tag#forbidden-strings-v}" echo "Using fallback release: $tag" fi
archive="forbidden-strings-${version}-x86_64-unknown-linux-gnu.tar.gz" gh release download "$tag" --repo "$REPO" --pattern "$archive"
# SLSA build-provenance: binds the archive's sha256 to the # cargo-publish.yml run that produced it. A swapped-out release # asset would fail this step. gh attestation verify "$archive" --repo "$REPO"
# Install to a path on PATH so downstream steps invoke the binary # as plain `forbidden-strings`. Lives under RUNNER_TEMP so it # doesn't pollute the working tree. bin_dir="$RUNNER_TEMP/forbidden-strings" mkdir -p "$bin_dir" tar -xzf "$archive" \ --strip-components=1 \ -C "$bin_dir" \ "forbidden-strings-${version}-x86_64-unknown-linux-gnu/forbidden-strings" chmod +x "$bin_dir/forbidden-strings" echo "$bin_dir" >> "$GITHUB_PATH" "$bin_dir/forbidden-strings" --version
- name: Materialize deny-list # De-root design (commit 58995afff): no root example file and no root # rules file exist anymore. Compose the runtime rules file from the # committed shared appendix (forbidden-strings.append.txt, non-sensitive # repo-wide rules) plus the per-repo secret when one is configured. The # embedded betterleaks-ported baseline is NOT a file here: the scan steps # activate it with --builtin-rules, which reads it from inside the # downloaded binary. This keeps the baseline credential scan running even when # no secret exists, while the sensitive repo-specific literals stay # out-of-band: the gitignored forbidden-strings.append.local.txt is # absent in CI, so its sensitive equivalent is the FORBIDDEN_STRINGS_LIST # secret. Compose under RUNNER_TEMP so the secret-bearing file never # enters the working tree, and use printenv (not shell interpolation) so # the secret bytes are never expanded into a logged command line. env: FORBIDDEN_STRINGS_LIST: ${{ secrets.FORBIDDEN_STRINGS_LIST }} run: | set -euo pipefail rules="$RUNNER_TEMP/forbidden-strings.rules.txt" cp forbidden-strings.append.txt "$rules" chmod 600 "$rules" if [ -n "$FORBIDDEN_STRINGS_LIST" ]; then printenv FORBIDDEN_STRINGS_LIST >> "$rules" else echo "::notice::FORBIDDEN_STRINGS_LIST secret not set; baseline + shared appendix scan." fi
- name: Scan changed files # Pushes use the event's before/after range because origin/main already # points at HEAD after checkout. Pull requests and merge groups retain # their merge-base comparison with main. Replaces both the old full-tree # push scan and the earlier `mise exec -- hk check` step. env: EVENT_NAME: ${{ github.event_name }} HEAD_SHA: ${{ github.sha }} PUSH_BASE_SHA: ${{ github.event.before }} run: | set -euo pipefail if [ "$EVENT_NAME" = 'push' ]; then # A rewritten main branch can leave the event's before commit outside # every fetched ref even with fetch-depth 0. Fetch that exact object # before comparing trees instead of falling back to a full-tree scan. if ! git cat-file -e "$PUSH_BASE_SHA^{commit}"; then git fetch --no-tags --depth=1 origin "$PUSH_BASE_SHA" fi mapfile -d '' -t changed < <( git diff --name-only --diff-filter=ACMRT -z "$PUSH_BASE_SHA" "$HEAD_SHA" ) comparison="$PUSH_BASE_SHA..$HEAD_SHA" else mapfile -d '' -t changed < <( git diff --name-only --diff-filter=ACMRT -z origin/main...HEAD ) comparison='origin/main...HEAD' fi if [ ${#changed[@]} -eq 0 ]; then echo "No changed files in $comparison; nothing to scan." exit 0 fi printf 'Scanning %d changed file(s) from %s:\n' "${#changed[@]}" "$comparison" printf ' %s\n' "${changed[@]}" forbidden-strings --builtin-rules --rules "$RUNNER_TEMP/forbidden-strings.rules.txt" "${changed[@]}"