feat: add config example validation script and workflow #5
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
| 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-tree 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-tree --no-commit-id --name-only --diff-filter=AMCR ${{ github.event.pull_request.base.sha }}...HEAD | grep './.*\.md$' || true) | |
| echo "Changed Markdown files: $changed_md" | |
| echo "list=${changed_md}" >> $GITHUB_OUTPUT | |
| shell: bash | |
| - 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 | |
| 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 }} |