-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
197 lines (188 loc) · 6.66 KB
/
action.yaml
File metadata and controls
197 lines (188 loc) · 6.66 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: 'sonarcloud'
description: 'Runs sonarcloud in the given container'
inputs:
coverage_artifact:
type: string
required: false
description: 'Name of the artifact containing the coverage reports'
default: 'coverage-reports'
strip_path:
type: string
required: false
description: 'What should be stripped from the absolute path in the coverage files'
default: '/var/www/'
target_branch:
type: string
required: false
description: 'Target branch for the scan'
default: 'b-8.0.x'
github_ref_name:
type: string
required: true
description: 'GitHub reference for the scan'
sonarcloud_organization:
type: string
required: false
description: 'Name of the organization in sonarcloud'
default: 'oxid-esales'
sonarcloud_project_key:
type: string
required: false
description: 'Project key in sonarcloud'
default: 'OXID-eSales_oxideshop_ce'
sonarcloud_project_name:
type: string
required: false
description: 'Project name in sonarcloud'
default: 'oxideshop_ce'
sonarcloud_parameters:
type: string
required: false
description: 'Parameters passed to the scanner'
default: >
-Dsonar.language=php
-Dsonar.sources=source
-Dsonar.tests=tests
-Dsonar.cpd.php.minimumTokens=25
-Dsonar.cpd.php.minimumLines=5
sonar_token:
type: string
required: true
description: 'Token for Sonarcloud'
github_token:
type: string
required: true
description: 'Token for Sonarcloud github access'
output_files:
type: string
required: false
description: 'sonarcloud output and test settings'
default: |
tests/*
output_artifact:
type: string
required: false
description: 'GitHub run artifact for the sonarcloud output'
default: 'sonarcloud-artifacts'
run_cleanup:
type: boolean
required: false
description: 'Whether to clean up coverage artifacts after processing'
default: true
debug:
type: string
description: 'Appended to debugging scripts'
default: ''
required: false
runs:
using: "composite"
steps:
- name: 'Download artifacts'
uses: 'actions/download-artifact@v4'
with:
pattern: '${{ inputs.coverage_artifact }}'
merge-multiple: true
path: coverage-reports
- name: 'Fix Paths In Coverage Reports'
shell: bash
run: |
# sonarcloud: Fix Paths In Coverage Reports
${{ inputs.debug }}
COVERAGE_FILES=""
for FILE in $(find coverage-reports -iname 'coverage*.xml'); do
echo -e "\033[0;35mFixing paths in ${FILE}\033[0m"
cp "${FILE}" "${FILE}.orig"
sed -e 's|${{ inputs.strip_path }}||' -i.backup ${FILE}
COVERAGE_FILES="${COVERAGE_FILES},${FILE}"
# diff -y --color=always "${FILE}.orig" "${FILE}" || true
done
# remove leading comma when adding this
echo "COVERAGE_PARAM=-Dsonar.php.coverage.reportPaths=${COVERAGE_FILES:1}"| tee -a "${GITHUB_ENV}"
PHPUNIT_FILES=""
for FILE in $(find coverage-reports -iname 'phpunit*.xml'); do
echo -e "\033[0;35mFixing paths in ${FILE}\033[0m"
cp "${FILE}" "${FILE}.orig"
sed -e 's|${{ inputs.strip_path }}||' -i.backup ${FILE}
PHPUNIT_FILES="${PHPUNIT_FILES},${FILE}"
# diff -y --color=always "${FILE}.orig" "${FILE}" || true
done
# remove leading comma when adding this
if [ -n "${PHPUNIT_FILES:1}" ]; then
echo "PHPUNIT_PARAM=-Dsonar.php.tests.reportPath=${PHPUNIT_FILES:1}"| tee -a "${GITHUB_ENV}"
fi
PHPSTAN_FILES=""
for FILE in $(find coverage-reports -iname 'phpstan*.json'); do
echo -e "\033[0;35mFixing paths in ${FILE}\033[0m"
cp "${FILE}" "${FILE}.orig"
sed -e 's|${{ inputs.strip_path }}||' -i.backup ${FILE}
PHPSTAN_FILES="${PHPSTAN_FILES},${FILE}"
# diff -y --color=always "${FILE}.orig" "${FILE}" || true
done
# remove leading comma when adding this
if [ -n "${PHPSTAN_FILES:1}" ]; then
echo "PHPSTAN_PARAM=-Dsonar.php.phpstan.reportPaths=${PHPSTAN_FILES:1}"| tee -a "${GITHUB_ENV}"
fi
if [ -z "${COVERAGE_FILES:1}${PHPUNIT_FILES:1}${PHPSTAN_FILES:1}" ]; then
echo -e "\033[0;31m### No input files found for SonarCloud ###\033[0m"
exit 1
fi
- name: 'Upload consolidated artifact'
uses: 'actions/upload-artifact@v4'
with:
name: '${{ inputs.output_artifact }}'
path: 'coverage-reports'
retention-days: 4
overwrite: true
- name: 'Remove old artifacts'
if: ${{ inputs.run_cleanup == 'true' }}
uses: 'joernott/rm-artifact@v1'
with:
name: '${{ inputs.coverage_artifact }}'
useGlob: true
failOnError: false
- name: 'Set target branch'
shell: bash
run: |
# sonarcloud: Set target branch
${{ inputs.debug }}
TARGET_BRANCH_PARAM="-Dsonar.branch.target=${{ inputs.target_branch }}"
if [ "${{ github.ref_name }}" == "${{ github.event.repository.default_branch }}" ]; then
TARGET_BRANCH_PARAM=""
fi
echo "TARGET_BRANCH_PARAM=$TARGET_BRANCH_PARAM" >> $GITHUB_ENV
- name: 'Debug Sonarcloud scan'
if: ${{ inputs.debug != '' }}
shell: bash
run: |
# sonarcloud: Debug sonarcloud Scan (simulated)
cat >debug/debug.sh <<EODS
banner "sonarcloud: Debug sonarcloud Scan (simulated)"
cat <<'EOF'
# would call SonarSource/sonarqube-scan-action@v6
-Dsonar.organization=${{ inputs.sonarcloud_organization }}
-Dsonar.projectKey=${{ inputs.sonarcloud_project_key }}
-Dsonar.projectName=${{ inputs.sonarcloud_project_name }}
-Dsonar.branch.name=${{ inputs.github_ref_name }}
${{ env.COVERAGE_PARAM }}
${{ env.PHPUNIT_PARAM }}
${{ env.PHPSTAN_PARAM }}
${{ env.TARGET_BRANCH_PARAM }}
${{ inputs.sonarcloud_parameters }}
EOF
EODS
- name: 'SonarCloud Scan'
uses: 'SonarSource/sonarqube-scan-action@v6'
env:
SONAR_TOKEN: ${{ inputs.sonar_token }}
GITHUB_TOKEN: ${{ inputs.github_token }}
with:
args: >
-Dsonar.organization=${{ inputs.sonarcloud_organization }}
-Dsonar.projectKey=${{ inputs.sonarcloud_project_key }}
-Dsonar.projectName=${{ inputs.sonarcloud_project_name }}
-Dsonar.branch.name=${{ inputs.github_ref_name }}
${{ env.COVERAGE_PARAM }}
${{ env.PHPUNIT_PARAM }}
${{ env.PHPSTAN_PARAM }}
${{ env.TARGET_BRANCH_PARAM }}
${{ inputs.sonarcloud_parameters }}