Skip to content

Commit

Permalink
Merge pull request #151 from coenjacobs/improve-tooling
Browse files Browse the repository at this point in the history
Improve tooling, checks and workflows
  • Loading branch information
coenjacobs authored Sep 9, 2024
2 parents 175fbdc + 31f3c5e commit f5c71c1
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 82 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/docker-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
92 changes: 43 additions & 49 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint, analyse and test
name: Lint, test and analyse

on:
push:
Expand All @@ -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
12 changes: 2 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 16 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true
},
"platform": {
"php": "8.0"
Expand All @@ -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"
]
}
}
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 5 additions & 1 deletion phpcs.xml → phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
<ruleset name="mozart">
<description>Coding standard ruleset based on the PSR-2 coding standard.</description>
<rule ref="PSR2"/>

<rule ref="PHPCompatibility"/>
<config name="testVersion" value="8.0-"/>

<file>./src</file>
</ruleset>
</ruleset>
File renamed without changes.

0 comments on commit f5c71c1

Please sign in to comment.