|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, master ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout repository |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Set up Node.js |
| 17 | + uses: actions/setup-node@v4 |
| 18 | + with: |
| 19 | + node-version: '18' |
| 20 | + cache: 'npm' |
| 21 | + |
| 22 | + - name: Set up Python |
| 23 | + uses: actions/setup-python@v4 |
| 24 | + with: |
| 25 | + python-version: '3.x' |
| 26 | + |
| 27 | + - name: Set up Go |
| 28 | + uses: actions/setup-go@v4 |
| 29 | + with: |
| 30 | + go-version: '1.20' |
| 31 | + |
| 32 | + - name: Show repo root |
| 33 | + run: | |
| 34 | + echo "Repository root:" |
| 35 | + ls -la |
| 36 | +
|
| 37 | + - name: Install & build (Node.js) |
| 38 | + if: contains(fromJSON('["package.json"]'), 'package.json') || fileExists('package.json') |
| 39 | + run: | |
| 40 | + if [ -f package.json ]; then |
| 41 | + echo "Detected package.json — running Node install/build/test if present" |
| 42 | + npm ci || npm install |
| 43 | + if npm run | sed -n '1,200p' | grep -q "build"; then |
| 44 | + npm run build || true |
| 45 | + fi |
| 46 | + if npm test --silent 2>/dev/null; then |
| 47 | + npm test || true |
| 48 | + fi |
| 49 | + else |
| 50 | + echo "No package.json found" |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Install & build (Python) |
| 54 | + run: | |
| 55 | + if [ -f requirements.txt ] || [ -f pyproject.toml ] || [ -f setup.py ]; then |
| 56 | + echo "Detected Python project" |
| 57 | + python -m pip install --upgrade pip |
| 58 | + if [ -f requirements.txt ]; then |
| 59 | + pip install -r requirements.txt || true |
| 60 | + fi |
| 61 | + if [ -f pyproject.toml ]; then |
| 62 | + pip install build || true |
| 63 | + python -m build || true |
| 64 | + fi |
| 65 | + if [ -f setup.py ]; then |
| 66 | + pip install . || true |
| 67 | + fi |
| 68 | + if [ -d tests ] || ls *_test.py >/dev/null 2>&1; then |
| 69 | + pip install pytest || true |
| 70 | + pytest || true |
| 71 | + fi |
| 72 | + else |
| 73 | + echo "No Python packaging files detected" |
| 74 | + fi |
| 75 | +
|
| 76 | + - name: Install & build (Go) |
| 77 | + run: | |
| 78 | + if ls *.go >/dev/null 2>&1 || [ -d cmd ]; then |
| 79 | + echo "Detected Go project" |
| 80 | + go version |
| 81 | + go env GOPATH GOMODCACHE || true |
| 82 | + go build ./... || true |
| 83 | + go test ./... || true |
| 84 | + else |
| 85 | + echo "No Go files detected" |
| 86 | + fi |
| 87 | +
|
| 88 | + - name: Makefile targets |
| 89 | + if: ${{ always() }} |
| 90 | + run: | |
| 91 | + if [ -f Makefile ]; then |
| 92 | + echo "Makefile found — running build/test if present" |
| 93 | + if grep -qE '^build:' Makefile; then |
| 94 | + make build || true |
| 95 | + fi |
| 96 | + if grep -qE '^test:' Makefile; then |
| 97 | + make test || true |
| 98 | + fi |
| 99 | + else |
| 100 | + echo "No Makefile found" |
| 101 | + fi |
| 102 | +
|
| 103 | + - name: Collect common artifact paths |
| 104 | + id: collect |
| 105 | + run: | |
| 106 | + paths="" |
| 107 | + for p in build dist out; do |
| 108 | + if [ -d "$p" ]; then |
| 109 | + paths="$paths $p" |
| 110 | + fi |
| 111 | + done |
| 112 | + # include common archives |
| 113 | + for a in *.tar.gz *.zip *.exe; do |
| 114 | + if ls $a >/dev/null 2>&1; then |
| 115 | + paths="$paths $a" |
| 116 | + fi |
| 117 | + done |
| 118 | + echo "::set-output name=paths::$paths" |
| 119 | +
|
| 120 | + - name: Upload build artifacts (if any) |
| 121 | + uses: actions/upload-artifact@v4 |
| 122 | + with: |
| 123 | + name: build-output |
| 124 | + path: ${{ steps.collect.outputs.paths }} |
0 commit comments