Skip to content

Commit 94d4f8a

Browse files
committed
SQSCANGHA-46 Replace the Docker action by a composite action
1 parent 13990a6 commit 94d4f8a

File tree

11 files changed

+155
-154
lines changed

11 files changed

+155
-154
lines changed

.cirrus.star

Lines changed: 0 additions & 4 deletions
This file was deleted.

.cirrus.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

.github/workflows/qa.yml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ jobs:
2727
argsInputTest:
2828
name: >
2929
'args' input
30-
runs-on: ubuntu-latest
30+
strategy:
31+
matrix:
32+
os: [ ubuntu-latest, windows-latest, macos-latest ]
33+
runs-on: ${{ matrix.os }}
3134
steps:
3235
- uses: actions/checkout@v4
3336
with:
3437
token: ${{ secrets.GITHUB_TOKEN }}
3538
- name: Run action with args
3639
uses: ./
3740
with:
38-
args: -Dsonar.someArg=aValue
41+
args: -Dsonar.someArg=aValue -Dsonar.scanner.internal.dumpToFile=./output.properties
3942
env:
4043
SONAR_HOST_URL: http://not_actually_used
4144
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
@@ -45,7 +48,10 @@ jobs:
4548
projectBaseDirInputTest:
4649
name: >
4750
'projectBaseDir' input
48-
runs-on: ubuntu-latest
51+
strategy:
52+
matrix:
53+
os: [ ubuntu-latest, windows-latest, macos-latest ]
54+
runs-on: ${{ matrix.os }}
4955
steps:
5056
- uses: actions/checkout@v4
5157
with:
@@ -54,6 +60,7 @@ jobs:
5460
- name: Run action with projectBaseDir
5561
uses: ./
5662
with:
63+
args: -Dsonar.scanner.internal.dumpToFile=./output.properties
5764
projectBaseDir: ./baseDir
5865
env:
5966
SONAR_HOST_URL: http://not_actually_used
@@ -78,6 +85,7 @@ jobs:
7885
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
7986
with:
8087
projectBaseDir: ./test/gradle-project
88+
args: -Dsonar.scanner.internal.dumpToFile=./output.properties
8189
- name: Assert
8290
run: |
8391
./test/assertFileExists ./output.properties
@@ -98,6 +106,7 @@ jobs:
98106
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
99107
with:
100108
projectBaseDir: ./test/gradle-project
109+
args: -Dsonar.scanner.internal.dumpToFile=./output.properties
101110
- name: Assert
102111
run: |
103112
./test/assertFileExists ./output.properties
@@ -118,6 +127,7 @@ jobs:
118127
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
119128
with:
120129
projectBaseDir: ./test/maven-project
130+
args: -Dsonar.scanner.internal.dumpToFile=./output.properties
121131
- name: Assert
122132
run: |
123133
./test/assertFileExists ./output.properties
@@ -145,7 +155,7 @@ jobs:
145155
id: runTest
146156
uses: ./
147157
env:
148-
SONAR_HOST_URL: http://sonarqube:9000
158+
SONAR_HOST_URL: http://localhost:9000
149159
with:
150160
args: -Dsonar.login=admin -Dsonar.password=admin
151161
projectBaseDir: ./test/example-project
@@ -155,13 +165,18 @@ jobs:
155165
runnerDebugUsedTest:
156166
name: >
157167
'RUNNER_DEBUG' is used
158-
runs-on: ubuntu-latest
168+
strategy:
169+
matrix:
170+
os: [ ubuntu-latest, windows-latest, macos-latest ]
171+
runs-on: ${{ matrix.os }}
159172
steps:
160173
- uses: actions/checkout@v4
161174
with:
162175
token: ${{ secrets.GITHUB_TOKEN }}
163176
- name: Run action with debug mode
164177
uses: ./
178+
with:
179+
args: -Dsonar.scanner.internal.dumpToFile=./output.properties
165180
env:
166181
RUNNER_DEBUG: 1
167182
SONAR_HOST_URL: http://not_actually_used
@@ -193,29 +208,34 @@ jobs:
193208
uses: actions/cache@v4
194209
with:
195210
path: ${{ github.workspace }}/.sonar/cache
196-
key: ${{ runner.os }}-sonar
211+
key: ${{ runner.os }}-${{ runner.arch }}-sonar
197212
- name: Run action on sample project
198213
id: runTest
199214
uses: ./
200215
env:
201-
SONAR_HOST_URL: http://sonarqube:9000
216+
SONAR_HOST_URL: http://localhost:9000
202217
SONAR_USER_HOME: ${{ github.workspace }}/.sonar
203218
with:
204219
args: -Dsonar.login=admin -Dsonar.password=admin
205220
projectBaseDir: ./test/example-project
206221
- name: Assert
207222
run: |
208-
./test/assertFileExists ./test/example-project/.scannerwork/report-task.txt
223+
./test/assertFileExists ./test/example-project/.scannerwork/report-task.txt
209224
useSslCertificate:
210225
name: >
211226
'SONAR_ROOT_CERT' is converted to truststore
212-
runs-on: ubuntu-latest
227+
strategy:
228+
matrix:
229+
os: [ ubuntu-latest, windows-latest, macos-latest ]
230+
runs-on: ${{ matrix.os }}
213231
steps:
214232
- uses: actions/checkout@v4
215233
with:
216234
token: ${{ secrets.GITHUB_TOKEN }}
217235
- name: Run action with SSL certificate
218236
uses: ./
237+
with:
238+
args: -Dsonar.scanner.internal.dumpToFile=./output.properties
219239
env:
220240
SONAR_ROOT_CERT: |
221241
-----BEGIN CERTIFICATE-----
@@ -252,7 +272,6 @@ jobs:
252272
Fct6d1S08JAosVnZcP2P7Yz+TbmDRtsqCgk=
253273
-----END CERTIFICATE-----
254274
SONAR_HOST_URL: http://not_actually_used
255-
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
256275
- name: Assert
257276
run: |
258-
./test/assertFileContains ./output.properties "sonar.scanner.truststorePassword=changeit"
277+
./test/assertFileExists ~/.sonar/ssl/truststore.p12

Dockerfile

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,10 @@ This GitHub Action will not work for all technologies. If you are in one of the
118118
* You want to analyze a .NET solution. Read the documentation about our [Scanner for .NET](https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html).
119119
* You want to analyze C or C++ code. Starting from SonarQube 10.6, this GitHub Action will scan C and C++ out of the box. If you want to have better control over the scan configuration/setup, you can switch to the [SonarQube C and C++](https://github.com/SonarSource/sonarqube-github-c-cpp) GitHub Action.
120120

121-
## Error cleaning up workspace
122-
123-
In some cases, the checkout action may fail to clean up the workspace. This is a known problem for GitHub actions implemented as a docker container (such as `sonarqube-scan-action`) when self-hosted runners are used.
124-
Example of the error message: `File was unable to be removed Error: EACCES: permission denied, unlink '/actions-runner/_work//project/.scannerwork/.sonar_lock'`
125-
To work around the problem, `sonarqube-scan-action` attempts to fix the permission of the temporary files that it creates. If that doesn't work, you can manually clean up the workspace by running the following action:
126-
```
127-
- name: Clean the workspace
128-
uses: docker://alpine
129-
with:
130-
args: /bin/sh -c "find \"${GITHUB_WORKSPACE}\" -mindepth 1 ! -name . -prune -exec rm -rf {} +"
131-
```
132-
You can find more info [here](https://github.com/actions/runner/issues/434).
133-
134121
## Have questions or feedback?
135122

136123
To provide feedback (requesting a feature or reporting a bug) please post on the [SonarSource Community Forum](https://community.sonarsource.com/tags/c/help/sq/github-actions).
137124

138125
## License
139126

140-
The Dockerfile and associated scripts and documentation in this project are released under the LGPLv3 License.
141-
142127
Container images built with this project include third-party materials.

action.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,42 @@ description: >
44
branding:
55
icon: check
66
color: green
7-
runs:
8-
using: docker
9-
image: Dockerfile
10-
entrypoint: "/entrypoint.sh"
11-
post-entrypoint: "/cleanup.sh"
127
inputs:
138
args:
149
description: Additional arguments to the sonar-scanner
1510
required: false
1611
projectBaseDir:
1712
description: Set the sonar.projectBaseDir analysis property
1813
required: false
19-
default: .
14+
scannerVersion:
15+
description: Version of the Sonar Scanner CLI to use
16+
required: false
17+
default: 6.2.1.4610
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: Sanity checks
22+
run: ${GITHUB_ACTION_PATH}/sanity-checks.sh
23+
shell: bash
24+
env:
25+
INPUT_PROJECTBASEDIR: ${{ inputs.projectBaseDir }}
26+
- name: Load Sonar Scanner CLI from cache
27+
id: sonar-scanner-cli
28+
uses: actions/[email protected]
29+
with:
30+
path: ${{ runner.temp }}/sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }}
31+
key: sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }}
32+
- name: Install Sonar Scanner CLI
33+
if: steps.sonar-scanner-cli.outputs.cache-hit != 'true'
34+
run: ${GITHUB_ACTION_PATH}/install-sonar-scanner-cli.sh
35+
shell: bash
36+
env:
37+
INPUT_SCANNERVERSION: ${{ inputs.scannerVersion }}
38+
- name: Add SonarScanner CLI to the PATH
39+
run: echo "${RUNNER_TEMP}/sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }}/bin" >> $GITHUB_PATH
40+
shell: bash
41+
- name: Run SonarScanner
42+
run: ${GITHUB_ACTION_PATH}/run-sonar-scanner.sh ${{ inputs.args }}
43+
shell: bash
44+
env:
45+
INPUT_PROJECTBASEDIR: ${{ inputs.projectBaseDir }}

cleanup.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

entrypoint.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

install-sonar-scanner-cli.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
set -eou pipefail
4+
5+
#See https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables
6+
7+
WGET=wget
8+
if [[ "$RUNNER_OS" == "Linux" && "$RUNNER_ARCH" == "X64" ]]; then
9+
FLAVOR="linux-x64"
10+
elif [[ "$RUNNER_OS" == "Linux" && "$RUNNER_ARCH" == "ARM64" ]]; then
11+
FLAVOR="linux-aarch64"
12+
elif [[ "$RUNNER_OS" == "Windows" && "$RUNNER_ARCH" == "X64" ]]; then
13+
FLAVOR="windows-x64"
14+
WGET="C:\\msys64\\usr\\bin\\wget.exe"
15+
elif [[ "$RUNNER_OS" == "macOS" && "$RUNNER_ARCH" == "X64" ]]; then
16+
FLAVOR="macosx-x64"
17+
elif [[ "$RUNNER_OS" == "macOS" && "$RUNNER_ARCH" == "ARM64" ]]; then
18+
FLAVOR="macosx-aarch64"
19+
else
20+
echo "$RUNNER_OS $RUNNER_ARCH not supported"
21+
exit 1
22+
fi
23+
24+
set -x
25+
26+
mkdir -p $RUNNER_TEMP/sonarscanner
27+
cd $RUNNER_TEMP/sonarscanner
28+
29+
$WGET --no-verbose --user-agent="sonarqube-scan-action" https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR.zip
30+
31+
unzip -q sonar-scanner-cli-$INPUT_SCANNERVERSION-$FLAVOR.zip
32+
33+
# Folder name should correspond to the directory cached by the actions/cache
34+
mv sonar-scanner-$INPUT_SCANNERVERSION-$FLAVOR $RUNNER_TEMP/sonar-scanner-cli-$INPUT_SCANNERVERSION-$RUNNER_OS-$RUNNER_ARCH

0 commit comments

Comments
 (0)