|
7 | 7 | REGISTRY: ghcr.io |
8 | 8 | IMAGE_NAME: ${{ github.repository }} |
9 | 9 | jobs: |
| 10 | + laravel-tests: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: shivammathur/setup-php@v2 |
| 14 | + with: |
| 15 | + php-version: "8.3" |
| 16 | + - uses: actions/checkout@main |
| 17 | + - name: Copy config |
| 18 | + env: |
| 19 | + COMPOSER_TOKEN: ${{ secrets.ACCESS_TOKEN_GITHUB }} |
| 20 | + GITHUB_ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN_GITHUB }} |
| 21 | + run: | |
| 22 | + php -r "copy('.env.testing', '.env');" |
| 23 | + sed -i 's/testdb.docker.dev/127.0.0.1/' .env.testing |
| 24 | + echo '{ "github-oauth": { "github.com": "'$GITHUB_ACCESS_TOKEN'"} }' > /home/$(whoami)/.composer/auth.json |
| 25 | + - name: Start MariaDB |
| 26 | + uses: getong/mariadb-action@v1.1 |
| 27 | + with: |
| 28 | + # MYSQL_DATABASE - name for the default database that is created |
| 29 | + mysql database: testing |
| 30 | + # MYSQL_USER - create the specified user with superuser power for created database |
| 31 | + mysql user: testing |
| 32 | + # MYSQL_PASSWORD - specified superuser password which user is power for created database |
| 33 | + mysql password: secret |
| 34 | + |
| 35 | + - name: Install Dependencies |
| 36 | + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist |
| 37 | + - name: Setup npm |
| 38 | + uses: actions/setup-node@v6 |
| 39 | + with: |
| 40 | + node-version: 18 |
| 41 | + - name: Install NPM dependencies |
| 42 | + run: npm install |
| 43 | + env: |
| 44 | + GITHUB_ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN_GITHUB }} |
| 45 | + - name: Compile assets |
| 46 | + run: npm run production |
| 47 | + env: |
| 48 | + GITHUB_ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN_GITHUB }} |
| 49 | + - name: Generate key |
| 50 | + run: php artisan key:generate |
| 51 | + - name: Directory Permissions |
| 52 | + run: chmod -R 777 storage bootstrap/cache |
| 53 | + - name: Migrate |
| 54 | + run: | |
| 55 | + php artisan config:clear |
| 56 | + php artisan migrate --env=testing |
| 57 | + - name: Execute tests defined in CI (Unit and Feature tests) via Pest tests |
| 58 | + run: | |
| 59 | + pwd |
| 60 | + ls -la |
| 61 | + vendor/bin/pest --no-coverage |
| 62 | + - name: Archive Test Results |
| 63 | + uses: actions/upload-artifact@v5 |
| 64 | + if: ${{ always() }} |
| 65 | + with: |
| 66 | + name: test-results |
| 67 | + path: | |
| 68 | + tests/_output/debug/ |
| 69 | + storage/logs/ |
| 70 | + changedfiles: |
| 71 | + runs-on: ubuntu-latest |
| 72 | + # Map a step output to a job output |
| 73 | + outputs: |
| 74 | + ts: ${{ steps.changes.outputs.ts }} |
| 75 | + steps: |
| 76 | + # Make sure we have some code to diff. |
| 77 | + - name: Checkout repository |
| 78 | + uses: actions/checkout@main |
| 79 | + with: |
| 80 | + fetch-depth: 0 |
| 81 | + |
| 82 | + - name: Get changed files |
| 83 | + id: changes |
| 84 | + # Set outputs using the command. |
| 85 | + run: echo "ts=$(git diff --name-only origin/develop..${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT |
| 86 | + |
| 87 | + phpcsmd: |
| 88 | + runs-on: ubuntu-latest |
| 89 | + # require the first job to have run |
| 90 | + needs: changedfiles |
| 91 | + # only run there are changed files |
| 92 | + if: ${{needs.changedfiles.outputs.ts}} |
| 93 | + steps: |
| 94 | + - name: Checkout repository |
| 95 | + uses: actions/checkout@main |
| 96 | + - name: Show changed files |
| 97 | + run: echo ${{needs.changedfiles.outputs.ts}} |
| 98 | + |
| 99 | + - name: Setup PHP |
| 100 | + uses: shivammathur/setup-php@v2 |
| 101 | + with: |
| 102 | + php-version: "8.3" |
| 103 | + extensions: ssh2 |
| 104 | + coverage: none |
| 105 | + tools: composer, cs2pr, phpcs |
| 106 | + |
| 107 | + - name: Install dependencies |
| 108 | + env: |
| 109 | + COMPOSER_TOKEN: ${{ secrets.ACCESS_TOKEN_GITHUB }} |
| 110 | + GITHUB_ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN_GITHUB }} |
| 111 | + # install composer packages |
| 112 | + run: | |
| 113 | + echo '{"github-oauth": { "github.com": "'$GITHUB_ACCESS_TOKEN'"}}' > /home/$(whoami)/.composer/auth.json |
| 114 | + composer install --prefer-dist --no-progress |
| 115 | +
|
| 116 | + - name: Check PHP code style |
| 117 | + # run PHP Code Sniffer |
| 118 | + run: vendor/bin/phpcs ${{needs.changedfiles.outputs.ts}} --report-full |
| 119 | + |
| 120 | + - name: Run PHP Mess Detector |
| 121 | + # run PHP Mess Detector |
| 122 | + run: FILES="${{needs.changedfiles.outputs.ts}}" && vendor/bin/phpmd ${FILES// /,} text phpmd.xml --exclude vendor/,tests/ |
| 123 | + phpstan: |
| 124 | + name: phpstan |
| 125 | + runs-on: ubuntu-latest |
| 126 | + steps: |
| 127 | + - uses: actions/checkout@v5 |
| 128 | + |
| 129 | + - name: Setup PHP |
| 130 | + uses: shivammathur/setup-php@v2 |
| 131 | + with: |
| 132 | + php-version: '8.3' |
| 133 | + coverage: none |
| 134 | + |
| 135 | + - name: Install composer dependencies |
| 136 | + run: composer install -n --prefer-dist |
| 137 | + |
| 138 | + - name: Run Static Analysis |
| 139 | + run: ./vendor/bin/phpstan --error-format=github |
10 | 140 | build: |
| 141 | + needs: [ laravel-tests, phpcsmd, phpstan ] |
| 142 | + ## if one of the above jobs does not run, this job should start. |
| 143 | + ## This job runs when upstream jobs are either successful or skipped, but not if any have failed. |
| 144 | + if: ${{ always() && !contains(needs.*.result, 'failure') }} |
11 | 145 | runs-on: ubuntu-latest |
12 | 146 | # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
13 | 147 | permissions: |
|
0 commit comments