-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actions: Add action to ensure the table is updated
This new action will ensure that we don't forget to update the `README.md` whenever a new check is added to the catalog.
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
import re | ||
import sys | ||
from typing import Final | ||
|
||
CHECK_ID_PATTERN: Final[str] = r"(PWR\d+|PWD\d+|RMK\d+)" | ||
CHECKS_DIR: Final[str] = "Checks/" | ||
README_FILE: Final[str] = "README.md" | ||
TABLE_MARKER: Final[str] = "|" | ||
|
||
|
||
def extractIdsFromTable(readmeFile: str) -> set[str]: | ||
with open(readmeFile, "r") as file: | ||
return { | ||
match.group(1) | ||
for line in file.readlines() | ||
if line.startswith(TABLE_MARKER) | ||
and (match := re.search(CHECK_ID_PATTERN, line)) | ||
} | ||
|
||
|
||
def extractIdsFromChecksDirectory(cheksDirectory: str) -> set[str]: | ||
return {entry.name for entry in os.scandir(cheksDirectory) if entry.is_dir()} | ||
|
||
|
||
def main(): | ||
tableIds: Final[set[str]] = extractIdsFromTable(README_FILE) | ||
checksDirIds: Final[set[str]] = extractIdsFromChecksDirectory(CHECKS_DIR) | ||
|
||
missingFromTable: Final[set[str]] = checksDirIds - tableIds | ||
extraInTable: Final[set[str]] = tableIds - checksDirIds | ||
|
||
if missingFromTable: | ||
print( | ||
f"[Error] The following IDs are missing from the README table: " | ||
f"{', '.join(missingFromTable)}" | ||
) | ||
if extraInTable: | ||
print( | ||
f"[Error] The following IDs are listed in the README table but do " | ||
f"not exist in the checks directory: {', '.join(extraInTable)}" | ||
) | ||
|
||
if missingFromTable or extraInTable: | ||
sys.exit(1) | ||
else: | ||
print("README table is up-to-date!") | ||
sys.exit(0) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Validate README Table | ||
|
||
on: | ||
push: | ||
paths: | ||
- '.github/workflows/**' | ||
- 'Checks/**' | ||
- 'README.md' | ||
|
||
jobs: | ||
validate-readme: | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Validate README Table | ||
run: python .github/utils/ValidateReadmeTable.py |