|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + pull_request: |
| 7 | + branches: [main, master] |
| 8 | + release: |
| 9 | + types: [created] |
| 10 | + |
| 11 | +jobs: |
| 12 | + lint: |
| 13 | + name: Lint |
| 14 | + runs-on: ubuntu-latest |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + service: [server] |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: '3.11' |
| 27 | + cache: 'pip' |
| 28 | + |
| 29 | + - name: Install dependencies |
| 30 | + working-directory: ./services/${{ matrix.service }} |
| 31 | + run: | |
| 32 | + python -m pip install --upgrade pip |
| 33 | + if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi |
| 34 | + if [ -f requirements-server.txt ]; then pip install -r requirements-server.txt; fi |
| 35 | + pip install pre-commit |
| 36 | +
|
| 37 | + - name: Run pre-commit |
| 38 | + working-directory: ./services/${{ matrix.service }} |
| 39 | + run: | |
| 40 | + if [ -f .pre-commit-config.yaml ]; then |
| 41 | + pre-commit run --all-files |
| 42 | + else |
| 43 | + echo "No pre-commit config found, running basic linting" |
| 44 | + chmod +x ../../s/ci/lint.sh ../../s/lib.sh |
| 45 | + cd ../.. |
| 46 | + ./s/ci/lint.sh ${{ matrix.service }} || true |
| 47 | + fi |
| 48 | +
|
| 49 | + detect-changes: |
| 50 | + name: Detect Changed Services |
| 51 | + runs-on: ubuntu-latest |
| 52 | + outputs: |
| 53 | + services: ${{ steps.changes.outputs.services }} |
| 54 | + steps: |
| 55 | + - name: Checkout repository |
| 56 | + uses: actions/checkout@v4 |
| 57 | + with: |
| 58 | + fetch-depth: 0 |
| 59 | + |
| 60 | + - name: Detect changed services |
| 61 | + id: changes |
| 62 | + run: | |
| 63 | + if [ "${{ github.event_name }}" == "pull_request" ]; then |
| 64 | + BASE=${{ github.event.pull_request.base.sha }} |
| 65 | + HEAD=${{ github.sha }} |
| 66 | + else |
| 67 | + BASE=${{ github.event.before }} |
| 68 | + HEAD=${{ github.sha }} |
| 69 | + fi |
| 70 | + |
| 71 | + CHANGED_SERVICES="[]" |
| 72 | + for svc in server bot ai chronos sockets scheduler; do |
| 73 | + if git diff --name-only $BASE $HEAD | grep -q "^services/$svc/"; then |
| 74 | + CHANGED_SERVICES=$(echo $CHANGED_SERVICES | jq -c ". + [\"$svc\"]") |
| 75 | + fi |
| 76 | + done |
| 77 | + |
| 78 | + echo "services=$CHANGED_SERVICES" >> $GITHUB_OUTPUT |
| 79 | + echo "Changed services: $CHANGED_SERVICES" |
| 80 | +
|
| 81 | + build: |
| 82 | + name: Build Docker Images |
| 83 | + needs: detect-changes |
| 84 | + if: needs.detect-changes.outputs.services != '[]' |
| 85 | + runs-on: ubuntu-latest |
| 86 | + strategy: |
| 87 | + fail-fast: false |
| 88 | + matrix: |
| 89 | + service: ${{ fromJson(needs.detect-changes.outputs.services) }} |
| 90 | + steps: |
| 91 | + - name: Checkout repository |
| 92 | + uses: actions/checkout@v4 |
| 93 | + |
| 94 | + - name: Set up Docker Buildx |
| 95 | + uses: docker/setup-buildx-action@v3 |
| 96 | + |
| 97 | + - name: Build Docker image (no push) |
| 98 | + uses: docker/build-push-action@v5 |
| 99 | + with: |
| 100 | + context: ./services/${{ matrix.service }} |
| 101 | + push: false |
| 102 | + tags: swecc-${{ matrix.service }}:test |
| 103 | + cache-from: type=gha |
| 104 | + cache-to: type=gha,mode=max |
| 105 | + |
0 commit comments