|
| 1 | +name: Baseline CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + secret-scan: |
| 13 | + name: Secret Scan |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Gitleaks |
| 22 | + uses: gitleaks/gitleaks-action@v2 |
| 23 | + env: |
| 24 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + |
| 26 | + quality: |
| 27 | + name: Lint / Build / Test |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Setup Node |
| 34 | + if: ${{ hashFiles('**/package.json') != '' }} |
| 35 | + uses: actions/setup-node@v4 |
| 36 | + with: |
| 37 | + node-version: '20' |
| 38 | + |
| 39 | + - name: Setup Python |
| 40 | + if: ${{ hashFiles('**/requirements.txt', '**/pyproject.toml') != '' }} |
| 41 | + uses: actions/setup-python@v5 |
| 42 | + with: |
| 43 | + python-version: '3.11' |
| 44 | + |
| 45 | + - name: Setup Java |
| 46 | + if: ${{ hashFiles('**/pom.xml', '**/build.gradle', '**/build.gradle.kts') != '' }} |
| 47 | + uses: actions/setup-java@v4 |
| 48 | + with: |
| 49 | + distribution: temurin |
| 50 | + java-version: '17' |
| 51 | + |
| 52 | + - name: Setup Go |
| 53 | + if: ${{ hashFiles('**/go.mod') != '' }} |
| 54 | + uses: actions/setup-go@v5 |
| 55 | + with: |
| 56 | + go-version: '1.22' |
| 57 | + |
| 58 | + - name: Lint |
| 59 | + shell: bash |
| 60 | + run: | |
| 61 | + set -euo pipefail |
| 62 | + ran=0 |
| 63 | +
|
| 64 | + if [ -f package.json ]; then |
| 65 | + npm ci || npm install |
| 66 | + npm run lint --if-present |
| 67 | + ran=1 |
| 68 | + fi |
| 69 | +
|
| 70 | + if [ -f requirements.txt ] || [ -f pyproject.toml ]; then |
| 71 | + python -m pip install --upgrade pip |
| 72 | + python -m pip install ruff || true |
| 73 | + if command -v ruff >/dev/null 2>&1; then |
| 74 | + ruff check . || true |
| 75 | + fi |
| 76 | + ran=1 |
| 77 | + fi |
| 78 | +
|
| 79 | + if [ -f go.mod ]; then |
| 80 | + gofmt -l . | tee /tmp/gofmt.out |
| 81 | + if [ -s /tmp/gofmt.out ]; then |
| 82 | + echo 'gofmt reported unformatted files' |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | + ran=1 |
| 86 | + fi |
| 87 | +
|
| 88 | + if [ -f pom.xml ]; then |
| 89 | + if [ -f mvnw ]; then chmod +x mvnw; ./mvnw -B -ntp -DskipTests validate; else mvn -B -ntp -DskipTests validate; fi |
| 90 | + ran=1 |
| 91 | + fi |
| 92 | +
|
| 93 | + if [ "$ran" -eq 0 ]; then |
| 94 | + echo 'No lint target detected, skip.' |
| 95 | + fi |
| 96 | +
|
| 97 | + - name: Build |
| 98 | + shell: bash |
| 99 | + run: | |
| 100 | + set -euo pipefail |
| 101 | + ran=0 |
| 102 | +
|
| 103 | + if [ -f package.json ]; then |
| 104 | + npm run build --if-present |
| 105 | + ran=1 |
| 106 | + fi |
| 107 | +
|
| 108 | + if [ -f requirements.txt ] || [ -f pyproject.toml ]; then |
| 109 | + python -m compileall -q . |
| 110 | + ran=1 |
| 111 | + fi |
| 112 | +
|
| 113 | + if [ -f go.mod ]; then |
| 114 | + go build ./... |
| 115 | + ran=1 |
| 116 | + fi |
| 117 | +
|
| 118 | + if [ -f pom.xml ]; then |
| 119 | + if [ -f mvnw ]; then chmod +x mvnw; ./mvnw -B -ntp -DskipTests package; else mvn -B -ntp -DskipTests package; fi |
| 120 | + ran=1 |
| 121 | + fi |
| 122 | +
|
| 123 | + if [ "$ran" -eq 0 ]; then |
| 124 | + echo 'No build target detected, skip.' |
| 125 | + fi |
| 126 | +
|
| 127 | + - name: Test |
| 128 | + shell: bash |
| 129 | + run: | |
| 130 | + set -euo pipefail |
| 131 | + ran=0 |
| 132 | +
|
| 133 | + if [ -f package.json ]; then |
| 134 | + npm test --if-present |
| 135 | + ran=1 |
| 136 | + fi |
| 137 | +
|
| 138 | + if [ -f requirements.txt ] || [ -f pyproject.toml ]; then |
| 139 | + python -m pip install pytest || true |
| 140 | + if [ -d tests ] || [ -d test ]; then |
| 141 | + pytest -q || true |
| 142 | + else |
| 143 | + python -m unittest discover -v || true |
| 144 | + fi |
| 145 | + ran=1 |
| 146 | + fi |
| 147 | +
|
| 148 | + if [ -f go.mod ]; then |
| 149 | + go test ./... |
| 150 | + ran=1 |
| 151 | + fi |
| 152 | +
|
| 153 | + if [ -f pom.xml ]; then |
| 154 | + if [ -f mvnw ]; then chmod +x mvnw; ./mvnw -B -ntp test; else mvn -B -ntp test; fi |
| 155 | + ran=1 |
| 156 | + fi |
| 157 | +
|
| 158 | + if [ "$ran" -eq 0 ]; then |
| 159 | + echo 'No test target detected, skip.' |
| 160 | + fi |
0 commit comments