API CI Pipeline #54
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: API CI Pipeline | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - '*.x' | |
| pull_request: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: '0 0 * * *' | |
| jobs: | |
| lint: | |
| name: "Code Quality & Static Analysis" | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: 'api' | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.2' | |
| extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite | |
| coverage: none | |
| - name: Install Dependencies | |
| run: composer install --prefer-dist --no-progress --no-interaction | |
| - name: Copy .env | |
| run: cp ../.env.example ../.env | |
| - name: Generate Application Key | |
| run: php artisan key:generate | |
| laravel-tests: | |
| name: "Tests (PHP ${{ matrix.php-version }})" | |
| needs: lint | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| php-version: ['8.2', '8.3', '8.4'] | |
| defaults: | |
| run: | |
| working-directory: 'api' | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php-version }} | |
| extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite | |
| coverage: xdebug | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: api/vendor | |
| key: ${{ runner.os }}-php-${{ matrix.php-version }}-composer-${{ hashFiles('api/composer.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-php-${{ matrix.php-version }}-composer- | |
| - name: Create .env | |
| run: | | |
| if [ -z "${{ vars.ENV_FILE }}" ]; then | |
| echo "ENV_FILE secret is not set. Copying .env.example from root..." | |
| # Copies from root to root | |
| cp ../.env.example ../.env | |
| else | |
| echo "Creating .env from secret in root..." | |
| echo "${{ vars.ENV_FILE }}" > ../.env | |
| fi | |
| # Verify file exists in root (for debugging logs) | |
| ls -la ../.env | |
| - name: Install Dependencies | |
| run: composer install --prefer-dist --no-progress --no-interaction | |
| - name: Directory Permissions | |
| run: chmod -R 777 storage bootstrap/cache | |
| - name: Create Database | |
| run: | | |
| mkdir -p database | |
| touch database/database.sqlite | |
| - name: Execute tests (Unit and Feature tests) via Pest/PHPUnit | |
| env: | |
| DB_CONNECTION: sqlite | |
| DB_DATABASE: database/database.sqlite | |
| XDEBUG_MODE: coverage | |
| run: php artisan test --coverage |