-
Notifications
You must be signed in to change notification settings - Fork 0
fix(hygiene): enforce real source debt with controls #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
56ddfe4
8e3f3be
1912aa9
babaf0f
15666c7
7201be0
79e4d58
6aa9773
44daf9a
5f54f5a
48f0431
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: Code Hygiene Self-Test | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - 'actions/code-hygiene-check/**' | ||
| - 'actions/affirmation-check/**' | ||
| - 'actions/referencing-check/**' | ||
| - 'actions/secrets-check/**' | ||
| - 'actions/boj-cartridge-check/**' | ||
| - '.github/workflows/code-hygiene-self-test.yml' | ||
| pull_request: | ||
| paths: | ||
| - 'actions/code-hygiene-check/**' | ||
| - 'actions/affirmation-check/**' | ||
| - 'actions/referencing-check/**' | ||
| - 'actions/secrets-check/**' | ||
| - 'actions/boj-cartridge-check/**' | ||
| - '.github/workflows/code-hygiene-self-test.yml' | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Gate controls | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| persist-credentials: false | ||
| - run: bash actions/code-hygiene-check/test.sh | ||
| - run: bash actions/affirmation-check/test.sh | ||
| - run: bash actions/referencing-check/test.sh | ||
| - run: bash actions/secrets-check/test.sh | ||
| - run: bash actions/boj-cartridge-check/test.sh | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,15 @@ | ||
| name: 'Affirmation Document Gate' | ||
| description: 'Validates that the AFFIRMATION document is signed and updated within the last 28 days.' | ||
| description: 'Validates an applicable AFFIRMATION snapshot without treating it as a universal or self-proving document.' | ||
| inputs: | ||
| required: | ||
| description: 'Set true only when the repository declares the governance-tier capability.' | ||
| required: false | ||
| default: 'false' | ||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Run Affirmation Check | ||
| shell: bash | ||
| run: | | ||
| echo "Validating AFFIRMATION Document..." | ||
|
|
||
| # Check for existence (can be .md, .adoc, etc.) | ||
| aff_file=$(find . -maxdepth 1 -name "AFFIRMATION*" | head -n 1) | ||
| if [ -z "$aff_file" ]; then | ||
| echo "::error::AFFIRMATION document not found in the repository root." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Found AFFIRMATION document: $aff_file" | ||
|
|
||
| # Check signature (heuristic: look for 'Signed:', 'Signature:', or PGP block) | ||
| if ! grep -E -i 'signed:|signature:|BEGIN PGP SIGNATURE' "$aff_file" > /dev/null; then | ||
| echo "::error::AFFIRMATION document does not appear to be signed." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check date (updated within last 28 days) | ||
| # First check git log for the file (if it is tracked in git) | ||
| last_update_ts=$(git log -1 --format="%at" -- "$aff_file" 2>/dev/null) | ||
|
|
||
| if [ -z "$last_update_ts" ]; then | ||
| # Fallback to filesystem mtime if not in git (e.g. during initial setup) | ||
| last_update_ts=$(stat -c %Y "$aff_file") | ||
| fi | ||
|
|
||
| current_ts=$(date +%s) | ||
| diff_days=$(( (current_ts - last_update_ts) / 86400 )) | ||
|
|
||
| if [ "$diff_days" -gt 28 ]; then | ||
| echo "::error::AFFIRMATION document is out of date! Last updated $diff_days days ago. Must be updated within 28 days." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "AFFIRMATION Document validation passed. (Updated $diff_days days ago)." | ||
| env: | ||
| AFFIRMATION_REQUIRED: ${{ inputs.required }} | ||
| run: "${{ github.action_path }}/check.sh" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| root=${GITHUB_WORKSPACE:-.} | ||
| required=${AFFIRMATION_REQUIRED:-false} | ||
| aff_file= | ||
|
|
||
| for candidate in AFFIRMATION.adoc AFFIRMATION.md AFFIRMATION; do | ||
| if [[ -f "$root/$candidate" ]]; then | ||
| aff_file=$candidate | ||
| break | ||
| fi | ||
| done | ||
|
|
||
| if [[ -z "$aff_file" ]]; then | ||
| if [[ "$required" == "true" ]]; then | ||
| echo "::error::AFFIRMATION.adoc is required by the declared governance-tier capability." | ||
|
Check warning on line 19 in actions/affirmation-check/check.sh
|
||
| exit 1 | ||
| fi | ||
| echo "::notice::AFFIRMATION is not applicable: governance-tier was not required." | ||
| exit 0 | ||
| fi | ||
|
|
||
| path=$root/$aff_file | ||
| echo "Found AFFIRMATION document: $aff_file" | ||
|
|
||
| substantive_lines=$(awk '!/^[[:space:]]*(#|\/\/|;|$)/ { count++ } END { print count + 0 }' "$path") | ||
| if (( substantive_lines < 5 )); then | ||
| echo "::error::$aff_file has only $substantive_lines substantive lines; it is a stub, not an affirmation." | ||
|
Check warning on line 31 in actions/affirmation-check/check.sh
|
||
| exit 1 | ||
| fi | ||
|
|
||
| if grep -qiE '\{\{|TODO: update|<PROJECT|YOUR_PROJECT|lorem ipsum|example\.com' "$path"; then | ||
| echo "::error::$aff_file contains template placeholders." | ||
|
Check warning on line 36 in actions/affirmation-check/check.sh
|
||
| exit 1 | ||
| fi | ||
|
|
||
| # The signature is the signature on the commit containing this content. Text | ||
| # such as "Signed:" inside the document proves nothing. Shallow checkouts may | ||
| # not contain the file-changing commit, so report that limitation honestly. | ||
| signature=N | ||
| last_update_ts= | ||
| if git -C "$root" rev-parse --is-inside-work-tree >/dev/null 2>&1; then | ||
| signature=$(git -C "$root" log -1 --format='%G?' -- "$aff_file" 2>/dev/null || true) | ||
| last_update_ts=$(git -C "$root" log -1 --format='%at' -- "$aff_file" 2>/dev/null || true) | ||
| fi | ||
|
|
||
| case "$signature" in | ||
| G) echo "Affirmation commit signature verified with a trusted key." ;; | ||
| U) echo "::notice::Affirmation commit has a valid signature from an untrusted or locally unknown key." ;; | ||
| B|R|E) echo "::error::Affirmation commit signature is bad, revoked, or failed verification."; exit 1 ;; | ||
|
Check warning on line 53 in actions/affirmation-check/check.sh
|
||
| *) echo "::notice::Affirmation commit signature could not be verified from the available Git history." ;; | ||
| esac | ||
|
|
||
| # A dated affirmation is a frozen receipt, not a claim that remains current | ||
| # forever. Report age without invalidating historical evidence or forcing an | ||
| # empty monthly rewrite. | ||
| if [[ -n "$last_update_ts" ]]; then | ||
| current_ts=$(date +%s) | ||
| age_days=$(( (current_ts - last_update_ts) / 86400 )) | ||
| if (( age_days > 28 )); then | ||
| echo "::warning::$aff_file is a $age_days-day-old snapshot; verify its anchor before relying on it as current." | ||
| else | ||
| echo "$aff_file snapshot age: $age_days days." | ||
| fi | ||
| fi | ||
|
|
||
| echo "AFFIRMATION document validation passed." | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| here=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) | ||
| fixture=$(mktemp -d) | ||
| trap 'rm -rf -- "$fixture"' EXIT | ||
|
|
||
| GITHUB_WORKSPACE=$fixture AFFIRMATION_REQUIRED=false "$here/check.sh" | ||
|
|
||
| if GITHUB_WORKSPACE=$fixture AFFIRMATION_REQUIRED=true "$here/check.sh"; then | ||
| echo "required-but-absent affirmation unexpectedly passed" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| printf '= AFFIRMATION\n' > "$fixture/AFFIRMATION.adoc" | ||
| if GITHUB_WORKSPACE=$fixture AFFIRMATION_REQUIRED=true "$here/check.sh"; then | ||
| echo "stub affirmation unexpectedly passed" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| printf '%s\n' \ | ||
| '= AFFIRMATION — controlled fixture' \ | ||
| 'This snapshot makes a falsifiable claim.' \ | ||
| 'The claim is anchored to a named revision.' \ | ||
| 'Tests were run and their scope is stated.' \ | ||
| 'Unproved properties are not called proved.' \ | ||
| 'Later revisions must be assessed separately.' \ | ||
| > "$fixture/AFFIRMATION.adoc" | ||
| GITHUB_WORKSPACE=$fixture AFFIRMATION_REQUIRED=true "$here/check.sh" | ||
|
|
||
| echo 'affirmation-check controls passed' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,15 @@ | ||
| name: 'BoJ Cartridge Gate' | ||
| description: 'Validates that a cartridge is present for use with the BoJ server.' | ||
| description: 'Checks for a BoJ cartridge when BoJ integration is applicable.' | ||
| inputs: | ||
| required: | ||
| description: 'Set true when this repository declares BoJ integration.' | ||
| required: false | ||
| default: 'false' | ||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Run BoJ Cartridge Check | ||
| shell: bash | ||
| run: | | ||
| echo "Validating BoJ Cartridge presence..." | ||
|
|
||
| # Check for typical cartridge files | ||
| if [ -f "cartridge.json" ] || [ -f "cartridge.yml" ] || [ -f "cartridge.yaml" ] || [ -d ".cartridges" ] || find . -maxdepth 2 -name "*cartridge*" | grep -q .; then | ||
| echo "BoJ cartridge detected." | ||
| else | ||
| echo "::error::No BoJ cartridge found. A cartridge should be present for use of the tool in full with the BoJ server." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "BoJ Cartridge validation passed." | ||
| env: | ||
| BOJ_CARTRIDGE_REQUIRED: ${{ inputs.required }} | ||
| run: "${{ github.action_path }}/check.sh" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| root=${GITHUB_WORKSPACE:-.} | ||
| required=${BOJ_CARTRIDGE_REQUIRED:-false} | ||
| found= | ||
|
|
||
| for candidate in cartridge.json cartridge.yml cartridge.yaml; do | ||
| if [[ -f "$root/$candidate" ]]; then | ||
| found=$candidate | ||
| break | ||
| fi | ||
| done | ||
| if [[ -z "$found" && -d "$root/.cartridges" ]]; then | ||
| found=.cartridges/ | ||
| fi | ||
|
|
||
| if [[ -z "$found" ]]; then | ||
| if [[ "$required" == "true" ]]; then | ||
| echo '::error::A BoJ cartridge is required but no canonical cartridge path exists.' | ||
|
Check warning on line 22 in actions/boj-cartridge-check/check.sh
|
||
| exit 1 | ||
| fi | ||
| echo '::notice::BoJ cartridge is not applicable to this repository.' | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "BoJ cartridge present at $found." | ||
Uh oh!
There was an error while loading. Please reload this page.