-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (189 loc) · 7 KB
/
ci.yml
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: Continuous Integration
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
workflow_dispatch:
inputs:
coverage:
description: "Run with coverage tests"
required: false
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
PHP_VERSION: 8.3
PHP_EXTENSIONS: mbstring,pdo,xml,ctype,fileinfo,json,curl,openssl,dom,zip
PHP_INI_PROPERTIES: post_max_size=256M,upload_max_filesize=256M
jobs:
setup:
name: Setup PHP
runs-on: ubuntu-24.04
outputs:
combined-key: ${{ steps.prepare-env.outputs.combined-key }}
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Prepare environment and composer data
id: prepare-env
run: |
composer_dir=$(composer config cache-files-dir)
composer_hash=${{ hashFiles('**/composer.lock') }}
os_lower=$(echo ${{ runner.os }} | tr '[:upper:]' '[:lower:]')
arch_lower=$(echo ${{ runner.arch }} | tr '[:upper:]' '[:lower:]')
combined_key="${os_lower}-${arch_lower}-composer-${composer_hash}"
echo "combined-key=${combined_key}" >> "$GITHUB_OUTPUT"
- name: Setup PHP
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
with:
php-version: ${{ env.PHP_VERSION }}
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: ${{ env.PHP_INI_PROPERTIES }}
- name: Install composer dependencies
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0
with:
composer-options: "--optimize-autoloader --prefer-dist"
custom-cache-key: ${{ steps.prepare-env.outputs.combined-key }}
format:
name: Perform Pint format
runs-on: ubuntu-24.04
needs: setup
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup PHP
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
with:
php-version: ${{ env.PHP_VERSION }}
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: ${{ env.PHP_INI_PROPERTIES }}
- name: Install composer dependencies
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0
with:
composer-options: "--optimize-autoloader --prefer-dist"
custom-cache-key: ${{ needs.setup.outputs.combined-key }}
- name: Run Pint
run: ./vendor/bin/pint --no-interaction --test --preset=laravel
tests:
name: Run tests
runs-on: ubuntu-24.04
needs: setup
env:
BROADCAST_DRIVER: log
CACHE_DRIVER: redis
QUEUE_CONNECTION: redis
SESSION_DRIVER: redis
DB_CONNECTION: pgsql
DB_HOST: localhost
DB_PASSWORD: postgres
DB_USERNAME: postgres
DB_DATABASE: postgres
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: app
ports:
- 5432/tcp
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis
ports:
- 6379/tcp
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup PHP
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
with:
php-version: ${{ env.PHP_VERSION }}
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: ${{ env.PHP_INI_PROPERTIES }}
coverage: "xdebug"
- name: Install composer dependencies
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0
with:
composer-options: "--optimize-autoloader --prefer-dist"
custom-cache-key: ${{ needs.setup.outputs.combined-key }}
- name: Prepare the application
run: |
php -r "file_exists('.env') || copy('.env.example', '.env');"
php artisan config:clear
php artisan key:generate
- name: Run Migration
run: php artisan migrate --seed -v
env:
DB_PORT: ${{ job.services.postgres.ports['5432'] }}
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
- name: Run tests
run: php artisan test
env:
DB_PORT: ${{ job.services.postgres.ports['5432'] }}
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
- name: Run coverage tests
if: github.event_name == 'workflow_dispatch' && github.event.inputs.coverage == 'true'
run: php artisan test --coverage --min=90
env:
DB_PORT: ${{ job.services.postgres.ports['5432'] }}
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
deploy:
name: Deploy on Forge
if: >
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
github.actor != 'dependabot[bot]' &&
github.actor != 'dependabot-preview[bot]'
runs-on: ubuntu-24.04
environment: ${{ github.ref_name == 'develop' && 'develop' || github.ref_name == 'main' && 'production' || null }}
needs:
- tests
- format
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get the latest commit message
id: get_commit_message
run: |
echo "message=$(git log -1 --pretty=%s)" >> "$GITHUB_OUTPUT"
- name: Print GitHub Context
run: |
echo "### GitHub Context ###"
echo "Event Name: ${{ github.event_name }}"
echo "Ref: ${{ github.ref_name }} | ${{ github.ref }}"
echo "Commit title: ${{ steps.get_commit_message.outputs.message }}"
echo "Commit Hash: ${{ github.sha }}"
echo "Actor: ${{ github.actor }}"
- name: Trigger Deployment on Laravel Forge
uses: ./.github/actions/deploy-forge
with:
forge_server_id: ${{ secrets.FORGE_SERVER_ID }}
forge_site_id: ${{ secrets.FORGE_SITE_ID }}
forge_api_token: ${{ secrets.FORGE_DEPLOY_TOKEN }}
branch: ${{ github.ref_name }}
commit_sha: ${{ github.sha }}
commit_author: ${{ github.actor }}
commit_message: ${{ steps.get_commit_message.outputs.message }}
- name: Wait for deployment to complete
uses: ./.github/actions/wait-deploy
with:
forge_server_id: ${{ secrets.FORGE_SERVER_ID }}
forge_site_id: ${{ secrets.FORGE_SITE_ID }}
forge_api_token: ${{ secrets.FORGE_API_TOKEN }}
commit_sha: ${{ github.sha }}