Skip to content

Commit f5c71c1

Browse files
authored
Merge pull request #151 from coenjacobs/improve-tooling
Improve tooling, checks and workflows
2 parents 175fbdc + 31f3c5e commit f5c71c1

File tree

8 files changed

+80
-82
lines changed

8 files changed

+80
-82
lines changed

.github/workflows/docker-latest.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ jobs:
2323
id: buildx
2424
uses: docker/setup-buildx-action@v1
2525

26-
- name: Cache Docker layers
27-
uses: actions/cache@v2
28-
with:
29-
path: /tmp/.buildx-cache
30-
key: ${{ runner.os }}-buildx-${{ github.sha }}
31-
restore-keys: |
32-
${{ runner.os }}-buildx-
33-
3426
- name: Login to DockerHub
3527
uses: docker/login-action@v1
3628
with:
@@ -48,5 +40,5 @@ jobs:
4840
platforms: linux/amd64
4941
push: ${{ github.event_name != 'pull_request' }}
5042
tags: ${{ steps.prep.outputs.tags }}
51-
cache-from: type=local,src=/tmp/.buildx-cache
52-
cache-to: type=local,dest=/tmp/.buildx-cache
43+
cache-from: type=gha
44+
cache-to: type=gha,mode=max

.github/workflows/main.yml

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Lint, analyse and test
1+
name: Lint, test and analyse
22

33
on:
44
push:
@@ -9,60 +9,54 @@ on:
99
- master
1010

1111
jobs:
12-
tests:
12+
linting:
1313
runs-on: ubuntu-latest
14-
strategy:
15-
matrix:
16-
php: ['8.0', '8.1', '8.2', '8.3']
17-
name: PHP ${{ matrix.php }} tests
14+
name: Linting
1815
steps:
19-
- uses: actions/checkout@v3
20-
- name: Install PHP
21-
uses: shivammathur/setup-php@v2
16+
- name: Setup Docker buildx
17+
uses: docker/setup-buildx-action@v2
18+
- uses: actions/checkout@v4
19+
- name: Build Docker image
20+
id: build-and-push
21+
uses: docker/build-push-action@v4
2222
with:
23-
php-version: ${{ matrix.php }}
24-
- name: Debugging
25-
run: |
26-
php --version
27-
php -m
28-
composer --version
29-
- name: Install dependencies
30-
run: composer install --prefer-dist --no-suggest --no-progress
31-
- name: Run tests
32-
run: vendor/bin/phpunit --printer mheap\\GithubActionsReporter\\Printer
33-
analysis:
23+
context: "{{defaultContext}}"
24+
push: false
25+
cache-from: type=gha
26+
cache-to: type=gha,mode=max
27+
- name: Run linting
28+
run: docker compose run --rm actions-tester composer test:lint
29+
testing:
3430
runs-on: ubuntu-latest
35-
name: Analysis of code
31+
name: Testing
3632
steps:
37-
- uses: actions/checkout@v3
38-
- name: Install PHP
39-
uses: shivammathur/setup-php@v2
33+
- name: Setup Docker buildx
34+
uses: docker/setup-buildx-action@v2
35+
- uses: actions/checkout@v4
36+
- name: Build Docker image
37+
id: build-and-push
38+
uses: docker/build-push-action@v4
4039
with:
41-
php-version: '8.1'
42-
- name: Debugging
43-
run: |
44-
php --version
45-
php -m
46-
composer --version
47-
- name: Install dependencies
48-
run: composer install --prefer-dist --no-suggest --no-progress
49-
- name: Run validate
50-
run: composer run analysis
51-
lint:
40+
context: "{{defaultContext}}"
41+
push: false
42+
cache-from: type=gha
43+
cache-to: type=gha,mode=max
44+
- name: Run testing
45+
run: docker compose run --rm actions-tester composer test:phpunit
46+
analysis:
5247
runs-on: ubuntu-latest
53-
name: Lint all project files
48+
name: Analysis
5449
steps:
55-
- uses: actions/checkout@v3
56-
- name: Install PHP
57-
uses: shivammathur/setup-php@v2
50+
- name: Setup Docker buildx
51+
uses: docker/setup-buildx-action@v2
52+
- uses: actions/checkout@v4
53+
- name: Build Docker image
54+
id: build-and-push
55+
uses: docker/build-push-action@v4
5856
with:
59-
php-version: '8.0'
60-
- name: Debugging
61-
run: |
62-
php --version
63-
php -m
64-
composer --version
65-
- name: Install dependencies
66-
run: composer install --prefer-dist --no-suggest --no-progress
67-
- name: Run validate
68-
run: composer run lint
57+
context: "{{defaultContext}}"
58+
push: false
59+
cache-from: type=gha
60+
cache-to: type=gha,mode=max
61+
- name: Run analysis
62+
run: docker compose run --rm actions-tester composer test:phpstan

.github/workflows/release.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ jobs:
6262
id: buildx
6363
uses: docker/setup-buildx-action@v1
6464

65-
- name: Cache Docker layers
66-
uses: actions/cache@v2
67-
with:
68-
path: /tmp/.buildx-cache
69-
key: ${{ runner.os }}-buildx-${{ github.sha }}
70-
restore-keys: |
71-
${{ runner.os }}-buildx-
72-
7365
- name: Login to DockerHub
7466
uses: docker/login-action@v1
7567
with:
@@ -87,8 +79,8 @@ jobs:
8779
platforms: linux/amd64
8880
push: ${{ github.event_name != 'pull_request' }}
8981
tags: ${{ steps.prep.outputs.tags }}
90-
cache-from: type=local,src=/tmp/.buildx-cache
91-
cache-to: type=local,dest=/tmp/.buildx-cache
82+
cache-from: type=gha
83+
cache-to: type=gha,mode=max
9284

9385
- name: Image digest
9486
run: echo ${{ steps.docker_build.outputs.digest }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM php:8.3.9-cli-alpine AS base
44
FROM base as builder
55
RUN apk update && apk add git
66
COPY --from=composer /usr/bin/composer /usr/bin/composer
7-
COPY ./composer.json /mozart/
7+
COPY ./ /mozart/
88
WORKDIR /mozart/
99
RUN composer install
1010

composer.json

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
},
2222
"config": {
2323
"allow-plugins": {
24-
"phpstan/extension-installer": true
24+
"phpstan/extension-installer": true,
25+
"dealerdirect/phpcodesniffer-composer-installer": true
2526
},
2627
"platform": {
2728
"php": "8.0"
@@ -36,21 +37,25 @@
3637
"phpstan/extension-installer": "^1.4",
3738
"league/flysystem": "^2.5",
3839
"symfony/console": "^5.4",
39-
"symfony/finder": "^5.4"
40+
"symfony/finder": "^5.4",
41+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
42+
"phpcompatibility/php-compatibility": "dev-develop"
4043
},
4144
"scripts": {
42-
"lint": [
43-
"composer validate",
44-
"phpcs"
45+
"test": [
46+
"@test:lint",
47+
"@test:phpunit",
48+
"@test:phpstan"
4549
],
46-
"analysis": [
47-
"@analysis:phpstan"
50+
"test:lint": [
51+
"composer validate",
52+
"./vendor/bin/phpcs --standard=phpcs.xml.dist"
4853
],
49-
"analysis:phpstan": [
50-
"./vendor/bin/phpstan --memory-limit=2G"
54+
"test:phpunit": [
55+
"./vendor/bin/phpunit -c phpunit.xml.dist"
5156
],
52-
"test": [
53-
"phpunit"
57+
"test:phpstan": [
58+
"./vendor/bin/phpstan analyse -c phpstan.neon.dist --memory-limit=2G"
5459
]
5560
}
5661
}

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ services:
88
volumes:
99
- .:/mozart/
1010
command: /bin/sh -c "while sleep 1000; do :; done"
11+
actions-tester:
12+
# This service is technically the same as the builder service, only this one
13+
# has no volume mounted to the working directory. This causes the files to
14+
# be used (for example installed dependencies) that are created _inside_ the
15+
# container to be used, rather than having to set them up in the working
16+
# directory, during GitHub Actions for example.
17+
build:
18+
context: .
19+
dockerfile: Dockerfile
20+
target: builder
21+
command: /bin/sh -c "while sleep 1000; do :; done"

phpcs.xml renamed to phpcs.xml.dist

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
<ruleset name="mozart">
44
<description>Coding standard ruleset based on the PSR-2 coding standard.</description>
55
<rule ref="PSR2"/>
6+
7+
<rule ref="PHPCompatibility"/>
8+
<config name="testVersion" value="8.0-"/>
9+
610
<file>./src</file>
7-
</ruleset>
11+
</ruleset>
File renamed without changes.

0 commit comments

Comments
 (0)