-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (160 loc) · 5.7 KB
/
php-phpunit-with-sonar-qube.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
name: PHP Unit with Sonar Qube
on:
workflow_call:
secrets:
COMPOSER_TOKEN:
required: false
description: 'composer token'
SONAR_TOKEN:
required: true
description: 'SonarQube token'
inputs:
SONAR_HOST_URL:
required: false
type: string
description: 'SonaQube host URL'
default: 'https://sonar.nice.com'
PHP_VERSION:
required: false
type: string
description: 'PHP version'
default: '8.1'
PHP_EXTENSIONS:
required: false
type: string
description: 'A list of PHP extensions to install'
default: 'mbstring,sockets,xdebug'
PHP_INI_VALUES:
required: false
type: string
description: 'PHP ini values'
default: ''
COPY_CONFIGURATION_FILES:
required: false
type: string
description: 'Configuration files to copy before running the phpunit'
default: ''
SERVICES:
required: false
type: string
description: 'A list of services, currently available: mysql'
default: ''
MYSQL_DATABASE:
required: false
type: string
description: 'Mysql database name'
default: 'db'
MYSQL_USER:
required: false
type: string
description: 'Mysql user'
default: 'app'
MYSQL_PASSWORD:
required: false
type: string
description: 'Mysql password'
# Not a secret
default: '123'
MYSQL_ROOT_PASSWORD:
required: false
type: string
description: 'Mysql root password'
# Not a secret
default: '123'
RUNS_ON:
required: false
type: string
description: 'Runs on'
default: 'ubuntu-latest'
GITHUB_ACTIONS_REPOSITORY_REF:
required: false
type: string
description: 'Which version of BrandEmbassy/github-actions repository to checkout'
default: 'master'
jobs:
phpunit-with-sonar-qube:
name: PHP Unit with Sonar Qube
runs-on: ${{ inputs.RUNS_ON }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
ini-values: ${{ inputs.PHP_INI_VALUES }}
php-version: ${{ inputs.PHP_VERSION }}
extensions: ${{ inputs.PHP_EXTENSIONS }}
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Configure composer token
if: env.COMPOSER_TOKEN != ''
env:
COMPOSER_TOKEN: ${{ secrets.COMPOSER_TOKEN }}
run: composer config github-oauth.github.com ${{ secrets.COMPOSER_TOKEN }}
- name: Install dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Copy configuration files
if: env.COPY_CONFIGURATION_FILES != ''
env:
COPY_CONFIGURATION_FILES: ${{ inputs.COPY_CONFIGURATION_FILES }}
run: |
IFS=' ' read -ra ADDR <<< "$COPY_CONFIGURATION_FILES"
for file in "${ADDR[@]}"; do
IFS=':' read -r src dest <<< "$file"
echo "Copying $src to $dest"
mkdir -p "$(dirname "$dest")" && cp "$src" "$dest"
done
- name: Build list of desired docker-compose files
if: env.SERVICES != ''
env:
SERVICES: ${{ inputs.SERVICES }}
run: |
# Initialize an empty string to accumulate our docker-compose file paths
SERVICES_TO_RUN=""
# Split the SERVICES string into an array based on commas
IFS=',' read -ra ADDR <<< "$SERVICES"
# Loop through the array, trim whitespace, and append the specific docker-compose file path to SERVICES_TO_RUN
for SERVICE in "${ADDR[@]}"; do
SERVICE=$(echo "$SERVICE" | xargs) # Trim whitespace
SERVICES_TO_RUN+=".shared-github-actions/docker/docker-compose.$SERVICE.yaml "
done
# Use GHA commands to set SERVICES_TO_RUN as an output variable
echo "SERVICES_TO_RUN=$SERVICES_TO_RUN" >> $GITHUB_ENV
# Print the content of SERVICES_TO_RUN to the log
echo "Docker Compose files to run: $SERVICES_TO_RUN"
- name: Checkout the github-actions repository with shared files
if: env.SERVICES_TO_RUN != ''
env:
GITHUB_ACTIONS_REPOSITORY_REF: ${{ inputs.GITHUB_ACTIONS_REPOSITORY_REF }}
uses: actions/checkout@v4
with:
repository: 'BrandEmbassy/github-actions'
path: '.shared-github-actions'
ref: ${{ env.GITHUB_ACTIONS_REPOSITORY_REF }}
sparse-checkout: |
docker
- name: Docker compose
if: env.SERVICES_TO_RUN != ''
env:
MYSQL_DATABASE: ${{ inputs.MYSQL_DATABASE }}
MYSQL_USER: ${{ inputs.MYSQL_USER }}
MYSQL_PASSWORD: ${{ inputs.MYSQL_PASSWORD }}
MYSQL_ROOT_PASSWORD: ${{ inputs.MYSQL_ROOT_PASSWORD }}
uses: hoverkraft-tech/compose-action@v1.5.1
with:
compose-file: ${{ env.SERVICES_TO_RUN }}
up-flags: "--wait"
- name: Run phpunit with code coverage and Sonar Qube
run: composer phpunit-cc
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ inputs.SONAR_HOST_URL }}