Skip to content

feat(yaml): parse GitHub Actions workflow run steps as bash - #5584

Closed
m3lonxd wants to merge 1 commit into
Graphify-Labs:v8from
m3lonxd:feat/gha-workflow-run-bash-edges-5565
Closed

m3lonxd wants to merge 1 commit into
Graphify-Labs:v8from
m3lonxd:feat/gha-workflow-run-bash-edges-5565

Conversation

@m3lonxd

@m3lonxd m3lonxd commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #5565

GitHub Actions workflow run: steps under .github/workflows/ (and composite action.yml / action.yaml steps) frequently invoke repository scripts (e.g. bash scripts/check.sh, ./scripts/lint) that are never called anywhere else, leaving workflows disconnected and scripts appearing unused.

This PR:

  • Extracts extract_bash_source() in graphify/extractors/bash.py so extract_yaml() can parse qualifying run: step bodies purely in memory with tree-sitter-bash and attach discovered script-invocation (calls/invokes) and source (imports_from) edges directly to the workflow/action file node with accurate YAML line provenance.
  • Recognizes extensionless shebang-backed bash scripts (e.g. ./scripts/lint with #!/usr/bin/env bash) and safe runner flags (e.g. bash -euo pipefail scripts/check.sh, while stopping on -c / unknown flags).
  • Anchors workflow step paths to the repository root (honoring workflow/job defaults.run.working-directory and step working-directory, plus $GITHUB_WORKSPACE).
  • Neutralizes GitHub Actions ${{ ... }} expressions into a non-resolvable placeholder while preserving line count so expressions never split adjacent tokens across ERROR nodes or trigger guessed fallback paths.
  • Updates _looks_like_bash() in graphify/extract.py so source calls inside workflow steps also participate in resolve_bash_source_edges.
  • Bumps _AST_CACHE_SCHEMA from 58 to 59 so cached YAML/workflow and bash extractions refresh.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

  • Deterministic & in-memory: No temp files, shell execution, or string interpolation into shell/Python; tested with monkeypatched NamedTemporaryFile, mkstemp, subprocess.run, subprocess.Popen, and os.system.

  • Fail-closed & security-bounded: Rejects non-bash shells (pwsh, powershell, cmd, python, Windows runners without explicit bash shell, and composite steps without shell), ${{ ... }} in script/working-directory paths, missing/non-script targets, and out-of-tree/UNC paths (via _resolve_safe / _safe_to_probe before any stat). Missing tree-sitter-bash degrades gracefully without failing YAML extraction.

  • Limitations / unsupported cases: Non-bash workflow shells, dynamic runtime expressions (${{ ... }}) inside script paths, reusable workflow uses: edges, and Windows-default PowerShell steps without shell: bash are intentionally left unlinked.

  • Read the CONTRIBUTING.md guide.

  • Reproduced the issue and identified the invariant.

  • Made the smallest fix necessary.

  • Added a regression test (if bug fix) or isolated boundary test.

  • Kept the PR description synchronized with the final implementation.

  • Documented any limitations / unsupported cases explicitly.

How was this tested?

uv run --frozen pytest tests/test_yaml_extraction.py tests/test_symbol_resolution.py tests/test_unc_probe_guard.py tests/test_extractors_registry.py tests/test_grammar_cache_key.py tests/test_cache.py tests/test_affected_cli.py tests/test_architecture_doc.py tests/test_node_id_canonical.py tests/test_extract_code_only_cli.py -q
  -> 255 passed, 1 skipped (Windows-only symlink/case test)
uv run --frozen pytest tests/test_extract.py -k 'bash' -q
  -> 66 passed, 309 deselected
uv run --frozen ruff check .
  -> All checks passed!
uv run --frozen pyright graphify/extractors/bash.py graphify/extractors/yaml_config.py tests/test_yaml_extraction.py
  -> 0 errors, 0 warnings, 0 informations
uv run --frozen python -m tools.skillgen --check
  -> check OK: 134 artifact(s) match committed output and expected/.
uv run --frozen bandit -r graphify/extractors/bash.py graphify/extractors/yaml_config.py graphify/cache.py -ll -q
  -> 0 high/medium findings

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A — no skill fragments modified)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

Parse bash-compatible GitHub Actions workflow and composite action run: steps in memory with tree-sitter-bash via extract_bash_source() and attach script-invocation/source edges directly to the workflow/action file node with exact YAML line provenance.

Key details and invariants:
- Resolves workflow run: scripts relative to the repository root (respecting defaults.run.working-directory and step working-directory) and pre-seeds GITHUB_WORKSPACE safely inside the scan/repo root ceiling.
- Recognizes extensionless shebang-backed bash scripts (e.g. ./scripts/lint) in bash script invocations alongside .sh/.bash scripts, and skips shell runner flags (-euo pipefail) while failing closed on -c or unknown flags.
- Neutralizes GitHub Actions ${{ ... }} expressions into a non-resolvable placeholder while preserving line numbers so expressions never split adjacent tokens across ERROR nodes or fall back to guessed paths.
- Fails closed on non-bash shells (pwsh, cmd, python, Windows runners with unset shell), out-of-tree/UNC paths, missing targets, and missing tree-sitter-bash.
- Bumps _AST_CACHE_SCHEMA 58 -> 59 so cached YAML/workflow and bash extractions refresh.

Fixes Graphify-Labs#5565

Co-Authored-By: Gemini <[email protected]>
@m3lonxd
m3lonxd requested a review from safishamsi as a code owner November 28, 2026 12:04
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @m3lonxd. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Nothing blocking · 4 possible issues to check · Merge confidence 5/5

4 possible issues to check · High impact

GitHub Actions workflow and composite-action run: steps are parsed as Bash when their shell settings qualify.

4 possible issues we couldn't confirm

They don't change the score.

What this review covered
  • A changed file's diff was too long to show in full, so the review may not have seen every changed line in it.
  • Part of a file with a line too long to show was not read.
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
  • 5 of 5 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 5860 functions depend on this change
  • 8 functions became more coupled. Largest: extract() (1421 callers), build_from_json() (354 callers), detect() (158 callers).
  • 416 of 652 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed e1ae041

@safishamsi

Copy link
Copy Markdown
Member

Thanks @m3lonxd — this GitHub-Actions-run-as-bash feature is well-built and overreach-verified (windows jobs / non-GHA YAML produce no edges). Holding it here because v0.9.123 just landed eight bash-extractor PRs (#5568/#5569/#5570/#5576/#5577/#5578/#5589/#5597) that heavily rewrote bash.py, and this PR's ~500-line refactor now conflicts with them in several regions — merging it blind risked breaking the extractor. Could you rebase onto the current v8 bash.py? The feature itself is a clear merge once it's on top of the landed bash work. Reopen/resubmit after rebase and I'll fast-track it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GitHub Actions workflows: run: steps are not parsed as bash, so a workflow has no edge to the scripts it runs

2 participants