diff --git a/.github/workflows/repo_health.yml b/.github/workflows/repo_health.yml index 2a2d473..e078ebb 100644 --- a/.github/workflows/repo_health.yml +++ b/.github/workflows/repo_health.yml @@ -12,8 +12,8 @@ # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . @@ -24,7 +24,7 @@ # REPO: https://github.com/mokoconsulting-tech/MokoStandards # PATH: /.github/workflows/repo_health.yml # VERSION: 03.05.00 -# BRIEF: Enforces Joomla repository guardrails by validating release configuration, required validation scripts, tooling availability, and core repository health artifacts. +# BRIEF: Enforces repository guardrails by validating release configuration, scripts governance, tooling availability, and core repository health artifacts using MokoStandards definition files. # ============================================================================ name: Repo Health @@ -122,7 +122,11 @@ jobs: contents: read steps: - $1 + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Load guardrails definition env: GUARDRAILS_DEFINITION_URL: ${{ vars.MOKOSTANDARDS_GUARDRAILS_URL || 'https://raw.githubusercontent.com/mokoconsulting-tech/MokoStandards/main/repo-guardrails.definition.json' }} @@ -154,31 +158,18 @@ if not env_path: def put_multiline(key: str, values): vals = [str(v) for v in (values or []) if str(v).strip()] with open(env_path, "a", encoding="utf-8") as w: - w.write(f"{key}< "${key_file}" - printf '\n' >> "${key_file}" + printf '%s\n' "${FTP_KEY}" > "${key_file}" chmod 600 "${key_file}" if [ -n "${FTP_PASSWORD:-}" ]; then @@ -293,9 +310,7 @@ PY echo "Attempting non-destructive SFTP session" >> "${GITHUB_STEP_SUMMARY}" set +e - printf 'pwd -bye -' | sftp -oBatchMode=yes -oStrictHostKeyChecking=no -P "${port}" -i "${key_file}" "${FTP_USER}@${FTP_HOST}" >/tmp/sftp_check.log 2>&1 + printf 'pwd\nbye\n' | sftp -oBatchMode=yes -oStrictHostKeyChecking=no -P "${port}" -i "${key_file}" "${FTP_USER}@${FTP_HOST}" >/tmp/sftp_check.log 2>&1 sftp_rc=$? set -e @@ -321,7 +336,11 @@ bye contents: read steps: - $1 + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Load guardrails definition env: GUARDRAILS_DEFINITION_URL: ${{ vars.MOKOSTANDARDS_GUARDRAILS_URL || 'https://raw.githubusercontent.com/mokoconsulting-tech/MokoStandards/main/repo-guardrails.definition.json' }} @@ -348,25 +367,15 @@ with open(path, "r", encoding="utf-8") as f: env_path = os.environ.get("GITHUB_ENV") if not env_path: - raise SystemExit("GITHUB_ENV not set") + raise SystemExit("GITHUB_ENV not set") def put_multiline(key: str, values): - vals = [str(v) for v in (values or []) if str(v).strip()] - with open(env_path, "a", encoding="utf-8") as w: - w.write(f"{key}<> "${GITHUB_STEP_SUMMARY}" echo "Warning: scripts/ directory is optional. No scripts governance enforced." >> "${GITHUB_STEP_SUMMARY}" exit 0 fi - required_script_dirs=( - "scripts/fix" - "scripts/lib" - "scripts/release" - "scripts/run" - "scripts/validate" - ) - - optional_script_dirs=( - "scripts/config" - "scripts/tools" - "scripts/docs" - ) - + required_script_dirs=("scripts/fix" "scripts/lib" "scripts/release" "scripts/run" "scripts/validate") + optional_script_dirs=("scripts/config" "scripts/tools" "scripts/docs") allowed_script_dirs=( "scripts" "scripts/fix" @@ -431,6 +427,22 @@ PY "scripts/docs" ) + if [ "${GUARDRAILS_LOADED:-false}" = "true" ] && [ -n "${GUARDRAILS_SCRIPTS_RECOMMENDED_DIRS:-}" ]; then + rec=() + while IFS= read -r v; do [ -n "${v}" ] && rec+=("${v}"); done < <(printf '%s\n' "${GUARDRAILS_SCRIPTS_RECOMMENDED_DIRS}") + if [ "${#rec[@]}" -gt 0 ]; then + required_script_dirs=("${rec[@]}") + fi + fi + + if [ "${GUARDRAILS_LOADED:-false}" = "true" ] && [ -n "${GUARDRAILS_SCRIPTS_ALLOWED_DIRS:-}" ]; then + al=() + while IFS= read -r v; do [ -n "${v}" ] && al+=("${v}"); done < <(printf '%s\n' "${GUARDRAILS_SCRIPTS_ALLOWED_DIRS}") + if [ "${#al[@]}" -gt 0 ]; then + allowed_script_dirs=("${al[@]}") + fi + fi + missing_dirs=() unapproved_dirs=() @@ -477,7 +489,6 @@ PY echo "Scripts governance completed in advisory mode." >> "${GITHUB_STEP_SUMMARY}" - repo_health: name: Repository health runs-on: ubuntu-latest @@ -488,7 +499,11 @@ PY contents: read steps: - $1 + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Load guardrails definition env: GUARDRAILS_DEFINITION_URL: ${{ vars.MOKOSTANDARDS_GUARDRAILS_URL || 'https://raw.githubusercontent.com/mokoconsulting-tech/MokoStandards/main/repo-guardrails.definition.json' }} @@ -518,27 +533,18 @@ if not env_path: raise SystemExit("GITHUB_ENV not set") def put_multiline(key: str, values): - vals = [str(v) for v in (values or []) if str(v).strip()] - with open(env_path, "a", encoding="utf-8") as w: - w.write(f"{key}<> "${GITHUB_STEP_SUMMARY}" + { + printf "### Guardrails repository health\n\n" + printf "### Guardrails report (JSON)\n" + printf "```json\n" + printf "%s\n" "${report_json}" + printf "```\n" + } >> "${GITHUB_STEP_SUMMARY}" if [ "${#missing_required[@]}" -gt 0 ]; then echo "### Missing required repo artifacts" >> "${GITHUB_STEP_SUMMARY}" @@ -704,4 +721,3 @@ PY fi echo "Repository health guardrails passed." >> "${GITHUB_STEP_SUMMARY}" -\n