Skip to content

Commit af5e740

Browse files
committed
Don't use composite action in pr
1 parent f5232cc commit af5e740

File tree

1 file changed

+92
-23
lines changed

1 file changed

+92
-23
lines changed

.github/workflows/run-examples-prep.yml

Lines changed: 92 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ jobs:
1717
# Detect modified PDL files, includes Add, Modified, but not Deleted
1818
- uses: actions/checkout@v4
1919
with:
20-
ref: ${{ github.event.pull_request.head.ref }}
21-
repository: ${{ github.event.pull_request.head.repo.full_name }}
22-
token: ${{ github.token }}
2320
fetch-depth: 0
2421
- name: Detect all PDL files that were changed or added
2522
id: changed-pdl-files
@@ -30,38 +27,104 @@ jobs:
3027
json: "true"
3128
escape_json: "false"
3229
- name: List PDL files that were modified or added and append to test_examples_run
33-
env:
34-
MODIFIED_PDL_FILES: ${{ steps.changed-pdl-files.outputs.all_changed_files }}
35-
run: echo "$MODIFIED_PDL_FILES"
30+
run: |
31+
echo ${{ steps.changed-pdl-files.outputs.all_changed_files }}
32+
if [ ${{ steps.changed-pdl-files.outputs.all_changed_files_count }} -gt 0 ]; then
33+
echo "early-stop=false" >> $GITHUB_ENV
34+
else
35+
echo "No file need to be checked, skipping all subsequent tests."
36+
echo "early-stop=true" >> $GITHUB_ENV
37+
fi
3638
3739
# Run tests if there are modified PDL files
3840
- name: Check if update results automatically by GitHub Actions Bot
41+
if: ${{ !env.early-stop }}
3942
id: parse-run-examples-config
4043
shell: bash
4144
run: |
4245
value=$(yq '.update_results' tests/test_examples_run.yaml | tr '[:upper:]' '[:lower:]')
4346
echo "value=$value"
44-
echo "update_results=$value" >> $GITHUB_OUTPUT
47+
echo "update_results=$value" >> $GITHUB_ENV
48+
49+
# Set up Ollama
50+
- name: Cache Ollama model files
51+
if: ${{ !env.early-stop }}
52+
uses: actions/cache@v4
53+
with:
54+
path: /usr/share/ollama/.ollama/models
55+
key: ${{ runner.os }}-build-ollama-cache
56+
restore-keys: |
57+
${{ runner.os }}-build-
58+
${{ runner.os }}
59+
- uses: ./.github/actions/ollama
60+
if: ${{ !env.early-stop }}
4561

46-
- uses: ./.github/actions/run-examples
47-
if: ${{ steps.changed-pdl-files.outputs.all_changed_files_count > 0 }}
62+
# Set up Run Examples environment
63+
- name: Set up Python ${{ matrix.python-version }}
64+
uses: actions/setup-python@v5
65+
if: ${{ !env.early-stop }}
4866
with:
4967
python-version: ${{ matrix.python-version }}
50-
runner-os: ${{ runner.os }}
51-
update-results: ${{ steps.parse-run-examples-config.outputs.update_results }}
52-
check: ${{ steps.changed-pdl-files.outputs.all_changed_files }}
53-
head-ref: ${{ github.event.pull_request.head.ref }}
54-
repository: ${{ github.event.pull_request.head.repo.full_name }}
55-
token: ${{ secrets.PDL_PAT }}
68+
- name: Cache pip
69+
uses: actions/cache@v4
70+
if: ${{ !env.early-stop }}
71+
with:
72+
# This path is specific to Ubuntu
73+
path: ${{ env.pythonLocation }}
74+
# Look to see if there is a cache hit for the setup file
75+
key: ${{ runner.os }}-pip-new3-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}
76+
restore-keys: |
77+
${{ runner.os }}-pip-new3
78+
${{ runner.os }}-new3
79+
- name: Install dependencies
80+
if: ${{ !env.early-stop }}
81+
shell: bash
82+
run: pip install --upgrade --upgrade-strategy eager .[all]
83+
- name: Pip list packages
84+
if: ${{ !env.early-stop }}
85+
shell: bash
86+
run: pip list
87+
- name: View Run Examples config
88+
if: ${{ !env.early-stop }}
89+
shell: bash
90+
run: cat tests/test_examples_run.yaml
91+
- name: Run Pytest
92+
if: ${{ !env.early-stop }}
93+
shell: bash
94+
run: |
95+
(
96+
set +e
97+
py.test -v --capture=tee-sys -rfE -s tests/test_examples_run.py --disable-pytest-warnings
98+
EXIT_CODE=$?
5699
57-
# Patch config with update_results to false
58-
- name: Patch tests/test_examples_run.yaml with update_results to False, only for the last matrix version
59-
if: ${{ steps.parse-run-examples-config.outputs.update_results && matrix.python-version == '3.13' }}
100+
if [ $EXIT_CODE -eq 0 ]; then
101+
echo "TEST_RESULT=PASSED" >> $GITHUB_ENV
102+
else
103+
echo "TEST_RESULT=FAILED" >> $GITHUB_ENV
104+
fi
105+
)
106+
107+
# Commit the results if update results
108+
- name: Push new results to branch
109+
shell: bash
110+
if: ${{ !env.early-stop && env.update_results }}
111+
run: |
112+
git config --local user.name github-actions[bot]
113+
git config --local user.email 41898282+github-actions[bot]@users.noreply.github.com
114+
git status
115+
git pull
116+
git add tests/results/
117+
git diff --cached --quiet || git commit -s -m "github-actions[bot]: Run examples: updated result files on your behalf"
118+
git push
119+
120+
# Patch config with update_results to false and commit to PR
121+
- name: Patch tests/test_examples_run.yaml with update_results to False, only for the last job in the series
122+
if: ${{ !env.early-stop && env.update_results && matrix.python-version == '3.13' }}
60123
shell: bash
61124
run: |
62125
yq -i '.update_results = ('false')' tests/test_examples_run.yaml
63126
- name: Push the new run-examples yaml config
64-
if: ${{ steps.parse-run-examples-config.outputs.update_results && matrix.python-version == '3.13' }}
127+
if: ${{ !env.early-stop && env.update_results && matrix.python-version == '3.13' }}
65128
shell: bash
66129
run: |
67130
git config --local user.name github-actions[bot]
@@ -71,8 +134,14 @@ jobs:
71134
git add tests/test_examples_run.yaml
72135
git diff --cached --quiet || git commit -s -m "github-actions[bot]: Run examples: reverting update_result to false on your behalf"
73136
git push
74-
75-
76-
77-
137+
138+
- name: Check if pytest passed
139+
shell: bash
140+
run: |
141+
if [ "$TEST_RESULT" == "PASSED" ]; then
142+
exit 0
143+
else
144+
exit 1
145+
fi
146+
78147

0 commit comments

Comments
 (0)