Run examples on modified PDL files #1
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: Run examples on modified PDL files | |
| on: [pull_request] | |
| jobs: | |
| tests: | |
| name: Execution tests | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| strategy: | |
| fail-fast: false | |
| max-parallel: 1 | |
| matrix: | |
| python-version: ['3.11', '3.12', '3.13'] | |
| steps: | |
| # Detect modified PDL files, includes Add, Modified, but not Deleted | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Detect all PDL files that were changed or added | |
| id: changed-pdl-files | |
| uses: tj-actions/changed-files@6cb76d07bee4c9772c6882c06c37837bf82a04d3 # v46 | |
| with: | |
| files: | | |
| **.pdl | |
| json: "true" | |
| escape_json: "false" | |
| - name: List PDL files that were modified or added and append to test_examples_run | |
| env: | |
| MODIFIED_PDL_FILES: ${{ steps.changed-pdl-files.outputs.all_changed_files }} | |
| run: echo "$MODIFIED_PDL_FILES" | |
| # Run tests if there are modified PDL files | |
| - uses: actions/checkout@v4 | |
| if: ${{ steps.changed-pdl-files.outputs.all_changed_files_count > 0 }} | |
| with: | |
| ref: ${{ github.head_ref }} | |
| fetch-depth: 0 | |
| - name: Check if update results automatically by GitHub Actions Bot | |
| id: parse-run-examples-config | |
| shell: bash | |
| run: | | |
| value=$(yq '.update_results' tests/test_examples_run.yaml | tr '[:upper:]' '[:lower:]') | |
| echo "value=$value" | |
| echo "update_results=$value" >> $GITHUB_OUTPUT | |
| # Install yq if needed | |
| # Cache Ollama before running examples | |
| - name: Restore Ollama model cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.ollama | |
| key: ollama-cache-${{ runner.os }}-llama3 | |
| restore-keys: ollama-cache-${{ runner.os }} | |
| # Cache pip before running examples | |
| - name: Cache pip | |
| uses: actions/cache@v4 | |
| with: | |
| # This path is specific to Ubuntu | |
| path: ${{ env.pythonLocation }} | |
| # Look to see if there is a cache hit for the setup file | |
| key: ${{ runner.os }}-pip-new3-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip-new3 | |
| ${{ runner.os }}-new3 | |
| - uses: ./.github/actions/run-examples | |
| if: ${{ steps.changed-pdl-files.outputs.all_changed_files_count > 0 }} | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| runner-os: ${{ runner.os }} | |
| update-results: ${{ steps.parse-run-examples-config.outputs.update_results }} | |
| check: ${{ steps.changed-pdl-files.outputs.all_changed_files }} | |
| head-ref: ${{ github.head_ref }} | |
| # Patch config with update_results to false | |
| # Fetch the latest branch | |
| - uses: actions/checkout@v4 | |
| if: ${{ steps.parse-run-examples-config.outputs.update_results && matrix.python-version == '3.13' }} | |
| with: | |
| ref: ${{ github.head_ref }} | |
| fetch-depth: 0 | |
| - name: Patch tests/test_examples_run.yaml with update_results to False, only for the last matrix version | |
| if: ${{ steps.parse-run-examples-config.outputs.update_results && matrix.python-version == '3.13' }} | |
| uses: fjogeleit/yaml-update-action@main | |
| with: | |
| changes: | | |
| { | |
| "tests/test_examples_run.yaml": { | |
| "update_results": false | |
| } | |
| } | |
| commitChange: false | |
| - name: Push the new run-examples yaml config | |
| if: ${{ steps.parse-run-examples-config.outputs.update_results && matrix.python-version == '3.13' }} | |
| shell: bash | |
| run: | | |
| git config --local user.name github-actions[bot] | |
| git config --local user.email 41898282+github-actions[bot]@users.noreply.github.com | |
| git status | |
| git pull | |
| git add tests/test_examples_run.yaml | |
| git diff --cached --quiet || git commit -s -m "github-actions[bot]: Run examples: reverting update_result to false on your behalf" | |
| git push | |