Conversation
Co-authored-by: SRF-Audio <16975040+SRF-Audio@users.noreply.github.com>
Co-authored-by: SRF-Audio <16975040+SRF-Audio@users.noreply.github.com>
Co-authored-by: SRF-Audio <16975040+SRF-Audio@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update ansible-lint workflow to restrict checks to changed paths
Scope ansible-lint/yamllint/syntax-check to changed paths; add manual full-lint
Dec 31, 2025
SRF-Audio
requested changes
Dec 31, 2025
- Use jq split() instead of grep/sed/sort for role directory extraction - Run lint tools once with all targets via Python subprocess - Add targets_json output (roles + playbooks combined) - Add has_playbooks boolean output - Simplify syntax-check conditional from playbooks_json != '[]' to has_playbooks == 'true' - Remove unused ansible_yaml filter - Net -13 lines (34 additions, 47 deletions) Co-authored-by: SRF-Audio <16975040+SRF-Audio@users.noreply.github.com>
SRF-Audio
requested changes
Dec 31, 2025
Co-authored-by: SRF-Audio <16975040+SRF-Audio@users.noreply.github.com>
SRF-Audio
reviewed
Dec 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementation Complete ✅
Changes Summary
Update workflow triggers to add
workflow_dispatchand exclude docs-only changesworkflow_dispatch:trigger for manual runs!ansible/**/*.mdand!ansible/**/README*Add
detect-changesjob usingdorny/paths-filter@v3roles_json,playbooks_json,targets_json,has_targets,has_playbooksjq split()to extract role directories:[.[] | select(startswith("ansible/roles/")) | split("/") | "ansible/roles/" + .[2]] | uniquejq -r 'length > 0'Refactor existing jobs to use scoped targets (PR/push only)
ansible-yamllint: runs once with all targets fromtargets_jsonansible-lint: runs once with all targets +--exclude ansible/old_roles/ansible-playbook-syntax: dynamic matrix, conditional onhas_playbooks == 'true'Add
full-lintjob for manual workflow_dispatch runsansible/directoryworkflow_dispatcheventsValidate implementation
Key Improvements from Refactor
✅ No "script gymnastics": Pure jq for normalization, Python for execution
✅ Tools run once: Each lint tool gets all targets in a single invocation
✅ Cleaner conditionals:
has_playbooksboolean instead ofplaybooks_json != '[]'✅ Simpler logic: Removed unused
ansible_yamlfilter✅ More robust: Python
subprocess.run()handles quoting/escaping correctlyAcceptance Criteria Met
✅ PR changing only a role: lints only that role, no syntax-check
✅ PR changing only a playbook: lints and syntax-checks only that playbook
✅ PR changing 2 roles: lints both roles
✅ PR with no ansible changes: workflow doesn't trigger (path filtering)
✅ Manual workflow_dispatch: full-lint runs on everything
Original prompt
This section details on the original issue you should resolve
<issue_title>Scope ansible-lint/yamllint/syntax-check to changed paths; keep full run manual-only</issue_title>
<issue_description>### Goal
Update
.github/workflows/ansible-lint-and-test.ymlso that:Automatic (PR + push to main): run lint/syntax checks only for changed Ansible content (changed roles and/or playbooks), and no-op cleanly if nothing relevant changed.
Manual only: keep a “lint everything” run that only runs via
workflow_dispatchand never on PR/push.Non-goals
tj-actions/changed-files(security history).Design requirements (must follow)
A) Use native workflow path filters first (cheap gating)
At the workflow trigger level, restrict auto runs to only PR/push events that touch
ansible/**(and optionally exclude docs-only changes under ansible).on.pull_request.pathsandon.push.paths.!negation insidepaths). ([GitHub Docs][1])Example intent (don’t copy blindly; implement correctly):
ansible/**!ansible/**/*.md(and optionally!ansible/**/README*)B) Use a reliable changed-file detector for scoping, not ad-hoc git diff
Use
dorny/paths-filter@v3to detect changed files and to output file lists. ([GitHub][3])We need these outputs at minimum:
ansible/roles/argocd_deploy)ansible/playbooks/k3s-cluster-setup.yml)C) Jobs
Keep existing container tooling / image resolution logic / permissions structure as-is as much as possible. Only refactor where needed to add scoped targeting.
We want three logical flows, in the same workflow file:
1)
detect-changesjob (runs on PR/push only)Outputs:
roles_json: JSON array of role directories to lint (unique)playbooks_json: JSON array of changed playbooks to lint/syntax-check (unique)yamllint_targets_json: JSON array of yaml/yml target paths (or role dirs + playbooks)Implementation notes:
Use
dorny/paths-filter@v3withlist-files: json.Then a small normalization step (bash +
jq) to:ansible/roles/<role_name>)2)
scoped-lintjob (runs on PR/push only)Runs only if there is at least one relevant target (role or playbook) from
detect-changes.yamllint_targets_jsonplaybooks_jsonIf no targets exist: job should cleanly skip (use
if:guard).3)
full-lintjob (manual only)Runs only when
github.event_name == 'workflow_dispatch'and runs:ansible/This job must never run for pull_request/push.
Implementation steps (Copilot checklist)
1) Update
on:triggersModify existing workflow triggers (do not replace the workflow) to:
pull_request+pushbut addpaths:to only include Ansible changes (and optionally exclude docs-only changes using!patterns). ([GitHub Docs][1])workflow_dispatch:for manual runs.2) Add
detect-changesjobactions/checkoutwith sufficient history for PR comparisons (usefetch-depth: 0).dorny/paths-filter@v3with filters like:Filters to define (minimum):
roles:ansible/roles/**playbooks:ansible/playbooks/**/*.ymlandansible/playbooks/**/*.yamlansible_yaml:ansible/**/*.ymlandansible/**/*.yaml(optionally exclude docs/templates if needed)Then add a normalization step that produces these job outputs:
roles_json: unique role directories derived from files underansible/roles/<name>/...playbooks_json: list from the playbooks filteryamllint_targets_json: ideally:roles_jsonplaybooks_json3) Refactor existing lint/syntax jobs to use the outputs
...
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.