|
| 1 | +# SPDX-License-Identifier: MPL-2.0 |
| 2 | +# README single-source derivation — Reusable Workflow (ADR-004) |
| 3 | +# |
| 4 | +# Author READMEs once in AsciiDoc; derive README.md ONLY for repos that |
| 5 | +# declare a Markdown consumer in their descriptiles. This workflow reads that |
| 6 | +# declaration, regenerates the derived file behind a fail-closed vocabulary |
| 7 | +# gate, and (in the default check mode) fails-and-tells if the committed |
| 8 | +# README.md is stale — it never self-commits and never converts an undeclared |
| 9 | +# repo. Absence of a declaration is a machine-readable "do not convert": the |
| 10 | +# anti-runaway guard that the June 2026 estate-wide .adoc->.md sweep lacked. |
| 11 | +name: README Derive Reusable Workflow |
| 12 | + |
| 13 | +on: |
| 14 | + workflow_call: |
| 15 | + inputs: |
| 16 | + runs-on: |
| 17 | + description: Runner label |
| 18 | + type: string |
| 19 | + required: false |
| 20 | + default: ubuntu-latest |
| 21 | + threshold: |
| 22 | + description: Vocabulary-preservation floor (percent). ADR-004 default 98. |
| 23 | + type: number |
| 24 | + required: false |
| 25 | + default: 98 |
| 26 | + standards-ref: |
| 27 | + description: Ref of hyperpolymath/standards to source the vocab-gate script from. |
| 28 | + type: string |
| 29 | + required: false |
| 30 | + default: main |
| 31 | + |
| 32 | +permissions: |
| 33 | + contents: read |
| 34 | + |
| 35 | +# Read-only check workflow — safe to cancel superseded runs. |
| 36 | +concurrency: |
| 37 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 38 | + cancel-in-progress: true |
| 39 | + |
| 40 | +jobs: |
| 41 | + derive-readme: |
| 42 | + name: Derive & verify README.md |
| 43 | + runs-on: ${{ inputs.runs-on }} |
| 44 | + timeout-minutes: 10 |
| 45 | + steps: |
| 46 | + - name: Checkout caller repository |
| 47 | + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v4 |
| 48 | + |
| 49 | + - name: Read publishing declaration |
| 50 | + id: decl |
| 51 | + run: | |
| 52 | + # Prefer descriptiles; fall back to the deprecated 6a2 dir during the |
| 53 | + # estate migration. No file / no [publishing.readme] table / derive |
| 54 | + # not true => this repo has opted out and we do nothing. |
| 55 | + ECO="" |
| 56 | + for c in .machine_readable/descriptiles/ECOSYSTEM.a2ml \ |
| 57 | + .machine_readable/6a2/ECOSYSTEM.a2ml; do |
| 58 | + if [ -f "$c" ]; then ECO="$c"; break; fi |
| 59 | + done |
| 60 | +
|
| 61 | + if [ -z "$ECO" ]; then |
| 62 | + echo "No ECOSYSTEM.a2ml found — repo not opted in. Nothing to derive." |
| 63 | + echo "derive=false" >> "$GITHUB_OUTPUT" |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | + echo "Reading declaration from: $ECO" |
| 67 | +
|
| 68 | + # Extract the flat [publishing.readme] table into KEY=VALUE lines. |
| 69 | + eval "$( |
| 70 | + awk ' |
| 71 | + /^[[:space:]]*\[/ { inblk = ($0 ~ /^[[:space:]]*\[publishing\.readme\][[:space:]]*$/) ? 1 : 0; next } |
| 72 | + inblk && /=/ { |
| 73 | + key = $0; sub(/=.*/, "", key); gsub(/[[:space:]]/, "", key) |
| 74 | + val = $0; sub(/^[^=]*=[[:space:]]*/, "", val) |
| 75 | + sub(/[[:space:]]*(#.*)?$/, "", val) # strip trailing comment/space |
| 76 | + gsub(/^"|"$/, "", val) # strip surrounding quotes |
| 77 | + if (key ~ /^(canonical|derive|format|path|consumer)$/) |
| 78 | + printf "DECL_%s=%s\n", toupper(key), val |
| 79 | + } |
| 80 | + ' "$ECO" |
| 81 | + )" |
| 82 | +
|
| 83 | + if [ "${DECL_DERIVE:-false}" != "true" ]; then |
| 84 | + echo "[publishing.readme] absent or derive != true — repo not opted in." |
| 85 | + echo "derive=false" >> "$GITHUB_OUTPUT" |
| 86 | + exit 0 |
| 87 | + fi |
| 88 | +
|
| 89 | + CANONICAL="${DECL_CANONICAL:-README.adoc}" |
| 90 | + DERIVED_PATH="${DECL_PATH:-README.md}" |
| 91 | + FORMAT="${DECL_FORMAT:-gfm}" |
| 92 | + CONSUMER="${DECL_CONSUMER:-unspecified}" |
| 93 | +
|
| 94 | + if [ ! -f "$CANONICAL" ]; then |
| 95 | + echo "::error::Declared canonical '$CANONICAL' does not exist." |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + if [ "$FORMAT" != "gfm" ]; then |
| 99 | + echo "::error::Unsupported derived format '$FORMAT' (only 'gfm' is implemented)." |
| 100 | + exit 1 |
| 101 | + fi |
| 102 | +
|
| 103 | + echo "Opted in: consumer=$CONSUMER $CANONICAL -> $DERIVED_PATH ($FORMAT)" |
| 104 | + { |
| 105 | + echo "derive=true" |
| 106 | + echo "canonical=$CANONICAL" |
| 107 | + echo "derived_path=$DERIVED_PATH" |
| 108 | + echo "consumer=$CONSUMER" |
| 109 | + } >> "$GITHUB_OUTPUT" |
| 110 | +
|
| 111 | + - name: Install toolchain |
| 112 | + if: steps.decl.outputs.derive == 'true' |
| 113 | + run: | |
| 114 | + sudo apt-get update -qq |
| 115 | + sudo apt-get install -y -qq pandoc |
| 116 | + # asciidoctor + include-reducer from rubygems (ubuntu ships ruby) |
| 117 | + sudo gem install --no-document asciidoctor asciidoctor-reducer |
| 118 | + pandoc --version | head -1 |
| 119 | + asciidoctor --version | head -1 |
| 120 | +
|
| 121 | + - name: Fetch vocab-gate script from standards |
| 122 | + if: steps.decl.outputs.derive == 'true' |
| 123 | + run: | |
| 124 | + # Version-locked to the same standards ref that owns this workflow. |
| 125 | + git clone --depth 1 --branch "${{ inputs.standards-ref }}" \ |
| 126 | + https://github.com/hyperpolymath/standards.git "$RUNNER_TEMP/standards" |
| 127 | + chmod +x "$RUNNER_TEMP/standards/.github/scripts/readme-vocab-gate.sh" |
| 128 | +
|
| 129 | + - name: Derive Markdown from AsciiDoc |
| 130 | + if: steps.decl.outputs.derive == 'true' |
| 131 | + env: |
| 132 | + CANONICAL: ${{ steps.decl.outputs.canonical }} |
| 133 | + run: | |
| 134 | + set -euo pipefail |
| 135 | + # 1) flatten includes so the source is self-contained |
| 136 | + asciidoctor-reducer "$CANONICAL" -o "$RUNNER_TEMP/reduced.adoc" |
| 137 | + # 2) reliable route: asciidoc -> docbook -> gfm (direct converters lose structure) |
| 138 | + asciidoctor -b docbook5 -a attribute-missing=drop \ |
| 139 | + "$RUNNER_TEMP/reduced.adoc" -o "$RUNNER_TEMP/reduced.xml" |
| 140 | + pandoc -f docbook -t gfm --wrap=preserve \ |
| 141 | + "$RUNNER_TEMP/reduced.xml" -o "$RUNNER_TEMP/body.md" |
| 142 | +
|
| 143 | + # 3) stamp: carry the canonical SPDX line (rewritten as an HTML |
| 144 | + # comment) + a GENERATED banner so no one hand-edits the artefact. |
| 145 | + SPDX="$(grep -m1 -oE 'SPDX-License-Identifier:[[:space:]]*[^[:space:]]+' "$CANONICAL" || true)" |
| 146 | + { |
| 147 | + [ -n "$SPDX" ] && echo "<!-- $SPDX -->" |
| 148 | + echo "<!-- GENERATED from $CANONICAL by standards/.github/workflows/readme-derive-reusable.yml — do not edit. -->" |
| 149 | + echo "" |
| 150 | + cat "$RUNNER_TEMP/body.md" |
| 151 | + } > "$RUNNER_TEMP/derived.md" |
| 152 | +
|
| 153 | + - name: Vocabulary-preservation gate |
| 154 | + if: steps.decl.outputs.derive == 'true' |
| 155 | + env: |
| 156 | + CANONICAL: ${{ steps.decl.outputs.canonical }} |
| 157 | + run: | |
| 158 | + "$RUNNER_TEMP/standards/.github/scripts/readme-vocab-gate.sh" \ |
| 159 | + "$CANONICAL" "$RUNNER_TEMP/derived.md" "${{ inputs.threshold }}" |
| 160 | +
|
| 161 | + - name: Freshness check (fail-and-tell) |
| 162 | + if: steps.decl.outputs.derive == 'true' |
| 163 | + env: |
| 164 | + DERIVED_PATH: ${{ steps.decl.outputs.derived_path }} |
| 165 | + CANONICAL: ${{ steps.decl.outputs.canonical }} |
| 166 | + run: | |
| 167 | + set -euo pipefail |
| 168 | + if [ ! -f "$DERIVED_PATH" ]; then |
| 169 | + echo "::error::Declared derived README '$DERIVED_PATH' is missing. Regenerate and commit it." |
| 170 | + SHOW_CMD=1 |
| 171 | + elif ! diff -q "$RUNNER_TEMP/derived.md" "$DERIVED_PATH" >/dev/null; then |
| 172 | + echo "::error::'$DERIVED_PATH' is STALE relative to '$CANONICAL'. Regenerate and commit it." |
| 173 | + echo "----- diff (committed vs regenerated) -----" |
| 174 | + diff "$DERIVED_PATH" "$RUNNER_TEMP/derived.md" || true |
| 175 | + SHOW_CMD=1 |
| 176 | + else |
| 177 | + echo "✓ $DERIVED_PATH is up to date with $CANONICAL" |
| 178 | + exit 0 |
| 179 | + fi |
| 180 | +
|
| 181 | + cat <<'EOF' |
| 182 | +
|
| 183 | + To regenerate locally (requires asciidoctor, asciidoctor-reducer, pandoc): |
| 184 | +
|
| 185 | + asciidoctor-reducer README.adoc -o /tmp/reduced.adoc |
| 186 | + asciidoctor -b docbook5 -a attribute-missing=drop /tmp/reduced.adoc -o /tmp/reduced.xml |
| 187 | + pandoc -f docbook -t gfm --wrap=preserve /tmp/reduced.xml -o /tmp/body.md |
| 188 | + # then prepend the SPDX + GENERATED banner (see the workflow's stamp step) |
| 189 | +
|
| 190 | + Fail-and-tell mode (ADR-004): CI does not auto-commit. Commit the |
| 191 | + regenerated README.md yourself. |
| 192 | + EOF |
| 193 | + exit 1 |
0 commit comments