-
Notifications
You must be signed in to change notification settings - Fork 1
refine workflow #34
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
refine workflow #34
Changes from 18 commits
3236ff0
e4672d8
6f5d1ca
5f15d51
a05fdb1
d81ff38
af150fb
017dc8f
41c7412
789b416
15ba739
bf93897
8eaed55
1e910b7
60ed006
a52654c
da517c6
73057ef
5f09e9d
090adca
0c0e547
0ba617e
9e7f6ca
d0f031b
19d95d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| name: 03 Staging Gate | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'staging/**' | ||
| - 'tools/**' | ||
|
|
||
| jobs: | ||
| gate: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Fail if staging folder is missing or empty | ||
| run: | | ||
| if [ ! -d staging ] || [ -z "$(ls -A staging)" ]; then | ||
| echo "::error ::staging folder is missing or empty. Please add or update at least one module." | ||
| exit 1 | ||
| fi | ||
| - name: Staging compatibility check | ||
| run: bash tools/02_validate_module.sh | ||
|
|
||
| - name: Run all tools and report pass/fail | ||
| run: | | ||
| status=0 | ||
| for tool in tools/[0-9][0-9]_*.sh; do | ||
| # Skip 02_validate_module.sh (already run) | ||
| if [[ "$(basename "$tool")" == "02_validate_module.sh" ]]; then | ||
| continue | ||
| fi | ||
| echo "=== Running: $tool ===" | ||
| bash "$tool" | ||
| result=$? | ||
| if [[ $result -eq 0 ]]; then | ||
| echo "::notice ::PASS: $tool" | ||
| else | ||
| echo "::error ::FAIL: $tool (exit code $result)" | ||
| status=1 | ||
| fi | ||
| echo | ||
| done | ||
| exit $status |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,13 +9,13 @@ usage: $0 <modulename>|all|help | |
| Check results: | ||
| OK - File exists and passes checks | ||
| MISSING - File is missing | ||
| WARN - File exists but is incomplete | ||
| FAIL - File exists but is incomplete | ||
|
|
||
| Checks performed: | ||
| - <modulename>.md (must have more than a top-level header) | ||
| - <modulename>.sh (must contain Help info in _about_<modulename>() function) | ||
| - <modulename>.conf (must have required non-comment fields: feature, helpers, description) | ||
| - Checks for duplicate-named files in src/** (warns if present) | ||
| - Checks for duplicate-named files in src/** and docs/** (outside of ./staging) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update .conf usage to reflect additional required fields 🤖 Prompt for AI Agents |
||
|
|
||
| Examples: | ||
| $0 ok_box | ||
|
|
@@ -31,12 +31,11 @@ _check_md() { | |
| return 1 | ||
| fi | ||
| if ! grep -q "^# " "$file"; then | ||
| echo "WARN: $file missing top-level header" | ||
| echo "FAIL: $file missing top-level header" | ||
| return 1 | ||
| fi | ||
| # Check for more content than the header (ignore lines with only # ...) | ||
| if [ "$(grep -c "^# " "$file")" -eq "$(wc -l < "$file")" ]; then | ||
| echo "WARN: $file has only a top-level header" | ||
| echo "FAIL: $file has only a top-level header" | ||
| return 1 | ||
| fi | ||
| echo "OK: $file" | ||
|
|
@@ -49,16 +48,15 @@ _check_sh() { | |
| echo "MISSING: $file" | ||
| return 1 | ||
| fi | ||
| # Accepts either with or without function, with optional spaces | ||
| if ! grep -Eq "^(function[[:space:]]+)?_about_${modname}[[:space:]]*\(\)[[:space:]]*\{" "$file"; then | ||
| echo "WARN: $file missing _about_${modname}()" | ||
| echo "FAIL: $file missing _about_${modname}()" | ||
| return 1 | ||
| fi | ||
| echo "OK: $file" | ||
| } | ||
|
|
||
| _check_conf() { | ||
| local REQUIRED_CONF_FIELDS=(feature helpers description parent group contributor maintainer port) | ||
| local REQUIRED_CONF_FIELDS=(feature options helpers description parent group contributor maintainer port) | ||
| local file="$1" | ||
| local failed=0 | ||
| local failed_fields=() | ||
|
|
@@ -68,12 +66,10 @@ _check_conf() { | |
| return 1 | ||
| fi | ||
|
|
||
| # Extract 'feature' for helper validation | ||
| local feature | ||
| feature="$(grep -E "^feature=" "$file" | cut -d= -f2- | xargs)" | ||
|
|
||
| for field in "${REQUIRED_CONF_FIELDS[@]}"; do | ||
| # Must be present | ||
| if ! grep -qE "^$field=" "$file"; then | ||
| failed=1 | ||
| failed_fields+=(" $field (missing)") | ||
|
|
@@ -83,7 +79,6 @@ _check_conf() { | |
| local value | ||
| value="$(grep -E "^$field=" "$file" | cut -d= -f2- | xargs)" | ||
|
|
||
| # Must not be empty or whitespace | ||
| if [ -z "$value" ]; then | ||
| if [ "$field" = "helpers" ]; then | ||
| failed_fields+=(" helpers (no helper listed; must have at least _about_$feature)") | ||
|
|
@@ -96,37 +91,33 @@ _check_conf() { | |
|
|
||
| case "$field" in | ||
| helpers) | ||
| # Must contain _about_$feature | ||
| if [ -n "$feature" ] && ! echo "$value" | grep -qw "_about_$feature"; then | ||
| failed=1 | ||
| failed_fields+=(" helpers (must include _about_$feature)") | ||
| fi | ||
| ;; | ||
| parent|group) | ||
| # Must be lowercase, no spaces | ||
| if [[ "$value" =~ [A-Z\ ] ]]; then | ||
| failed=1 | ||
| failed_fields+=(" $field (should be lowercase, no spaces)") | ||
| fi | ||
| ;; | ||
| contributor) | ||
| # Must be a GitHub @username | ||
| if [[ ! "$value" =~ ^@[a-zA-Z0-9_-]+$ ]]; then | ||
| failed=1 | ||
| failed_fields+=(" contributor (should be valid github username, like @tearran)") | ||
| fi | ||
| ;; | ||
| maintainer) | ||
| # Must be true or false | ||
| if [[ "$value" != "true" && "$value" != "false" ]]; then | ||
| failed=1 | ||
| failed_fields+=(" maintainer (must be 'true' or 'false')") | ||
| fi | ||
| ;; | ||
| options) | ||
| # Warn (not fail) if blank | ||
| if [ -z "$value" ]; then | ||
| echo "WARN: options field is blank; should describe supported options or 'none'" | ||
| failed=1 | ||
| failed_fields+=(" options (blank; should describe supported options or 'none')") | ||
| fi | ||
| ;; | ||
Tearran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| esac | ||
|
|
@@ -144,19 +135,26 @@ _check_conf() { | |
| fi | ||
| } | ||
|
|
||
| _check_dup_src() { | ||
| file="$1" | ||
| modname="$(basename "$file")" | ||
| # Look for same-named files in src/** (excluding ./staging) | ||
| dups=$(find ./src -type f -name "$modname") | ||
| if [ -n "$dups" ]; then | ||
| echo "WARN: $modname also exists in:" | ||
| echo "$dups" | ||
| echo "If refactoring or bugfix: remove the old src copy." | ||
| echo "If not: rename the new module to avoid conflict." | ||
| return 1 | ||
| fi | ||
| return 0 | ||
| # Check for duplicates in src/ and docs/ (excluding ./staging) | ||
| _check_duplicate_anywhere() { | ||
| local modname="$1" | ||
| local found=0 | ||
| for dir in ./src ./docs; do | ||
| for ext in .sh .md .conf; do | ||
| # Find all matches, ignoring ./staging | ||
| while IFS= read -r file; do | ||
| # Skip if nothing found or file is in ./staging | ||
| [[ -z "$file" ]] && continue | ||
Tearran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [[ "$file" == ./staging/* ]] && continue | ||
| # FAIL if file exists outside staging | ||
| if [ -f "$file" ]; then | ||
| echo "FAIL: Duplicate found in $dir: $file" | ||
Tearran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| found=1 | ||
Tearran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
| done < <(find "$dir" -type f -name "$modname$ext") | ||
| done | ||
Tearran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| done | ||
| return $found | ||
| } | ||
|
|
||
| validate_module() { | ||
|
|
@@ -175,8 +173,7 @@ validate_module() { | |
| _check_md "./staging/$modname.md" || failed=1 | ||
| _check_sh "./staging/$modname.sh" || failed=1 | ||
| _check_conf "./staging/$modname.conf" || failed=1 | ||
| _check_dup_src "./staging/$modname.sh" || failed=1 | ||
|
|
||
| _check_duplicate_anywhere "$modname" || failed=1 | ||
| echo | ||
| done | ||
| if [[ "$failed" -ne 0 ]]; then | ||
|
|
@@ -185,20 +182,13 @@ validate_module() { | |
| fi | ||
| ;; | ||
| *) | ||
| _check_conf "./staging/$cmd.conf" || status=1 | ||
| _check_md "./staging/$cmd.md" || status=1 | ||
| _check_sh "./staging/$cmd.sh" || status=1 | ||
| _check_dup_src "./staging/$cmd.sh" || status=1 | ||
| echo "Unknown command" >&2 | ||
| exit 1 | ||
|
|
||
| if [[ "$status" -ne 0 ]]; then | ||
| echo "One or more validation checks failed for module: $cmd" >&2 | ||
| exit 1 | ||
| fi | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | ||
| validate_module "${1:-all}" | ||
| fi | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.