| 1 | name: AitoEarn Backend Check |
| 2 | |
| 3 | on: |
| 4 | pull_request: |
| 5 | types: [opened, synchronize, reopened] |
| 6 | |
| 7 | permissions: |
| 8 | contents: read |
| 9 | pull-requests: read |
| 10 | |
| 11 | env: |
| 12 | NX_NO_CLOUD: true |
| 13 | MONOREPO_DIR: project/aitoearn-backend |
| 14 | |
| 15 | concurrency: |
| 16 | group: ${{ github.workflow }}-${{ github.ref }} |
| 17 | cancel-in-progress: true |
| 18 | |
| 19 | jobs: |
| 20 | lint-and-build: |
| 21 | name: Lint & Build |
| 22 | runs-on: ubuntu-latest |
| 23 | |
| 24 | steps: |
| 25 | - name: Checkout |
| 26 | uses: actions/checkout@v4 |
| 27 | with: |
| 28 | fetch-depth: 0 |
| 29 | |
| 30 | - name: Check if backend files changed |
| 31 | id: check-changes |
| 32 | run: | |
| 33 | if git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -q "^project/aitoearn-backend/"; then |
| 34 | echo "changed=true" >> $GITHUB_OUTPUT |
| 35 | else |
| 36 | echo "changed=false" >> $GITHUB_OUTPUT |
| 37 | fi |
| 38 | |
| 39 | - name: Skip if no changes |
| 40 | if: steps.check-changes.outputs.changed == 'false' |
| 41 | run: | |
| 42 | echo "No changes in project/aitoearn-backend/, skipping checks" |
| 43 | exit 0 |
| 44 | |
| 45 | - name: Install pnpm |
| 46 | if: steps.check-changes.outputs.changed == 'true' |
| 47 | uses: pnpm/action-setup@v4 |
| 48 | with: |
| 49 | version: 10 |
| 50 | |
| 51 | - name: Setup Node.js |
| 52 | if: steps.check-changes.outputs.changed == 'true' |
| 53 | uses: actions/setup-node@v4 |
| 54 | with: |
| 55 | node-version: 22 |
| 56 | cache: pnpm |
| 57 | cache-dependency-path: ${{ env.MONOREPO_DIR }}/pnpm-lock.yaml |
| 58 | |
| 59 | - name: Install dependencies |
| 60 | if: steps.check-changes.outputs.changed == 'true' |
| 61 | working-directory: ${{ env.MONOREPO_DIR }} |
| 62 | run: pnpm install --frozen-lockfile |
| 63 | |
| 64 | - name: Run ESLint |
| 65 | if: steps.check-changes.outputs.changed == 'true' |
| 66 | working-directory: ${{ env.MONOREPO_DIR }} |
| 67 | run: pnpm nx run-many --target=lint --no-fix --nxBail --outputStyle=static |
| 68 | |
| 69 | - name: Run build |
| 70 | if: steps.check-changes.outputs.changed == 'true' |
| 71 | working-directory: ${{ env.MONOREPO_DIR }} |
| 72 | run: pnpm nx run-many --target=build --nxBail --outputStyle=static |
| 73 | |
| 74 |