diff --git a/.github/workflows/docker-latest.yml b/.github/workflows/docker-latest.yml index f0e5b779..3d6f39f3 100644 --- a/.github/workflows/docker-latest.yml +++ b/.github/workflows/docker-latest.yml @@ -23,14 +23,6 @@ jobs: id: buildx uses: docker/setup-buildx-action@v1 - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - name: Login to DockerHub uses: docker/login-action@v1 with: @@ -48,5 +40,5 @@ jobs: platforms: linux/amd64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.prep.outputs.tags }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 12da66ab..f5583e8a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Lint, analyse and test +name: Lint, test and analyse on: push: @@ -9,60 +9,54 @@ on: - master jobs: - tests: + linting: runs-on: ubuntu-latest - strategy: - matrix: - php: ['8.0', '8.1', '8.2', '8.3'] - name: PHP ${{ matrix.php }} tests + name: Linting steps: - - uses: actions/checkout@v3 - - name: Install PHP - uses: shivammathur/setup-php@v2 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v2 + - uses: actions/checkout@v4 + - name: Build Docker image + id: build-and-push + uses: docker/build-push-action@v4 with: - php-version: ${{ matrix.php }} - - name: Debugging - run: | - php --version - php -m - composer --version - - name: Install dependencies - run: composer install --prefer-dist --no-suggest --no-progress - - name: Run tests - run: vendor/bin/phpunit --printer mheap\\GithubActionsReporter\\Printer - analysis: + context: "{{defaultContext}}" + push: false + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Run linting + run: docker compose run --rm actions-tester composer test:lint + testing: runs-on: ubuntu-latest - name: Analysis of code + name: Testing steps: - - uses: actions/checkout@v3 - - name: Install PHP - uses: shivammathur/setup-php@v2 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v2 + - uses: actions/checkout@v4 + - name: Build Docker image + id: build-and-push + uses: docker/build-push-action@v4 with: - php-version: '8.1' - - name: Debugging - run: | - php --version - php -m - composer --version - - name: Install dependencies - run: composer install --prefer-dist --no-suggest --no-progress - - name: Run validate - run: composer run analysis - lint: + context: "{{defaultContext}}" + push: false + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Run testing + run: docker compose run --rm actions-tester composer test:phpunit + analysis: runs-on: ubuntu-latest - name: Lint all project files + name: Analysis steps: - - uses: actions/checkout@v3 - - name: Install PHP - uses: shivammathur/setup-php@v2 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v2 + - uses: actions/checkout@v4 + - name: Build Docker image + id: build-and-push + uses: docker/build-push-action@v4 with: - php-version: '8.0' - - name: Debugging - run: | - php --version - php -m - composer --version - - name: Install dependencies - run: composer install --prefer-dist --no-suggest --no-progress - - name: Run validate - run: composer run lint + context: "{{defaultContext}}" + push: false + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Run analysis + run: docker compose run --rm actions-tester composer test:phpstan diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dedc4f4a..aaa5cdc7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,14 +62,6 @@ jobs: id: buildx uses: docker/setup-buildx-action@v1 - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - name: Login to DockerHub uses: docker/login-action@v1 with: @@ -87,8 +79,8 @@ jobs: platforms: linux/amd64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.prep.outputs.tags }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + cache-from: type=gha + cache-to: type=gha,mode=max - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/Dockerfile b/Dockerfile index c9073b9d..1d8651f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ FROM php:8.3.9-cli-alpine AS base FROM base as builder RUN apk update && apk add git COPY --from=composer /usr/bin/composer /usr/bin/composer -COPY ./composer.json /mozart/ +COPY ./ /mozart/ WORKDIR /mozart/ RUN composer install diff --git a/composer.json b/composer.json index 4f37687f..eda74610 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ }, "config": { "allow-plugins": { - "phpstan/extension-installer": true + "phpstan/extension-installer": true, + "dealerdirect/phpcodesniffer-composer-installer": true }, "platform": { "php": "8.0" @@ -36,21 +37,25 @@ "phpstan/extension-installer": "^1.4", "league/flysystem": "^2.5", "symfony/console": "^5.4", - "symfony/finder": "^5.4" + "symfony/finder": "^5.4", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "phpcompatibility/php-compatibility": "dev-develop" }, "scripts": { - "lint": [ - "composer validate", - "phpcs" + "test": [ + "@test:lint", + "@test:phpunit", + "@test:phpstan" ], - "analysis": [ - "@analysis:phpstan" + "test:lint": [ + "composer validate", + "./vendor/bin/phpcs --standard=phpcs.xml.dist" ], - "analysis:phpstan": [ - "./vendor/bin/phpstan --memory-limit=2G" + "test:phpunit": [ + "./vendor/bin/phpunit -c phpunit.xml.dist" ], - "test": [ - "phpunit" + "test:phpstan": [ + "./vendor/bin/phpstan analyse -c phpstan.neon.dist --memory-limit=2G" ] } } diff --git a/docker-compose.yml b/docker-compose.yml index 1def9525..8835bc8f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,3 +8,14 @@ services: volumes: - .:/mozart/ command: /bin/sh -c "while sleep 1000; do :; done" + actions-tester: + # This service is technically the same as the builder service, only this one + # has no volume mounted to the working directory. This causes the files to + # be used (for example installed dependencies) that are created _inside_ the + # container to be used, rather than having to set them up in the working + # directory, during GitHub Actions for example. + build: + context: . + dockerfile: Dockerfile + target: builder + command: /bin/sh -c "while sleep 1000; do :; done" diff --git a/phpcs.xml b/phpcs.xml.dist similarity index 69% rename from phpcs.xml rename to phpcs.xml.dist index 2bf4e6c4..27d5af45 100644 --- a/phpcs.xml +++ b/phpcs.xml.dist @@ -3,5 +3,9 @@ Coding standard ruleset based on the PSR-2 coding standard. + + + + ./src - \ No newline at end of file + diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 100% rename from phpunit.xml rename to phpunit.xml.dist