-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-actions-laravel.yml
More file actions
183 lines (155 loc) · 4.94 KB
/
Copy pathgithub-actions-laravel.yml
File metadata and controls
183 lines (155 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Laravel CI with Cbox
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
env:
PHP_VERSION: "8.4"
jobs:
tests:
name: Tests (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4']
services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: laravel_test
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd="redis-cli ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build Cbox CI image
run: |
docker build -f templates/Dockerfile.ci \
--build-arg PHP_VERSION=${{ matrix.php }} \
-t cbox-ci:${{ matrix.php }} .
- name: Create vendor cache directory
run: mkdir -p vendor
- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php }}-composer-
- name: Install Composer dependencies
run: |
docker run --rm -v $(pwd):/var/www/html \
cbox-ci:${{ matrix.php }} \
composer install --prefer-dist --no-interaction --no-progress
- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install npm dependencies
run: |
docker run --rm -v $(pwd):/var/www/html \
cbox-ci:${{ matrix.php }} \
npm ci
- name: Build frontend assets
run: |
docker run --rm -v $(pwd):/var/www/html \
cbox-ci:${{ matrix.php }} \
npm run build
- name: Prepare Laravel
run: |
docker run --rm -v $(pwd):/var/www/html \
-e APP_ENV=testing \
-e APP_KEY=base64:${{ secrets.APP_KEY }} \
cbox-ci:${{ matrix.php }} \
sh -c "
cp .env.example .env &&
php artisan key:generate &&
php artisan config:cache
"
- name: Run PHPStan
run: |
docker run --rm -v $(pwd):/var/www/html \
cbox-ci:${{ matrix.php }} \
vendor/bin/phpstan analyse --memory-limit=1G
- name: Run PHP CS Fixer (dry-run)
run: |
docker run --rm -v $(pwd):/var/www/html \
cbox-ci:${{ matrix.php }} \
vendor/bin/php-cs-fixer fix --dry-run --diff
- name: Run Tests
run: |
docker run --rm -v $(pwd):/var/www/html \
--network host \
-e APP_ENV=testing \
-e DB_CONNECTION=mysql \
-e DB_HOST=127.0.0.1 \
-e DB_PORT=3306 \
-e DB_DATABASE=laravel_test \
-e DB_USERNAME=root \
-e DB_PASSWORD=root \
-e REDIS_HOST=127.0.0.1 \
cbox-ci:${{ matrix.php }} \
php artisan test --parallel --coverage
- name: Upload coverage to Codecov
if: matrix.php == '8.5'
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
code-quality:
name: Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Psalm
run: |
docker run --rm -v $(pwd):/var/www/html \
ghcr.io/cboxdk/php-baseimages/php-fpm-nginx:8.5-bookworm \
vendor/bin/psalm --show-info=true
deploy:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [tests, code-quality]
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build production image
run: |
docker build \
--tag ghcr.io/${{ github.repository }}:latest \
--tag ghcr.io/${{ github.repository }}:${{ github.sha }} \
.
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push images
run: |
docker push ghcr.io/${{ github.repository }}:latest
docker push ghcr.io/${{ github.repository }}:${{ github.sha }}
# Add your deployment steps here (SSH, kubectl, etc.)