Skip to content

Add workflow to report ID and file name mismatch#4903

Merged
aneta-petrova merged 10 commits into
theforeman:masterfrom
aneta-petrova:script-id-filename-match
Jun 8, 2026
Merged

Add workflow to report ID and file name mismatch#4903
aneta-petrova merged 10 commits into
theforeman:masterfrom
aneta-petrova:script-id-filename-match

Conversation

@aneta-petrova
Copy link
Copy Markdown
Member

@aneta-petrova aneta-petrova commented Jun 3, 2026

What changes are you introducing?

Adding a pull request check that reports when a module's file name, ID, or heading don't match.

Why are you introducing these changes? (Explanation, links to references, issues, etc.)

It happens to me all the time that I forget to keep them in sync in my PRs, and seeing a warning saves precious peer reviewers' time that they otherwise have to spend pointing it out to me 🙃

Anything else to add? (Considerations, potential downsides, alternative solutions you have explored, etc.)

My first choice would have been Vale but Vale can't read file names. Hence a script.

Contributor checklists

  • I am okay with my commits getting squashed when you merge this PR.
  • I am familiar with the contributing guidelines.

Please cherry-pick my commits into:

  • Foreman 3.19/Katello 4.21
  • Foreman 3.18/Katello 4.20 (Satellite 6.19)
  • Foreman 3.17/Katello 4.19
  • Foreman 3.16/Katello 4.18 (Satellite 6.18; orcharhino 7.6, 7.7, and 7.8)
  • Foreman 3.15/Katello 4.17
  • Foreman 3.14/Katello 4.16 (Satellite 6.17; orcharhino 7.4; orcharhino 7.5)
  • Foreman 3.13/Katello 4.15 (EL9 only)
  • Foreman 3.12/Katello 4.14 (Satellite 6.16; orcharhino 7.2 on EL9 only; orcharhino 7.3)
  • We do not accept PRs for Foreman older than 3.12.

@aneta-petrova aneta-petrova changed the title Script id filename match Add workflow to report ID and file name mismatch Jun 3, 2026
@github-actions github-actions Bot added Needs tech review Requires a review from the technical perspective Needs style review Requires a review from docs style/grammar perspective labels Jun 3, 2026
Adds a bash script that checks whether module IDs match their filenames,
following the repository convention where IDs should mirror the filename
(without the module type prefix like con_, proc_, ref_).

The script handles the {project-context} attribute substitution and
skips snippets and assemblies which don't follow this convention.

Also adds a GitHub Actions workflow that runs the check on changed
module files in pull requests.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@aneta-petrova aneta-petrova force-pushed the script-id-filename-match branch from 9b6d294 to e725aa1 Compare June 3, 2026 14:42
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

The PR preview for 8ec7aa4 is available at theforeman-foreman-documentation-preview-pr-4903.surge.sh

No diff compared to the current base

show diff

@aneta-petrova aneta-petrova removed Needs tech review Requires a review from the technical perspective Needs style review Requires a review from docs style/grammar perspective labels Jun 3, 2026
@aneta-petrova aneta-petrova force-pushed the script-id-filename-match branch 11 times, most recently from 39285a9 to 0a6286b Compare June 3, 2026 18:58
aneta-petrova and others added 5 commits June 4, 2026 09:58
Updates the ID-filename check workflow to use reviewdog with the
github-pr-check reporter, which creates check run annotations on PRs.

The workflow now:
- Installs reviewdog
- Runs the check script on each changed file
- Parses the script output with awk (handling ANSI color codes)
- Converts to reviewdog's rdjsonl format
- Creates check annotations on the PR (visible in Files changed tab)
- Fails the check when ID-filename mismatches are found

Using github-pr-check reporter instead of github-pr-review because it
works with read-only tokens from fork PRs, while still providing inline
feedback on the diff similar to Vale's output.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Removes:
- files_ignore for snippets (script handles this internally)

Keeps the 'List changed files' step for debugging purposes.
Extends the script to handle additional attributes found in module IDs:
- {smart-proxy-context} → smartproxy
- {ProjectNameID} → project
- {ProjectServerID} → project-server
- {customreposid} → repositories
- {FreeIPA-context} → freeipa
- {insights-id} → insights
- {foreman-installer} → foreman-installer
- and other less common variants

Does NOT handle {context} or _{context} suffix - these are legacy
format and should be reported as mismatches.
@aneta-petrova aneta-petrova force-pushed the script-id-filename-match branch 5 times, most recently from 93d2270 to 1901a8a Compare June 4, 2026 11:58
The heading normalization was missing the {foreman-installer} attribute
replacement, causing false positives for files that use this attribute
in their headings.
@aneta-petrova aneta-petrova force-pushed the script-id-filename-match branch 6 times, most recently from 50b8820 to 05e9020 Compare June 4, 2026 12:19
Renames from check-id-filename-match to check-filename-id-heading-match
to better reflect that the script validates all three elements: filename,
ID, and heading.

Script changes:
- check-id-filename-match.sh → check-filename-id-heading-match.sh
- Updated usage line in script header

Workflow changes:
- check-id-filename.yml → check-filename-id-heading-match.yml
- Workflow name: 'Check Filename-ID-Heading Match'
- Job name: check-match
- Step names updated
- Reviewdog reporter name updated
@aneta-petrova aneta-petrova force-pushed the script-id-filename-match branch from 05e9020 to 7a2a271 Compare June 4, 2026 12:21
@aneta-petrova aneta-petrova marked this pull request as ready for review June 4, 2026 12:24
@aneta-petrova
Copy link
Copy Markdown
Member Author

aneta-petrova commented Jun 4, 2026

I've tested this on many different filename/ID/heading changes. A few examples of the errors the check produced when I was testing it.

Heading includes "Content flows" but the ID and filename are "content-flow":
Screenshot From 2026-06-04 13-58-20

ID includes "-test", and the extra word produces a warning:
Screenshot From 2026-06-04 10-00-23

ID is capitalized but the expectation is a lower-case ID:
Screenshot From 2026-06-04 09-52-32

Nothing happens for snippets because they're not supposed to have IDs; the workflow skips them entirely:
Screenshot From 2026-06-04 09-31-50

ID contains _{context}, which gets reported as a mis-match. This is in line with our convention to remove _{context} from new IDs:
Screenshot From 2026-06-04 09-31-36

Some of these examples showcase that the check handles attributes in IDs as well, as long as they're defined in the list of attributes to be normalized in the script itself. ({project-context} in ID versus project in filename, for example).

@aneta-petrova aneta-petrova force-pushed the script-id-filename-match branch 6 times, most recently from 037905a to 80c4f17 Compare June 4, 2026 12:52
@aneta-petrova
Copy link
Copy Markdown
Member Author

I tried to account for capitalization requirements too:

A capitalized word in the heading doesn't trigger a warning:
Screenshot From 2026-06-04 14-51-44

But a capitalized element in the ID does because IDs are supposed to be lower case only:
Screenshot From 2026-06-04 14-52-43

@aneta-petrova aneta-petrova force-pushed the script-id-filename-match branch from 80c4f17 to 7a2a271 Compare June 4, 2026 12:54
@aneta-petrova aneta-petrova added the Needs style review Requires a review from docs style/grammar perspective label Jun 4, 2026
@aneta-petrova
Copy link
Copy Markdown
Member Author

Ready for review now. I've done a lot of testing by breaking various IDs/headings/file names and took screenshots of the messages (see comments above).

Copy link
Copy Markdown
Contributor

@Lennonka Lennonka left a comment

Choose a reason for hiding this comment

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

Oh, this is very elegant! I appreciate that it's attribute aware.

Can we just tweak the naming a bit so that we get an equally elegant pipeline name, ie. check / Filename-ID-Heading match ? Pretty please?

Comment thread .github/workflows/check-filename-id-heading-match.yml Outdated
Comment thread .github/workflows/check-filename-id-heading-match.yml Outdated
Co-authored-by: Lena Ansorge <zuansorg@redhat.com>
Copy link
Copy Markdown
Contributor

@Lennonka Lennonka left a comment

Choose a reason for hiding this comment

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

Thank you! LGTM

@aneta-petrova aneta-petrova added style review done No issues from docs style/grammar perspective and removed Needs style review Requires a review from docs style/grammar perspective labels Jun 4, 2026
@aneta-petrova
Copy link
Copy Markdown
Member Author

Oh, this is very elegant!

This is one of those situations 'why hasn't anyone thought of this before', right? 😆

I appreciate that it's attribute aware.

Agreed, that's great. Courtesy of Claude but very neat and seems to work reliably. Also, it should be easy for anyone to update the list in the script with more attributes if needed.

@Lennonka Lennonka added the testing done No issues from the functional perspective label Jun 5, 2026
@aneta-petrova aneta-petrova merged commit e29759b into theforeman:master Jun 8, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

style review done No issues from docs style/grammar perspective testing done No issues from the functional perspective

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants