prepare for website #318
Workflow file for this run
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: Parser Reference Guard | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened, labeled, unlabeled] | |
| jobs: | |
| parser-reference-guard: | |
| if: > | |
| !contains(github.event.pull_request.labels.*.name, 'ignore-parser-reference-guard') && | |
| (github.event.action == 'opened' || | |
| github.event.action == 'synchronize' || | |
| github.event.action == 'reopened' || | |
| github.event.label.name == 'ignore-parser-reference-guard' || | |
| github.event.label.name == 'require-parser-reference-update') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Verify parser references were updated when needed | |
| env: | |
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| PR_LABELS: ${{ join(github.event.pull_request.labels.*.name, ',') }} | |
| run: | | |
| set -euo pipefail | |
| CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA") | |
| echo "Changed files:" | |
| echo "$CHANGED_FILES" | |
| echo "PR labels: ${PR_LABELS:-<none>}" | |
| FORCE_LABEL="require-parser-reference-update" | |
| IGNORE_LABEL="ignore-parser-reference-guard" | |
| if [[ ",${PR_LABELS}," == *",${FORCE_LABEL},"* && \ | |
| ",${PR_LABELS}," == *",${IGNORE_LABEL},"* ]]; then | |
| echo "Conflicting labels: ${FORCE_LABEL} and ${IGNORE_LABEL}. Remove one." | |
| exit 1 | |
| fi | |
| if [[ ",${PR_LABELS}," == *",${IGNORE_LABEL},"* ]]; then | |
| echo "${IGNORE_LABEL} label present; skipping guard." | |
| exit 0 | |
| fi | |
| C_DOC="docs/developer/c-parser-reference.md" | |
| FORTRAN_DOC="docs/developer/fortran-parser-reference.md" | |
| PYI_DOC="docs/user/reference/semantic-pyi-format.md" | |
| C_DOC_CHANGED=false | |
| FORTRAN_DOC_CHANGED=false | |
| PYI_DOC_CHANGED=false | |
| C_PARSER_CHANGED=false | |
| FORTRAN_PARSER_CHANGED=false | |
| PYI_PARSER_CHANGED=false | |
| SHARED_PARSER_CHANGED=false | |
| if grep -Fxq "$C_DOC" <<< "$CHANGED_FILES"; then | |
| C_DOC_CHANGED=true | |
| fi | |
| if grep -Fxq "$FORTRAN_DOC" <<< "$CHANGED_FILES"; then | |
| FORTRAN_DOC_CHANGED=true | |
| fi | |
| if grep -Fxq "$PYI_DOC" <<< "$CHANGED_FILES"; then | |
| PYI_DOC_CHANGED=true | |
| fi | |
| while IFS= read -r changed_file; do | |
| case "$changed_file" in | |
| x2py/parsers/c/*|tests/parser/c/*|tests/parsing/c/*|tests/data/c/*|tests/probes/test_c_types.py) | |
| C_PARSER_CHANGED=true | |
| ;; | |
| x2py/parsers/fortran/*|tests/parser/fortran/*|tests/parsing/fortran/*|tests/data/fortran/*|tests/probes/test_fortran_types.py) | |
| FORTRAN_PARSER_CHANGED=true | |
| ;; | |
| x2py/parsers/pyi/*|tests/parsing/pyi/*|tests/pipeline/pyi_builds/*) | |
| PYI_PARSER_CHANGED=true | |
| ;; | |
| tests/parser/conftest.py|\ | |
| tests/cli/*|\ | |
| tests/pipeline/preprocessing/*|\ | |
| x2py/parsers/__init__.py|\ | |
| x2py/preprocessing.py) | |
| SHARED_PARSER_CHANGED=true | |
| ;; | |
| esac | |
| done <<< "$CHANGED_FILES" | |
| if [[ ",${PR_LABELS}," == *",${FORCE_LABEL},"* ]]; then | |
| if [ "$C_DOC_CHANGED" = true ] || [ "$FORTRAN_DOC_CHANGED" = true ] || [ "$PYI_DOC_CHANGED" = true ]; then | |
| echo "${FORCE_LABEL} label present and at least one parser reference changed." | |
| else | |
| echo "${FORCE_LABEL} label present, but no parser reference changed." | |
| echo "Update ${C_DOC}, ${FORTRAN_DOC}, or ${PYI_DOC}, or remove ${FORCE_LABEL}." | |
| exit 1 | |
| fi | |
| fi | |
| FAILED=false | |
| if [ "$C_PARSER_CHANGED" = true ] && [ "$C_DOC_CHANGED" != true ]; then | |
| echo "C parser-related files changed without updating ${C_DOC}." | |
| FAILED=true | |
| fi | |
| if [ "$FORTRAN_PARSER_CHANGED" = true ] && [ "$FORTRAN_DOC_CHANGED" != true ]; then | |
| echo "Fortran parser-related files changed without updating ${FORTRAN_DOC}." | |
| FAILED=true | |
| fi | |
| if [ "$PYI_PARSER_CHANGED" = true ] && [ "$PYI_DOC_CHANGED" != true ]; then | |
| echo "Semantic .pyi parser-related files changed without updating ${PYI_DOC}." | |
| FAILED=true | |
| fi | |
| if [ "$SHARED_PARSER_CHANGED" = true ] && \ | |
| [ "$C_DOC_CHANGED" != true ] && \ | |
| [ "$FORTRAN_DOC_CHANGED" != true ] && \ | |
| [ "$PYI_DOC_CHANGED" != true ]; then | |
| echo "Shared parser workflow files changed without updating a parser reference." | |
| echo "Update ${C_DOC}, ${FORTRAN_DOC}, or ${PYI_DOC}, whichever behavior changed." | |
| FAILED=true | |
| fi | |
| if [ "$FAILED" = true ]; then | |
| echo "Use ${IGNORE_LABEL} only when the parser reference is already accurate." | |
| exit 1 | |
| fi | |
| if [ "$C_DOC_CHANGED" = true ]; then | |
| echo "${C_DOC} changed." | |
| fi | |
| if [ "$FORTRAN_DOC_CHANGED" = true ]; then | |
| echo "${FORTRAN_DOC} changed." | |
| fi | |
| if [ "$PYI_DOC_CHANGED" = true ]; then | |
| echo "${PYI_DOC} changed." | |
| fi | |
| echo "Parser reference guard passed." |