-
Notifications
You must be signed in to change notification settings - Fork 1
175 lines (151 loc) · 5.77 KB
/
build.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
name: Build and test
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
release:
types: [created]
env:
default-php-version: '8.1'
coverage-with: 'sqlite'
jobs:
#############
# Run tests
#############
tests:
runs-on: ubuntu-latest
name: Tests with PHP ${{ matrix.php-version }} + ${{ matrix.connection }}
strategy:
fail-fast: false
matrix:
php-version: ['8.1']
connection: [sqlite, mysql]
coverage: [true]
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, dom, fileinfo, ${{ matrix.connection }}
coverage: none
- name: Check PHP Version
run: php -v
- name: Check Composer Version
run: composer -V
- name: Check PHP Extensions
run: php -m
# Composer
- name: Validate composer.json and composer.lock
run: composer validate
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer files
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
${{ runner.os }}-composer-${{ matrix.php-version }}
${{ runner.os }}-composer-
- name: Install composer dependencies
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
# Prepare
- name: Prepare environment
run: |
cp tests/.env.ci-${{ matrix.connection }} .env
mkdir -p public/js public/css
{\
echo "{"; \
for f in app.js app.css; do \
[[ $first == 1 ]] && echo -n "," || first=1; \
k=${f##*.}/$f; \
echo "\"/$k\": \"/$k\""; \
echo '' > public/$k; \
done; \
echo "}"; \
} | tee public/mix-manifest.json
- name: Create sqlite database
if: matrix.connection == 'sqlite'
run: touch database/database.sqlite
- name: Create mysql database
if: matrix.connection == 'mysql'
run: |
sudo systemctl start mysql.service
mysql --protocol=tcp -u root -proot -e "CREATE DATABASE IF NOT EXISTS version CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
- name: Generate key
run: php artisan key:generate
- name: Run migrations
run: php artisan migrate --no-interaction -vvv
# - name: Run seeds
# run: php artisan db:seed --no-interaction -vvv
- name: Cache route
run: php artisan route:cache
# Test
- name: Run tests suite with coverage
if: matrix.connection == env.coverage-with && matrix.php-version == env.default-php-version && matrix.coverage
run: phpdbg -dmemory_limit=4G -qrr vendor/bin/phpunit -c phpunit.xml --log-junit ./results/${{ matrix.connection }}/junit/results.xml --coverage-clover ./results/${{ matrix.connection }}/coverage/coverage.xml
env:
DB_CONNECTION: ${{ matrix.connection }}
- name: Run tests
if: matrix.connection != env.coverage-with || matrix.php-version != env.default-php-version || ! matrix.coverage
run: vendor/bin/phpunit -c phpunit.xml --log-junit ./results/${{ matrix.connection }}/junit/results.xml
env:
DB_CONNECTION: ${{ matrix.connection }}
- name: Fix results files
run: sed -i -e "s%$GITHUB_WORKSPACE/%%g" **/*.xml
working-directory: results/${{ matrix.connection }}
- name: Store results
if: matrix.php-version == env.default-php-version
uses: actions/upload-artifact@v3
with:
name: results
path: results
###########################
# Reporting to sonarcloud
###########################
reporting:
needs: tests
runs-on: ubuntu-latest
name: Sonarcloud
if: ${{ ! startsWith(github.ref, 'dependabot/') }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Download results
uses: actions/download-artifact@v3
with:
name: results
path: results
- name: Merge junit files
run: |
yarn global add junit-merge
$(yarn global bin)/junit-merge --recursive --dir results/${{ env.coverage-with }}/junit --out results/results.xml
- name: Set version parameter
id: version
run: |
version=$(git tag --points-at HEAD)
test -z "$version" && version="main"
echo "value=$version" >> $GITHUB_OUTPUT
- name: Set coverage list
id: coverage
run: |
SONAR_COVERAGE=$(ls -m --format=comma results/${{ env.coverage-with }}/coverage/coverage*.xml | sed -e ':a;N;$!ba;s/\n//g; s/ //g;')
echo "list=$SONAR_COVERAGE" >> $GITHUB_OUTPUT
- name: SonarCloud Scan
if: env.SONAR_TOKEN != ''
uses: SonarSource/sonarcloud-github-action@v1.6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: |
-Dsonar.projectVersion=${{ steps.version.outputs.value }}
-Dsonar.php.tests.reportPath=./results/results.xml
-Dsonar.php.coverage.reportPaths=${{ steps.coverage.outputs.list }}