ci: add linting and formatting checks to pipeline #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test Suite | |
| on: | |
| push: | |
| branches: [main, testing] | |
| pull_request: | |
| branches: [main, testing] | |
| jobs: | |
| test: | |
| name: Run Tests | |
| runs-on: ubuntu-latest | |
| services: | |
| mysql: | |
| image: mysql:8.0 | |
| env: | |
| MYSQL_ROOT_PASSWORD: testpassword | |
| MYSQL_DATABASE: nt_taxoffice_test | |
| ports: | |
| - 3306:3306 | |
| options: >- | |
| --health-cmd="mysqladmin ping -h localhost" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=5 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Security audit | |
| run: npm audit --audit-level=high | |
| - name: Lint code | |
| run: npm run lint | |
| - name: Check code formatting | |
| run: npm run format:check | |
| - name: Wait for MySQL | |
| run: | | |
| until mysqladmin ping -h 127.0.0.1 -P 3306 -u root -ptestpassword --silent; do | |
| echo 'Waiting for MySQL...' | |
| sleep 2 | |
| done | |
| echo 'MySQL is ready!' | |
| - name: Initialize test database | |
| run: npm run test:db:init | |
| env: | |
| DB_HOST: 127.0.0.1 | |
| DB_PORT: 3306 | |
| DB_USER: root | |
| DB_PASSWORD: testpassword | |
| DB_NAME: nt_taxoffice_test | |
| - name: Run unit tests | |
| run: npm run test:unit | |
| env: | |
| NODE_ENV: test | |
| SESSION_SECRET: test-secret-key-for-ci | |
| GMAIL_USER: test@example.com | |
| GMAIL_APP_PASSWORD: test-password | |
| ADMIN_EMAIL: admin@example.com | |
| DB_HOST: 127.0.0.1 | |
| DB_PORT: 3306 | |
| DB_USER: root | |
| DB_PASSWORD: testpassword | |
| DB_NAME: nt_taxoffice_test | |
| - name: Run integration tests | |
| run: npm run test:integration | |
| env: | |
| NODE_ENV: test | |
| DB_HOST: 127.0.0.1 | |
| DB_PORT: 3306 | |
| DB_USER: root | |
| DB_PASSWORD: testpassword | |
| DB_NAME: nt_taxoffice_test | |
| SESSION_SECRET: test-secret-key-for-ci | |
| GMAIL_USER: test@example.com | |
| GMAIL_APP_PASSWORD: test-password | |
| ADMIN_EMAIL: admin@example.com | |
| - name: Run coverage report | |
| run: npm run test:coverage | |
| env: | |
| NODE_ENV: test | |
| DB_HOST: 127.0.0.1 | |
| DB_PORT: 3306 | |
| DB_USER: root | |
| DB_PASSWORD: testpassword | |
| DB_NAME: nt_taxoffice_test | |
| SESSION_SECRET: test-secret-key-for-ci | |
| GMAIL_USER: test@example.com | |
| GMAIL_APP_PASSWORD: test-password | |
| ADMIN_EMAIL: admin@example.com | |
| - name: Upload coverage to artifacts | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: coverage-report | |
| path: coverage/ | |
| retention-days: 30 |