Skip to content

Commit b2fbe4c

Browse files
feat(scripts): 5 fix scripts for hypatia WF024 chapel + WF025 cron-drift (#251)
Companion to hypatia#422. Implements the auto-fix side. License-category remains disabled per #247. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0b479f4 commit b2fbe4c

6 files changed

Lines changed: 212 additions & 1 deletion
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MPL-2.0
3+
#
4+
# fix-chapel-chpl-llvm-export.sh — ensure CHPL_LLVM is exported on Chapel jobs
5+
#
6+
# Driven by hypatia WF024 (chapel-chpl-llvm-export recipe). Sharp edge #2 in
7+
# panic-attack wiki Chapel-Metalayer.md: CHPL_LLVM is required by `chpl`'s
8+
# diagnostic + build steps; unset means the toolchain falls back to a different
9+
# code path that doesn't link against libllvm14 (the .deb's only supported
10+
# binding).
11+
#
12+
# Inserts `export CHPL_LLVM=bundled` (the only supported value for the
13+
# precompiled .deb path) into the install step.
14+
#
15+
# Idempotent.
16+
17+
set -euo pipefail
18+
19+
REPO_PATH="$1"
20+
FINDING_FILE="${2:-}"
21+
22+
cd "$REPO_PATH"
23+
24+
CHANGED=0
25+
for f in $(find .github/workflows -name '*.yml' -o -name '*.yaml' 2>/dev/null); do
26+
if ! grep -qE 'CHAPEL_DEB_URL|chapel-[0-9]+\.[0-9]+' "$f"; then
27+
continue
28+
fi
29+
if grep -qE 'CHPL_LLVM[[:space:]]*=' "$f"; then
30+
continue # already exported / set
31+
fi
32+
if grep -qE 'chpl --version|sudo apt-get install.*chapel' "$f"; then
33+
sed -i -E '0,/(chpl --version|sudo apt-get install.*chapel)/{s|^([[:space:]]*)(chpl --version\|sudo apt-get install.*chapel)|\1export CHPL_LLVM=bundled\n\1\2|}' "$f"
34+
echo " CHPL_LLVM=bundled exported: $f"
35+
CHANGED=$((CHANGED + 1))
36+
fi
37+
done
38+
39+
echo "fix-chapel-chpl-llvm-export: $CHANGED change(s) applied"
40+
exit 0
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MPL-2.0
3+
#
4+
# fix-chapel-manpath-guard.sh — guard against unset MANPATH on Chapel install
5+
#
6+
# Driven by hypatia WF024 (chapel-manpath-guard recipe). One of the 5 sharp
7+
# edges in panic-attack wiki Chapel-Metalayer.md: the chpl install step
8+
# references $MANPATH unconditionally; unset MANPATH explodes under `set -u`.
9+
#
10+
# Inserts `: \${MANPATH:=}` BEFORE the chapel install runs.
11+
#
12+
# Idempotent.
13+
14+
set -euo pipefail
15+
16+
REPO_PATH="$1"
17+
FINDING_FILE="${2:-}"
18+
19+
cd "$REPO_PATH"
20+
21+
CHANGED=0
22+
for f in $(find .github/workflows -name '*.yml' -o -name '*.yaml' 2>/dev/null); do
23+
if ! grep -qE 'CHAPEL_DEB_URL|chapel-[0-9]+\.[0-9]+' "$f"; then
24+
continue
25+
fi
26+
if grep -qF ': ${MANPATH:=}' "$f"; then
27+
continue # already guarded
28+
fi
29+
# Insert guard before the first `chpl --version` or chapel install line
30+
if grep -qE 'chpl --version|sudo apt-get install.*chapel' "$f"; then
31+
sed -i -E '0,/(chpl --version|sudo apt-get install.*chapel)/{s|^([[:space:]]*)(chpl --version\|sudo apt-get install.*chapel)|\1: ${MANPATH:=}\n\1\2|}' "$f"
32+
echo " MANPATH guard inserted: $f"
33+
CHANGED=$((CHANGED + 1))
34+
fi
35+
done
36+
37+
echo "fix-chapel-manpath-guard: $CHANGED change(s) applied"
38+
exit 0
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MPL-2.0
3+
#
4+
# fix-chapel-replace-chpl-about.sh — replace dropped `chpl --about` with
5+
# the 2.8-compatible equivalent.
6+
#
7+
# Driven by hypatia WF024 (chapel-replace-chpl-about-with-version recipe).
8+
# Sharp edge #3 in panic-attack wiki Chapel-Metalayer.md: `chpl --about` was
9+
# removed in Chapel 2.8 — workflows that rely on it for diagnostic output
10+
# break silently (no `--about` flag is a no-op + exits 0 on some versions).
11+
#
12+
# Replace with `chpl --version && printchplenv` which gives the same
13+
# information across the 2.7/2.8 split.
14+
#
15+
# Idempotent.
16+
17+
set -euo pipefail
18+
19+
REPO_PATH="$1"
20+
FINDING_FILE="${2:-}"
21+
22+
cd "$REPO_PATH"
23+
24+
CHANGED=0
25+
for f in $(find .github/workflows -name '*.yml' -o -name '*.yaml' 2>/dev/null); do
26+
if ! grep -qF 'chpl --about' "$f"; then
27+
continue
28+
fi
29+
sed -i 's|chpl --about|chpl --version \&\& printchplenv|g' "$f"
30+
echo " chpl --about → chpl --version && printchplenv: $f"
31+
CHANGED=$((CHANGED + 1))
32+
done
33+
34+
echo "fix-chapel-replace-chpl-about: $CHANGED change(s) applied"
35+
exit 0

scripts/fix-chapel-runs-on-pin.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MPL-2.0
3+
#
4+
# fix-chapel-runs-on-pin.sh — pin runs-on: ubuntu-22.04 on any Chapel-using job
5+
#
6+
# Driven by hypatia WF024 (chapel-runs-on-pin-22-04 recipe). The Chapel-2.8.0
7+
# .deb (chapel-X.Y.Z-N.ubuntu22.amd64.deb) is ABI-linked to libclang-cpp.so.14
8+
# / LLVM-14 — only present on Ubuntu 22.04. ubuntu-latest / ubuntu-24.04
9+
# resolves the unmet dep with libclang-cpp-18 → `chpl` exit 127 at startup.
10+
#
11+
# Idempotent: skips files already pinned to ubuntu-22.04.
12+
13+
set -euo pipefail
14+
15+
REPO_PATH="$1"
16+
FINDING_FILE="${2:-}"
17+
18+
cd "$REPO_PATH"
19+
20+
CHANGED=0
21+
for f in $(find .github/workflows -name '*.yml' -o -name '*.yaml' 2>/dev/null); do
22+
# Only patch files that actually reference Chapel
23+
if ! grep -qE 'CHAPEL_DEB_URL|chapel-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+\.ubuntu22|chpl --(version|about)|printchplenv' "$f"; then
24+
continue
25+
fi
26+
27+
if grep -qE '^[[:space:]]+runs-on:[[:space:]]+ubuntu-latest' "$f"; then
28+
sed -i -E 's|^([[:space:]]+)runs-on:[[:space:]]+ubuntu-latest|\1runs-on: ubuntu-22.04|' "$f"
29+
echo " pinned ubuntu-22.04: $f"
30+
CHANGED=$((CHANGED + 1))
31+
fi
32+
33+
# Also normalise the apt install pattern (declarative resolution beats dpkg+fix loop)
34+
if grep -qF 'sudo dpkg -i /tmp/chapel.deb || sudo apt-get install -f -y' "$f"; then
35+
sed -i 's|sudo dpkg -i /tmp/chapel.deb || sudo apt-get install -f -y|sudo apt-get install -y /tmp/chapel.deb|' "$f"
36+
echo " apt-get install replaces dpkg fallback: $f"
37+
CHANGED=$((CHANGED + 1))
38+
fi
39+
done
40+
41+
echo "fix-chapel-runs-on-pin: $CHANGED change(s) applied in $REPO_PATH"
42+
exit 0

scripts/fix-codeql-cron-monthly.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MPL-2.0
3+
#
4+
# fix-codeql-cron-monthly.sh — convert codeql.yml cron to canonical monthly
5+
#
6+
# Driven by hypatia WF025 (codeql-cron-monthly recipe). Per standards#286
7+
# (Option B 2026-05-30 estate decision): CodeQL schedule monthly canonical
8+
# `0 6 1 * *`. PR-trigger runs unchanged.
9+
#
10+
# Handles both #288-shape (weekly `0 6 * * 1` → monthly) and #324-shape
11+
# (any non-canonical cron → monthly).
12+
#
13+
# Idempotent: skips files already on canonical monthly.
14+
15+
set -euo pipefail
16+
17+
REPO_PATH="$1"
18+
FINDING_FILE="${2:-}"
19+
20+
cd "$REPO_PATH"
21+
22+
F=".github/workflows/codeql.yml"
23+
if [[ ! -f "$F" ]]; then
24+
echo "fix-codeql-cron-monthly: no $F in $REPO_PATH"
25+
exit 0
26+
fi
27+
28+
if grep -qF "cron: '0 6 1 * *'" "$F"; then
29+
echo "fix-codeql-cron-monthly: already canonical monthly: $F"
30+
exit 0
31+
fi
32+
33+
python3 - <<PY
34+
import re, sys
35+
p = "$F"
36+
content = open(p).read()
37+
new, n = re.subn(
38+
r"(^[ \t]*-[ \t]*cron:[ \t]*)'[^']+'(.*)",
39+
r"\1'0 6 1 * *' # monthly 1st 06:00 UTC",
40+
content,
41+
count=1,
42+
flags=re.MULTILINE,
43+
)
44+
if n == 0:
45+
print("fix-codeql-cron-monthly: no cron line found in", p)
46+
sys.exit(0)
47+
open(p, "w").write(new)
48+
print(f"fix-codeql-cron-monthly: 1 cron line replaced in", p)
49+
PY
50+
51+
exit 0

scripts/fix-script-registry.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@
9797
"recipe-add-feedback-integration": "fix-missing-feedback-integration.sh",
9898
"recipe-add-vexometer-hooks": "fix-missing-vexometer-hooks.sh",
9999
"recipe-remove-tracked-package-lock": "fix-tracked-package-lock.sh",
100-
"cicd_rules/tracked_npm_lockfile": "fix-tracked-package-lock.sh"
100+
"cicd_rules/tracked_npm_lockfile": "fix-tracked-package-lock.sh",
101+
"chapel-runs-on-pin-22-04": "fix-chapel-runs-on-pin.sh",
102+
"codeql-cron-monthly": "fix-codeql-cron-monthly.sh",
103+
"chapel-manpath-guard": "fix-chapel-manpath-guard.sh",
104+
"chapel-chpl-llvm-export": "fix-chapel-chpl-llvm-export.sh",
105+
"chapel-replace-chpl-about-with-version": "fix-chapel-replace-chpl-about.sh"
101106
}
102107
}
103108
}

0 commit comments

Comments
 (0)