Skip to content

Introducing Run Examples check in PRs #21

Introducing Run Examples check in PRs

Introducing Run Examples check in PRs #21

---
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
run: |
echo ${{ steps.changed-pdl-files.outputs.all_changed_files }}
if [ ${{ steps.changed-pdl-files.outputs.all_changed_files_count }} -gt 0 ]; then
echo "early-stop=false" >> $GITHUB_ENV
else
echo "No file need to be checked, skipping all subsequent tests."
echo "early-stop=true" >> $GITHUB_ENV
fi
# Run tests if there are modified PDL files
- name: Check if update results automatically by GitHub Actions Bot
if: ${{ env.early-stop == 'false' }}
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_ENV
# Set up Ollama
# - name: Cache Ollama model files
# if: ${{ env.early-stop == 'false' }}
# uses: actions/cache@v4
# with:
# path: /usr/share/ollama/.ollama/models
# key: ${{ runner.os }}-build-ollama-cache
# restore-keys: |
# ${{ runner.os }}-build-
# ${{ runner.os }}
- uses: ./.github/actions/ollama
if: ${{ env.early-stop == 'false' }}
# Set up Run Examples environment
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
if: ${{ env.early-stop == 'false' }}
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v4
if: ${{ env.early-stop == 'false' }}
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
- name: Install dependencies
if: ${{ env.early-stop == 'false' }}
shell: bash
run: pip install --upgrade --upgrade-strategy eager .[all]
- name: Pip list packages
if: ${{ env.early-stop == 'false' }}
shell: bash
run: pip list
- name: Patch tests/test_examples_run.yaml check with modified files
if: ${{ env.early-stop == 'false' }}
shell: bash
run: |
yq -i '.check = (${{ steps.changed-pdl-files.outputs.all_changed_files }})' tests/test_examples_run.yaml
- name: View Run Examples config
if: ${{ env.early-stop == 'false' }}
shell: bash
run: cat tests/test_examples_run.yaml
- name: Run Pytest
if: ${{ env.early-stop == 'false' }}
shell: bash
run: |
(
set +e
py.test -v --capture=tee-sys -rfE -s tests/test_examples_run.py --disable-pytest-warnings
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo "TEST_RESULT=PASSED" >> $GITHUB_ENV
else
echo "TEST_RESULT=FAILED" >> $GITHUB_ENV
fi
)
# Commit the results if update results
- name: Push new results to branch
shell: bash
if: ${{ env.early-stop == 'false' && env.update_results == 'true' }}
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/results/
git diff --cached --quiet || git commit -s -m "github-actions[bot]: Run examples: updated result files on your behalf"
git push
# Patch config with update_results to false and commit to PR
- name: Patch tests/test_examples_run.yaml with update_results to False, only for the last job in the series
if: ${{ env.early-stop == 'false' && env.update_results == 'true' && matrix.python-version == '3.13' }}
shell: bash
run: |
yq -i '.update_results = ('false')' tests/test_examples_run.yaml
- name: Push the new run-examples yaml config
if: ${{ env.early-stop == 'false' && env.update_results == 'true' && 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
- name: Check if pytest passed
shell: bash
if: ${{ env.early-stop == 'false' }}
run: |
if [ "$TEST_RESULT" == "PASSED" ]; then
exit 0
else
exit 1
fi