1919 with :
2020 node-version : ' 18'
2121 cache : ' npm'
22+ # optional: if your lockfile lives in a subdirectory, change this to e.g. "subdir/package-lock.json"
23+ cache-dependency-path : package-lock.json
2224
2325 - name : Set up Python
2426 uses : actions/setup-python@v4
5456 npm ci
5557 elif [ -f pnpm-lock.yaml ]; then
5658 echo "Found pnpm-lock.yaml -> running: pnpm install --frozen-lockfile"
57- npm i -g pnpm || true
59+ npm i -g pnpm@latest || true
5860 pnpm install --frozen-lockfile || pnpm install
5961 elif [ -f yarn.lock ]; then
6062 echo "Found yarn.lock -> running: yarn install --frozen-lockfile"
@@ -64,14 +66,14 @@ jobs:
6466 npm install
6567 fi
6668
67- # run build script if present
68- if npm run | sed -n '1,200p' | grep -q " build"; then
69+ # run build script if present in package.json
70+ if grep -q '" build"' package.json >/dev/null 2>&1 ; then
6971 echo "Running npm run build"
7072 npm run build || true
7173 fi
7274
73- # run tests if present
74- if npm test --silent 2 >/dev/null; then
75+ # run tests if a test script is present
76+ if grep -q '" test"' package.json >/dev/null 2>&1 ; then
7577 echo "Running npm test"
7678 npm test || true
7779 fi
9496 if [ -f setup.py ]; then
9597 pip install . || true
9698 fi
99+ # run pytest if tests exist
97100 if [ -d tests ] || ls *_test.py >/dev/null 2>&1; then
98101 pip install pytest || true
99- pytest || true
102+ python -m pytest -q || true
100103 fi
101104 else
102105 echo "No Python packaging files detected"
@@ -129,19 +132,21 @@ jobs:
129132 - name : Collect common artifact paths
130133 id : collect
131134 run : |
135+ # avoid literal globs when nothing matches
136+ shopt -s nullglob
132137 paths=""
133138 for p in build dist out; do
134139 if [ -d "$p" ]; then
135140 paths="$paths $p"
136141 fi
137142 done
138143 for a in *.tar.gz *.zip *.exe; do
139- if ls $a >/dev/null 2>&1; then
140- paths="$paths $a "
141- fi
144+ for f in $a; do
145+ paths="$paths $f "
146+ done
142147 done
143- # Trim leading space
144- paths="$(echo $paths | sed 's/^ *//')"
148+ # Trim leading/trailing whitespace
149+ paths="$(echo " $paths" | sed -e 's/^ *//' -e 's/ *$ //')"
145150 echo "paths=$paths" >> $GITHUB_OUTPUT
146151
147152 - name : Upload build artifacts (if any)
0 commit comments