-
Notifications
You must be signed in to change notification settings - Fork 561
feat: add config example validation script and workflow #2627
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
base: master
Are you sure you want to change the base?
Changes from all commits
56f7bb7
80a24e3
a503fe3
4b9c5ca
527c2d8
6d7e5c9
a132634
d99381e
f4ac340
2e0e31f
98406cc
c22f888
30f2e45
9d94865
4758ed7
b8d553f
782be6d
2538636
af69845
67b9f8f
a303da3
b30f5f9
b4f4f68
139ccd3
381b212
45086a5
9fda3df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| name: Validate example configurations in PRs | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '**/*.md' | ||
|
|
||
| permissions: {} | ||
|
|
||
| # Avoid multiple commits on the same PR racing to update the comment. | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| validate-configs: | ||
| name: Validate example configurations in changed Markdown files | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Check out code | ||
| uses: actions/checkout@v7 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Get changed Markdown files | ||
| # We do not use the usual changed files action because of previous security issues. | ||
| id: changed_files | ||
| # This complex command finds files changed in the PR, filtering for `.md` and also ensuring they are in the `docs` directory. | ||
| # It ensures we only process files that are part of the PR and match our pattern. | ||
| # Note: The `github.event.pull_request.base.sha` is used to get the base commit of the PR, which is important for accurate diffing. | ||
| # | ||
| # On pull requests, HEAD refers to the merge commit. | ||
| # We want to compare against the base of the PR. | ||
| # Use git diff to get files changed between the PR base and the current commit. | ||
| # --name-only lists only the names of the files. | ||
| # --diff-filter=AMCR will only show Added, Modified, Copied, Renamed files. | ||
| # We grep for *.md files you are interested in. | ||
| # The 'docs/' prefix is a common convention but adjust as necessary. | ||
| run: | | ||
| changed_md=$(git diff --name-only --diff-filter=AMCR ${{ github.event.pull_request.base.sha }}...HEAD | grep '\.md$' || true) | ||
| echo "Changed Markdown files: $changed_md" | ||
| # The value is newline-separated, so it needs the multiline output delimiter syntax. | ||
| # A random delimiter avoids any chance of the value terminating the block early. | ||
| delimiter=$(openssl rand -hex 16) | ||
| { | ||
| echo "list<<${delimiter}" | ||
| echo "${changed_md}" | ||
| echo "${delimiter}" | ||
| } >> "$GITHUB_OUTPUT" | ||
| shell: bash | ||
|
eschabell marked this conversation as resolved.
|
||
|
|
||
| - name: Validate example configurations provided in any changed files | ||
| run: | | ||
| if [ -z "${CHANGED_MD_FILES:-}" ]; then | ||
| echo "No Markdown files changed in this PR. Skipping validation." | ||
| exit 0 | ||
| fi | ||
|
|
||
| error_count=0 | ||
|
|
||
| # Loop through each changed file | ||
| for FILE in $CHANGED_MD_FILES; do | ||
| echo "Processing changed file: $FILE" | ||
| ./scripts/test-config.sh "$FILE" || error_count=$((error_count + 1)) | ||
| done | ||
|
Comment on lines
+65
to
+68
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== workflow excerpt =="
sed -n '1,110p' .github/workflows/pr-example-validation.yaml 2>/dev/null || true
echo
echo "== script behavior probe =="
python3 - <<'PY'
import subprocess, shlex
files = ["pipeline/guide with spaces.md", "pipeline/*glob*.md", "pipeline/[brackets].md"]
env = {
"CHANGED_MD_FILES": "\n".join(files),
"PATH": "/usr/bin:/bin",
"SHELL": "/bin/bash",
}
# Simulate the shell loop's explicit arguments by building the command
# as a child process prints argv[0], then exits successfully.
script = r'''
set -u
for FILE in $CHANGED_MD_FILES; do
printf '%s\n' "$FILE"
done
'''
proc = subprocess.run(["bash", "-c", script], env=env, text=True, capture_output=True)
print("stderr:", proc.stderr.strip() if proc.stderr.strip() else "")
print("stdin:", f"CHANGED_MD_FILES contains {len(files)} filenames")
print("output:")
print(proc.stdout)
PYRepository: fluent/fluent-bit-docs Length of output: 3324 Preserve each changed path as one argument.
🤖 Prompt for AI Agents |
||
|
|
||
| if [ $error_count -ne 0 ]; then | ||
| echo "ERROR: Validation failed for $error_count file(s)." | ||
| exit 1 | ||
| fi | ||
| shell: bash | ||
| env: | ||
| CHANGED_MD_FILES: ${{ steps.changed_files.outputs.list }} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: fluent/fluent-bit-docs
Length of output: 219
🏁 Script executed:
Repository: fluent/fluent-bit-docs
Length of output: 7182
🏁 Script executed:
Repository: fluent/fluent-bit-docs
Length of output: 626
Fail when
git diffcannot compute the changed-file list.changed_md=$(git diff ... | grep '\.md$' || true)makes the whole command succeed even ifgit diffencounters an invalid revision or repository error.CHANGED_MD_FILESstays empty, so the validation step prints “No Markdown files changed” and exits successfully.Compute
git diffseparately, exit on failure, then filter the output for Markdown files.🤖 Prompt for AI Agents