Skip to content

Commit 68b5ece

Browse files
salmanmkckoverholt
andauthored
Fix python-tests workflow: split get_sample_dirs into its own job (#1420)
* Fix python-tests workflow: split get_sample_dirs into its own job The build job declares `needs: get_sample_dirs`, but get_sample_dirs was defined as a step inside build rather than as a separate job. This caused GitHub Actions to reject the workflow with: The workflow must contain at least one job with no dependencies. This commit: - Extracts get_sample_dirs into its own job with proper outputs - Replaces undefined $PYTHON_DIR with the actual path (samples/python) - Formats the find output as JSON array for fromJson() compatibility - Adds an if condition to skip the build matrix when no samples exist Signed-off-by: Salman Muin Kayser Chishti <13schishti@gmail.com> * Update actions/checkout from v4 to v6 --------- Signed-off-by: Salman Muin Kayser Chishti <13schishti@gmail.com> Co-authored-by: Kristopher Overholt <koverholt@google.com>
1 parent cb2a85b commit 68b5ece

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

.github/workflows/python-tests.yaml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,38 @@ on:
3333
- cron: "0 0 * * 0"
3434

3535
jobs:
36+
get_sample_dirs:
37+
runs-on: ubuntu-latest
38+
outputs:
39+
sample_dirs: ${{ steps.get_dirs.outputs.sample_dirs }}
40+
steps:
41+
- uses: actions/checkout@v6
42+
with:
43+
ref: ${{ github.event.pull_request.head.sha }}
44+
45+
- name: Get Sample Directories
46+
id: get_dirs
47+
run: |
48+
SAMPLE_DIRS=$( find samples/python -type d -not -path "*/.venv*" -exec test -e '{}'/requirements.txt \; -print | jq -R -s -c 'split("\n") | map(select(. != ""))' )
49+
echo "sample_dirs=$SAMPLE_DIRS" >> $GITHUB_OUTPUT
50+
echo "SAMPLE_DIRS: $SAMPLE_DIRS" # For debugging
51+
3652
build:
3753
runs-on: ubuntu-latest
54+
needs:
55+
- get_sample_dirs
56+
if: ${{ needs.get_sample_dirs.outputs.sample_dirs != '[]' }}
3857
strategy:
3958
matrix:
4059
python-version: ["3.9", "3.10", "3.11", "3.12"]
4160
sample_dir: ${{ fromJson(needs.get_sample_dirs.outputs.sample_dirs) }}
4261
fail-fast: false # Important: Don't stop if one matrix configuration fails
4362

44-
needs:
45-
- get_sample_dirs
46-
4763
steps:
4864
- uses: actions/checkout@v6
4965
with:
5066
ref: ${{ github.event.pull_request.head.sha }}
5167

52-
- name: Get Sample Directories
53-
id: get_sample_dirs
54-
run: |
55-
SAMPLE_DIRS=$( find $PYTHON_DIR -type d -not -path "*/.venv*" -exec test -e '{}'/requirements.txt \; -print )
56-
echo "sample_dirs=$SAMPLE_DIRS" >> $GITHUB_OUTPUT
57-
echo "SAMPLE_DIRS: $SAMPLE_DIRS" # For debugging
58-
5968
- name: Set up Python ${{ matrix.python-version }}
6069
uses: actions/setup-python@v6
6170
with:
@@ -91,4 +100,4 @@ jobs:
91100
pytest.txt
92101
./htmlcov/
93102
retention-days: 30
94-
if: ${{ always() }}
103+
if: ${{ always() }}

0 commit comments

Comments
 (0)