From cd474119dcbe415f06e4ce0072af42ebe96b8363 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Fri, 29 Dec 2023 19:14:21 +0100 Subject: [PATCH] build: reuse workflows (#1017) --- .github/workflows/build.yml | 168 ++--------------------- .github/workflows/deploy.yml | 3 +- .github/workflows/static.yml | 72 +--------- tests/{.env.ci-mysql => .env.ci.mysql} | 0 tests/{.env.ci-sqlite => .env.ci.sqlite} | 0 5 files changed, 19 insertions(+), 224 deletions(-) rename tests/{.env.ci-mysql => .env.ci.mysql} (100%) rename tests/{.env.ci-sqlite => .env.ci.sqlite} (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d8e4f03b..eb8749d4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,168 +8,26 @@ on: release: types: [created] -env: - default-php-version: '8.1' - coverage-with: 'sqlite' - - jobs: - ############# - # Run tests - ############# tests: - runs-on: ubuntu-latest - name: Tests with PHP ${{ matrix.php-version }} + ${{ matrix.connection }} + uses: monicahq/workflows/.github/workflows/laravel.yml@main + with: + php-version: ${{ matrix.php-version }} + connection: ${{ matrix.connection }} + coverage: ${{ matrix.connection == 'sqlite' && matrix.php-version == '8.2' }} + database_name: version + vite: false strategy: fail-fast: false matrix: - php-version: ['8.1'] + php-version: [8.1, 8.2] connection: [sqlite, mysql] - coverage: [true] - - steps: - - name: Checkout sources - uses: actions/checkout@v3 - - - name: Setup PHP ${{ matrix.php-version }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, dom, fileinfo, ${{ matrix.connection }} - coverage: none - - name: Check PHP Version - run: php -v - - name: Check Composer Version - run: composer -V - - name: Check PHP Extensions - run: php -m - - # Composer - - name: Validate composer.json and composer.lock - run: composer validate - - - name: Get Composer Cache Directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache composer files - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }} - ${{ runner.os }}-composer-${{ matrix.php-version }} - ${{ runner.os }}-composer- - - - name: Install composer dependencies - run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader - - # Prepare - - name: Prepare environment - run: | - cp tests/.env.ci-${{ matrix.connection }} .env - mkdir -p public/js public/css - {\ - echo "{"; \ - for f in app.js app.css app2.js app2.css; do \ - [[ $first == 1 ]] && echo -n "," || first=1; \ - k=${f##*.}/$f; \ - echo "\"/$k\": \"/$k\""; \ - echo '' > public/$k; \ - done; \ - echo "}"; \ - } | tee public/mix-manifest.json - - name: Create sqlite database - if: matrix.connection == 'sqlite' - run: touch database/database.sqlite - - name: Create mysql database - if: matrix.connection == 'mysql' - run: | - sudo systemctl start mysql.service - mysql --protocol=tcp -u root -proot -e "CREATE DATABASE IF NOT EXISTS version CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" - - - name: Generate key - run: php artisan key:generate - - - name: Run migrations - run: php artisan migrate --no-interaction -vvv -# - name: Run seeds -# run: php artisan db:seed --no-interaction -vvv - - name: Cache route - run: php artisan route:cache - # Test - - name: Run tests suite with coverage - if: matrix.connection == env.coverage-with && matrix.php-version == env.default-php-version && matrix.coverage - run: phpdbg -dmemory_limit=4G -qrr vendor/bin/phpunit -c phpunit.xml --log-junit ./results/${{ matrix.connection }}/junit/results.xml --coverage-clover ./results/${{ matrix.connection }}/coverage/coverage.xml - env: - DB_CONNECTION: ${{ matrix.connection }} - - name: Run tests - if: matrix.connection != env.coverage-with || matrix.php-version != env.default-php-version || ! matrix.coverage - run: vendor/bin/phpunit -c phpunit.xml --log-junit ./results/${{ matrix.connection }}/junit/results.xml - env: - DB_CONNECTION: ${{ matrix.connection }} - - - name: Fix results files - run: sed -i -e "s%$GITHUB_WORKSPACE/%%g" **/*.xml - working-directory: results/${{ matrix.connection }} - - - name: Store results - if: matrix.php-version == env.default-php-version - uses: actions/upload-artifact@v3 - with: - name: results - path: results - - - ########################### - # Reporting to sonarcloud - ########################### reporting: + uses: monicahq/workflows/.github/workflows/reporting.yml@main + with: + project: monicahq_marketing_site + secrets: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} needs: tests - runs-on: ubuntu-latest - name: Sonarcloud - if: ${{ ! startsWith(github.ref, 'dependabot/') }} - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - - name: Download results - uses: actions/download-artifact@v3 - with: - name: results - path: results - - - name: Merge junit files - run: | - yarn global add junit-merge - $(yarn global bin)/junit-merge --recursive --dir results/${{ env.coverage-with }}/junit --out results/results.xml - - - name: Set version parameter - id: version - run: | - version=$(git tag --points-at HEAD) - test -z "$version" && version="main" - echo "::set-output name=value::$version" - - - name: Set coverage list - id: coverage - run: | - SONAR_COVERAGE=$(ls -m --format=comma results/${{ env.coverage-with }}/coverage/coverage*.xml | sed -e ':a;N;$!ba;s/\n//g; s/ //g;') - echo "::set-output name=list::$SONAR_COVERAGE" - - - name: SonarCloud Scan - if: env.SONAR_TOKEN != '' - uses: SonarSource/sonarcloud-github-action@v1.6 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - with: - args: | - -Dsonar.projectVersion=${{ steps.version.outputs.value }} - -Dsonar.php.tests.reportPath=./results/results.xml - -Dsonar.php.coverage.reportPaths=${{ steps.coverage.outputs.list }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5c93fd2a..0bd0f431 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -184,7 +184,8 @@ jobs: - name: Deploy run: | git remote add deploy $REPO_URL - git push deploy main:master --force + branch=$(git rev-parse --abbrev-ref HEAD) + git push deploy $branch:master --force env: # This avoids a failure when the client does not know the SSH Host already GIT_SSH_COMMAND: "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index d1e02ac7..dde3538c 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -4,72 +4,8 @@ on: pull_request: types: [opened, synchronize, reopened] -env: - php-version: '8.1' - - jobs: - psalm: - runs-on: ubuntu-latest - - steps: - - name: Checkout sources - uses: actions/checkout@v3 - - - name: Setup PHP ${{ env.php-version }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ env.php-version }} - coverage: none - - - name: Get Composer Cache Directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache composer files - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ env.php-version }}-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer-${{ env.php-version }}-${{ hashFiles('**/composer.lock') }} - ${{ runner.os }}-composer-${{ env.php-version }} - ${{ runner.os }}-composer- - - - name: Install dependencies - run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader - - - name: Run psalm - run: vendor/bin/psalm --output-format=github - - - phpstan: - runs-on: ubuntu-latest - - steps: - - name: Checkout sources - uses: actions/checkout@v3 - - - name: Setup PHP ${{ env.php-version }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ env.php-version }} - coverage: none - - - name: Get Composer Cache Directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache composer files - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ env.php-version }}-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer-${{ env.php-version }}-${{ hashFiles('**/composer.lock') }} - ${{ runner.os }}-composer-${{ env.php-version }} - ${{ runner.os }}-composer- - - - name: Install dependencies - run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader - - - name: Run phpstan - run: vendor/bin/phpstan analyse + statics: + uses: monicahq/workflows/.github/workflows/static.yml@main + with: + php-version: 8.2 diff --git a/tests/.env.ci-mysql b/tests/.env.ci.mysql similarity index 100% rename from tests/.env.ci-mysql rename to tests/.env.ci.mysql diff --git a/tests/.env.ci-sqlite b/tests/.env.ci.sqlite similarity index 100% rename from tests/.env.ci-sqlite rename to tests/.env.ci.sqlite