Skip to content

Commit bac6369

Browse files
authored
Refactor CI workflow for better language handling
Updated CI workflow to improve language detection and build steps.
1 parent 186f4f6 commit bac6369

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ jobs:
1313
- name: Checkout repository
1414
uses: actions/checkout@v4
1515

16-
- name: Set up Node.js 18
16+
- name: Set up Node.js 18 (if present)
1717
uses: actions/setup-node@v4
1818
with:
1919
node-version: '18'
20+
cache: 'npm'
2021

21-
- name: Set up Python 3.x
22+
- name: Set up Python 3.x (if present)
2223
uses: actions/setup-python@v4
2324
with:
2425
python-version: '3.x'
2526

26-
- name: Set up Go 1.20
27+
- name: Set up Go 1.20 (if present)
2728
uses: actions/setup-go@v4
2829
with:
2930
go-version: '1.20'
@@ -33,7 +34,7 @@ jobs:
3334
echo "Repository root:"
3435
ls -la
3536
36-
- name: Install dependencies and build (multi-language)
37+
- name: Detect languages and build/test
3738
run: |
3839
set -e
3940
@@ -45,10 +46,12 @@ jobs:
4546
echo ""
4647
echo "Detected Node.js project (package.json found)"
4748
npm ci || npm install || true
48-
if npm run | grep -q " build"; then
49+
# run build if script exists
50+
if npm run | sed -n '1,200p' | grep -q " build"; then
4951
echo "Running npm run build"
5052
npm run build || true
5153
fi
54+
# run tests if any
5255
if npm test --silent 2>/dev/null; then
5356
echo "Running npm test"
5457
npm test || true
@@ -61,7 +64,7 @@ jobs:
6164
if [ -f requirements.txt ] || [ -f pyproject.toml ] || [ -f setup.py ]; then
6265
echo ""
6366
echo "Detected Python project"
64-
python -m pip install --upgrade pip
67+
python -m pip install --upgrade pip setuptools wheel || true
6568
if [ -f requirements.txt ]; then
6669
pip install -r requirements.txt || true
6770
fi
@@ -84,8 +87,8 @@ jobs:
8487
if ls *.go >/dev/null 2>&1 || [ -d cmd ]; then
8588
echo ""
8689
echo "Detected Go project"
87-
go version
88-
go env
90+
go version || true
91+
go env || true
8992
go build ./... || true
9093
go test ./... || true
9194
else
@@ -95,11 +98,11 @@ jobs:
9598
# Makefile
9699
if [ -f Makefile ]; then
97100
echo ""
98-
echo "Makefile found — running common targets if present"
99-
if grep -q "^build:" Makefile; then
101+
echo "Makefile found — running build/test if present"
102+
if grep -qE '^build:' Makefile; then
100103
make build || true
101104
fi
102-
if grep -q "^test:" Makefile; then
105+
if grep -qE '^test:' Makefile; then
103106
make test || true
104107
fi
105108
fi
@@ -119,13 +122,12 @@ jobs:
119122
paths="$paths $a"
120123
fi
121124
done
122-
echo "::set-output name=paths::$paths"
125+
# Trim leading space
126+
paths="$(echo $paths | sed 's/^ *//')"
127+
echo "paths=$paths" >> $GITHUB_OUTPUT
123128
124129
- name: Upload build artifacts (if any)
125-
uses: actions/upload-artifact@v4
126-
with:
127-
name: build-output
128-
path: ${{ steps.collect.outputs.paths }}
130+
if: ${{ steps.collect.outputs.paths != '' }}
129131
uses: actions/upload-artifact@v4
130132
with:
131133
name: build-output

0 commit comments

Comments
 (0)