Compare commits

...

15 Commits

Author SHA1 Message Date
Julien HENRY
802bf88184 Revert test to show expected behavior (USER-933) 2025-09-08 09:24:24 +02:00
Julien HENRY
a6104e7ee4 Try with string-argv 2025-09-05 16:21:13 +02:00
Julien HENRY
42fef39f2a Another try 2025-09-05 16:18:24 +02:00
Julien HENRY
ef61b6021f Fix JS import 2025-09-05 15:32:19 +02:00
Julien HENRY
500f8e1411 Add support for Unix 2025-09-05 13:51:39 +02:00
Julien HENRY
4690589d97 Fix parsing 2025-09-05 13:49:53 +02:00
Julien HENRY
cdb14cba33 Experiment 2025-09-05 12:47:47 +02:00
Julien HENRY
3b1a0d504d Disable fail fast on matrix jobs 2025-09-05 11:39:53 +02:00
Julien HENRY
cdefb11fbe Fix test assertion 2025-09-05 11:23:26 +02:00
SonarTech
5837ebfcca BUILD-8875: Migrate to standardized GitHub runner names
Co-authored-by: Julien HENRY <julien.henry@sonarsource.com>
2025-09-02 10:10:38 +02:00
Daan Timmer
1a6d90ebcb SQSCANGHA-102 Pin actions/cache to a full-length commit SHA (#199) 2025-08-28 12:18:32 +02:00
Aleksandra Bozhinoska
016cabf33a SQSCANGHA-101 Add more command injection tests 2025-08-28 10:57:10 +02:00
Aleksandra Bozhinoska
5fc8cfce6b SQSCANGHA-101 Fix sha256 check in QA Deprecated C/C++ action 2025-08-28 10:57:10 +02:00
dependabot[bot]
786af10ed4 NO-JIRA Bump actions/checkout from 4 to 5
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-19 13:34:18 +02:00
Julien HENRY
01850e2590 SQSCANGHA-94 Fix the scanner-update workflow 2025-07-22 11:46:10 +02:00
14 changed files with 215 additions and 91 deletions

View File

@@ -7,7 +7,7 @@ on:
jobs: jobs:
PullRequestClosed_job: PullRequestClosed_job:
name: Pull Request Closed name: Pull Request Closed
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
permissions: permissions:
id-token: write id-token: write
pull-requests: read pull-requests: read

View File

@@ -7,7 +7,7 @@ on:
jobs: jobs:
PullRequestCreated_job: PullRequestCreated_job:
name: Pull Request Created name: Pull Request Created
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
permissions: permissions:
id-token: write id-token: write
# For external PR, ticket should be created manually # For external PR, ticket should be created manually

View File

@@ -7,7 +7,7 @@ on:
jobs: jobs:
RequestReview_job: RequestReview_job:
name: Request review name: Request review
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
permissions: permissions:
id-token: write id-token: write
# For external PR, ticket should be moved manually # For external PR, ticket should be moved manually

View File

@@ -7,7 +7,7 @@ on:
jobs: jobs:
SubmitReview_job: SubmitReview_job:
name: Submit Review name: Submit Review
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
permissions: permissions:
id-token: write id-token: write
pull-requests: read pull-requests: read

View File

@@ -12,7 +12,7 @@ jobs:
name: Action outputs name: Action outputs
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest-large, windows-latest-large, macos-latest, macos-13] os: [github-ubuntu-latest-s, github-windows-latest-s, macos-latest, macos-13]
cache: [true, false] cache: [true, false]
include: include:
- arch: X64 - arch: X64
@@ -31,7 +31,7 @@ jobs:
exit 1 exit 1
fi fi
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

View File

@@ -12,7 +12,7 @@ jobs:
name: Action outputs name: Action outputs
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest-large, windows-latest-large, macos-latest, macos-13] os: [github-ubuntu-latest-s, github-windows-latest-s, macos-latest, macos-13]
cache: [true, false] cache: [true, false]
include: include:
- arch: X64 - arch: X64
@@ -31,7 +31,7 @@ jobs:
exit 1 exit 1
fi fi
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

View File

@@ -12,11 +12,12 @@ jobs:
name: > name: >
No inputs No inputs
strategy: strategy:
fail-fast: false
matrix: matrix:
os: [ ubuntu-latest-large, macos-latest ] os: [ github-ubuntu-latest-s, macos-latest ]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action without args - name: Run action without args
@@ -31,17 +32,18 @@ jobs:
name: > name: >
'args' input 'args' input
strategy: strategy:
fail-fast: false
matrix: matrix:
os: [ ubuntu-latest-large, windows-latest-large, macos-latest ] os: [ github-ubuntu-latest-s, github-windows-latest-s, macos-latest ]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with args - name: Run action with args
uses: ./ uses: ./
with: with:
args: -Dsonar.someArg=aValue -Dsonar.anotherArgWithSpaces="Another Value" args: -Dsonar.someArg=aValue -Dsonar.anotherArgWithSpaces="Another Value" -Dsonar.argWithSingleQuotes='Another Value'
env: env:
SONAR_HOST_URL: http://not_actually_used SONAR_HOST_URL: http://not_actually_used
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}' SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
@@ -49,22 +51,26 @@ jobs:
run: | run: |
./test/assertFileContains ./output.properties "sonar.someArg=aValue" ./test/assertFileContains ./output.properties "sonar.someArg=aValue"
./test/assertFileContains ./output.properties "sonar.anotherArgWithSpaces=Another Value" ./test/assertFileContains ./output.properties "sonar.anotherArgWithSpaces=Another Value"
./test/assertFileContains ./output.properties "sonar.argWithSingleQuotes=Another Value"
argsInputInjectionTest: argsInputInjectionTest:
name: > name: >
'args' input with command injection will fail 'args' input with command injection will fail
strategy: strategy:
fail-fast: false
matrix: matrix:
os: [ ubuntu-latest-large, windows-latest-large, macos-latest ] os: [ github-ubuntu-latest-s, github-windows-latest-s, macos-latest ]
args: [ -Dsonar.someArg=aValue && echo "Injection", -Dsonar.someArg="value\"; whoami; echo \"" ]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with args - name: Run action with args
id: runTest
uses: ./ uses: ./
continue-on-error: true continue-on-error: true
with: with:
args: -Dsonar.someArg=aValue && echo "Injection" args: ${{ matrix.args }}
env: env:
SONAR_HOST_URL: http://not_actually_used SONAR_HOST_URL: http://not_actually_used
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}' SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
@@ -74,15 +80,101 @@ jobs:
- name: Assert the scanner was not called - name: Assert the scanner was not called
run: | run: |
./test/assertFileDoesntExist ./output.properties ./test/assertFileDoesntExist ./output.properties
backtickCommandInjectionTest:
name: >
'args' input with backticks injection does not execute command
strategy:
fail-fast: false
matrix:
os: [ github-ubuntu-latest-s, github-windows-latest-s, macos-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with args
uses: ./
continue-on-error: true
with:
args: >
-Dsonar.arg1="refs/heads/branch: [workflows] Bump `actions/*`" -Dsonar.arg2="test `echo Command Injection`" -Dsonar.arg3="`id`" -Dsonar.arg4="test'; `echo injection`; echo '" -Dsonar.arg5=" `whoami` " -Dsonar.arg6="test\`echo injection\`test"
env:
SONAR_HOST_URL: http://not_actually_used
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
- name: Assert command in arg is not executed
run: |
./test/assertFileContains ./output.properties 'sonar.arg1="refs/heads/branch\\: \[workflows\] Bump `actions/\*`"'
./test/assertFileContains ./output.properties 'sonar.arg2="test `echo Command Injection`"'
./test/assertFileContains ./output.properties 'sonar.arg3="`id`"'
./test/assertFileContains ./output.properties "sonar.arg4=\"test'; \`echo injection\`; echo '\""
./test/assertFileContains ./output.properties 'sonar.arg5=" `whoami` "'
./test/assertFileContains ./output.properties 'sonar.arg6="test\\\\`echo injection\\\\`test"'
dollarSymbolCommandInjectionTest:
name: >
'args' input with dollar command injection does not execute command
strategy:
matrix:
os: [ github-ubuntu-latest-s, github-windows-latest-s, macos-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with args
uses: ./
continue-on-error: true
with:
args: -Dsonar.arg1="$(whoami)" -Dsonar.arg2="$GITHUB_TOKEN" -Dsonar.arg3="$(echo outer $(echo inner))" -Dsonar.arg4="value\$(whoami)end" -Dsonar.arg5="$(printf 'A%.0s' {1..10000})" -Dsonar.arg6='value"; $(whoami); echo "'
env:
SONAR_HOST_URL: http://not_actually_used
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
- name: Assert command in arg is not executed
run: |
./test/assertFileContains ./output.properties 'sonar.arg1="$(whoami)"'
./test/assertFileContains ./output.properties 'sonar.arg2="$GITHUB_TOKEN"'
./test/assertFileContains ./output.properties 'sonar.arg3="$(echo outer $(echo inner))"'
./test/assertFileContains ./output.properties 'sonar.arg4="value\\\\$(whoami)end"'
./test/assertFileContains ./output.properties 'sonar.arg5="$(printf '\''A%.0s'\'' {1..10000})"'
./test/assertFileContains ./output.properties 'sonar.arg6='\''value"; $(whoami); echo "'\'''
otherCommandInjectionVariantsTest:
name: >
'args' input with other command injection variants does not execute command
strategy:
matrix:
os: [ github-ubuntu-latest-s, github-windows-latest-s, macos-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with args
uses: ./
continue-on-error: true
with:
args: -Dsonar.arg1="test | base64" -Dsonar.arg2="value; whoami" -Dsonar.arg3="value && echo test" -Dsonar.arg4="value > /tmp/output.txt" -Dsonar.arg5="< /etc/passwd" -Dsonar.arg6="" -Dsonar.arg7="../../../*" -Dsonar.arg8="*.key" -Dsonar.arg9="test\u0027\u0060whoami\u0060"
env:
SONAR_HOST_URL: http://not_actually_used
SONAR_SCANNER_JSON_PARAMS: '{"sonar.scanner.internal.dumpToFile": "./output.properties"}'
- name: Assert command in arg is not executed
run: |
./test/assertFileContains ./output.properties 'sonar.arg1="test | base64"'
./test/assertFileContains ./output.properties 'sonar.arg2="value; whoami"'
./test/assertFileContains ./output.properties 'sonar.arg3="value && echo test"'
./test/assertFileContains ./output.properties 'sonar.arg4="value > /tmp/output.txt"'
./test/assertFileContains ./output.properties 'sonar.arg5="< /etc/passwd"'
./test/assertFileContains ./output.properties 'sonar.arg6=""'
./test/assertFileContains ./output.properties 'sonar.arg7="../../../\*"'
./test/assertFileContains ./output.properties 'sonar.arg8="\*.key"'
./test/assertFileContains ./output.properties 'sonar.arg9="test\\\\u0027\\\\u0060whoami\\\\u0060"'
projectBaseDirInputTest: projectBaseDirInputTest:
name: > name: >
'projectBaseDir' input 'projectBaseDir' input
strategy: strategy:
matrix: matrix:
os: [ ubuntu-latest-large, windows-latest-large, macos-latest ] os: [ github-ubuntu-latest-s, github-windows-latest-s, macos-latest ]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- run: mkdir -p ./baseDir - run: mkdir -p ./baseDir
@@ -100,9 +192,9 @@ jobs:
scannerVersionTest: scannerVersionTest:
name: > name: >
'scannerVersion' input 'scannerVersion' input
runs-on: ubuntu-latest-large # assumes default RUNNER_ARCH for linux is X64 runs-on: github-ubuntu-latest-s # assumes default RUNNER_ARCH for linux is X64
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with scannerVersion - name: Run action with scannerVersion
@@ -120,9 +212,9 @@ jobs:
scannerBinariesUrlTest: scannerBinariesUrlTest:
name: > name: >
'scannerBinariesUrl' input with invalid URL 'scannerBinariesUrl' input with invalid URL
runs-on: ubuntu-latest-large # assumes default RUNNER_ARCH for linux is X64 runs-on: github-ubuntu-latest-s # assumes default RUNNER_ARCH for linux is X64
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with scannerBinariesUrl - name: Run action with scannerBinariesUrl
@@ -148,9 +240,9 @@ jobs:
scannerBinariesUrlIsEscapedWithWget: scannerBinariesUrlIsEscapedWithWget:
name: > name: >
'scannerBinariesUrl' is escaped with wget so special chars are not injected in the download command 'scannerBinariesUrl' is escaped with wget so special chars are not injected in the download command
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with scannerBinariesUrl - name: Run action with scannerBinariesUrl
@@ -169,9 +261,9 @@ jobs:
scannerBinariesUrlIsEscapedWithCurl: scannerBinariesUrlIsEscapedWithCurl:
name: > name: >
'scannerBinariesUrl' is escaped with curl so special chars are not injected in the download command 'scannerBinariesUrl' is escaped with curl so special chars are not injected in the download command
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Remove wget - name: Remove wget
@@ -198,9 +290,9 @@ jobs:
dontFailGradleTest: dontFailGradleTest:
name: > name: >
Don't fail on Gradle project Don't fail on Gradle project
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action on Gradle project - name: Run action on Gradle project
@@ -219,9 +311,9 @@ jobs:
dontFailGradleKotlinTest: dontFailGradleKotlinTest:
name: > name: >
Don't fail on Kotlin Gradle project Don't fail on Kotlin Gradle project
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action on Kotlin Gradle project - name: Run action on Kotlin Gradle project
@@ -240,9 +332,9 @@ jobs:
dontFailMavenTest: dontFailMavenTest:
name: > name: >
Don't fail on Maven project Don't fail on Maven project
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action on Maven project - name: Run action on Maven project
@@ -259,7 +351,7 @@ jobs:
run: | run: |
./test/assertFileExists ./output.properties ./test/assertFileExists ./output.properties
runAnalysisTest: runAnalysisTest:
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
services: services:
sonarqube: sonarqube:
image: sonarqube:lts-community image: sonarqube:lts-community
@@ -275,7 +367,7 @@ jobs:
--health-timeout 5s --health-timeout 5s
--health-retries 10 --health-retries 10
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action on sample project - name: Run action on sample project
@@ -293,11 +385,12 @@ jobs:
name: > name: >
'RUNNER_DEBUG' is used 'RUNNER_DEBUG' is used
strategy: strategy:
fail-fast: false
matrix: matrix:
os: [ ubuntu-latest-large, windows-latest-large, macos-latest ] os: [ github-ubuntu-latest-s, github-windows-latest-s, macos-latest ]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with debug mode - name: Run action with debug mode
@@ -312,7 +405,7 @@ jobs:
run: | run: |
./test/assertFileContains ./output.properties "sonar.verbose=true" ./test/assertFileContains ./output.properties "sonar.verbose=true"
runAnalysisWithCacheTest: runAnalysisWithCacheTest:
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
services: services:
sonarqube: sonarqube:
image: sonarqube:lts-community image: sonarqube:lts-community
@@ -328,7 +421,7 @@ jobs:
--health-timeout 5s --health-timeout 5s
--health-retries 10 --health-retries 10
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: SonarQube Cache - name: SonarQube Cache
@@ -352,11 +445,12 @@ jobs:
name: > name: >
'SONARCLOUD_URL' is used 'SONARCLOUD_URL' is used
strategy: strategy:
fail-fast: false
matrix: matrix:
os: [ ubuntu-latest-large, windows-latest-large, macos-latest ] os: [ github-ubuntu-latest-s, github-windows-latest-s, macos-latest ]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with SONARCLOUD_URL - name: Run action with SONARCLOUD_URL
@@ -372,9 +466,9 @@ jobs:
./test/assertFileContains ./output.properties "sonar.scanner.sonarcloudUrl=mirror.sonarcloud.io" ./test/assertFileContains ./output.properties "sonar.scanner.sonarcloudUrl=mirror.sonarcloud.io"
dontFailWhenMissingWgetButCurlAvailable: dontFailWhenMissingWgetButCurlAvailable:
name: Don't fail when missing wget but curl available name: Don't fail when missing wget but curl available
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Remove wget - name: Remove wget
@@ -398,9 +492,9 @@ jobs:
./test/assertFileExists ./output.properties ./test/assertFileExists ./output.properties
dontFailWhenMissingCurlButWgetAvailable: dontFailWhenMissingCurlButWgetAvailable:
name: Don't fail when missing curl but wget available name: Don't fail when missing curl but wget available
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Remove curl - name: Remove curl
@@ -425,9 +519,9 @@ jobs:
./test/assertFileExists ./output.properties ./test/assertFileExists ./output.properties
failWhenBothWgetAndCurlMissing: failWhenBothWgetAndCurlMissing:
name: Fail when both wget and curl are missing name: Fail when both wget and curl are missing
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Remove wget and curl - name: Remove wget and curl
@@ -458,9 +552,9 @@ jobs:
curlPerformsRedirect: curlPerformsRedirect:
name: > name: >
curl performs redirect when scannerBinariesUrl returns 3xx curl performs redirect when scannerBinariesUrl returns 3xx
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Remove wget - name: Remove wget
@@ -491,11 +585,12 @@ jobs:
name: > name: >
'SONAR_ROOT_CERT' is converted to truststore 'SONAR_ROOT_CERT' is converted to truststore
strategy: strategy:
fail-fast: false
matrix: matrix:
os: [ ubuntu-latest-large, windows-latest-large, macos-latest ] os: [ github-ubuntu-latest-s, github-windows-latest-s, macos-latest ]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with SSL certificate - name: Run action with SSL certificate
@@ -544,9 +639,9 @@ jobs:
analysisWithSslCertificate: analysisWithSslCertificate:
name: > name: >
Analysis takes into account 'SONAR_ROOT_CERT' Analysis takes into account 'SONAR_ROOT_CERT'
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate server certificate - name: Generate server certificate
@@ -652,9 +747,9 @@ jobs:
overridesScannerLocalFolderWhenPresent: # can happen in uncleaned self-hosted runners overridesScannerLocalFolderWhenPresent: # can happen in uncleaned self-hosted runners
name: > name: >
'SCANNER_LOCAL_FOLDER' is cleaned with warning when present 'SCANNER_LOCAL_FOLDER' is cleaned with warning when present
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Create a dummy SCANNER_LOCAL_FOLDER with dummy content in it - name: Create a dummy SCANNER_LOCAL_FOLDER with dummy content in it
@@ -686,9 +781,9 @@ jobs:
updateTruststoreWhenPresent: # can happen in uncleaned self-hosted runners updateTruststoreWhenPresent: # can happen in uncleaned self-hosted runners
name: > name: >
truststore.p12 is updated when present truststore.p12 is updated when present
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Create SONAR_SSL_FOLDER with a file in it (not-truststore.p12) - name: Create SONAR_SSL_FOLDER with a file in it (not-truststore.p12)
@@ -815,9 +910,9 @@ jobs:
scannerVersionValidationTest: scannerVersionValidationTest:
name: > name: >
'scannerVersion' input validation 'scannerVersion' input validation
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run action with invalid scannerVersion - name: Run action with invalid scannerVersion

View File

@@ -10,9 +10,9 @@ on:
jobs: jobs:
create-install-dir-test: create-install-dir-test:
name: create_install_path.sh name: create_install_path.sh
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
@@ -107,7 +107,7 @@ jobs:
grep "=== Script failed ===" output grep "=== Script failed ===" output
setup-script-test: setup-script-test:
name: configure_paths.sh name: configure_paths.sh
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
env: env:
INSTALL_PATH: 'install-directory' INSTALL_PATH: 'install-directory'
SONAR_HOST_URL: 'http://sonar-host.com' SONAR_HOST_URL: 'http://sonar-host.com'
@@ -123,7 +123,7 @@ jobs:
SONAR_SCANNER_URL_MACOSX_AARCH64: 'https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-vX.Y.Z.MMMM-macosx-aarch64.zip' SONAR_SCANNER_URL_MACOSX_AARCH64: 'https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-vX.Y.Z.MMMM-macosx-aarch64.zip'
SONAR_SCANNER_SHA_MACOSX_AARCH64: 'DOWNLOAD-SHA-MACOSX-AARCH64' SONAR_SCANNER_SHA_MACOSX_AARCH64: 'DOWNLOAD-SHA-MACOSX-AARCH64'
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
@@ -250,9 +250,9 @@ jobs:
grep "=== Script failed ===" output grep "=== Script failed ===" output
download-script-test: download-script-test:
name: download.sh name: download.sh
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
@@ -319,9 +319,9 @@ jobs:
grep "=== Script failed ===" output grep "=== Script failed ===" output
fetch-latest-version-test: fetch-latest-version-test:
name: fetch_latest_version.sh name: fetch_latest_version.sh
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v5
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Test script - name: Test script

View File

@@ -7,13 +7,13 @@ on:
jobs: jobs:
generate: generate:
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
permissions: permissions:
contents: write contents: write
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v5
- name: Parse semver - name: Parse semver
uses: madhead/semver-utils@36d1e0ed361bd7b4b77665de8093092eaeabe6ba # v4.3.0 uses: madhead/semver-utils@36d1e0ed361bd7b4b77665de8093092eaeabe6ba # v4.3.0

View File

@@ -7,17 +7,15 @@ on:
jobs: jobs:
check-version: check-version:
name: Check for sonar-scanner version update name: Check for sonar-scanner version update
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
outputs: outputs:
should_update: ${{ steps.version-check.outputs.should_update }} should_update: ${{ steps.version-check.outputs.should_update }}
latest_version: ${{ steps.latest-version.outputs.latest }} new-version: ${{ steps.latest-version.outputs.sonar-scanner-version }}
steps: steps:
- run: sudo apt install -y jq - run: sudo apt install -y jq
- run: sudo snap install yq - uses: actions/checkout@v5
- uses: actions/checkout@v4
with: with:
ref: master ref: master
persist-credentials: true
fetch-depth: 0 fetch-depth: 0
- name: "Fetch currently used sonar-scanner version" - name: "Fetch currently used sonar-scanner version"
@@ -30,13 +28,13 @@ jobs:
shell: bash shell: bash
run: | run: |
./scripts/fetch_latest_version.sh > sonar-scanner-version ./scripts/fetch_latest_version.sh > sonar-scanner-version
echo "latest=$(cat sonar-scanner-version)" >> $GITHUB_OUTPUT cat sonar-scanner-version >> $GITHUB_OUTPUT
- name: "Determine if update is needed" - name: "Determine if update is needed"
id: version-check id: version-check
shell: bash shell: bash
run: | run: |
if [[ "${{ steps.tagged-version.outputs.sonar-scanner-version }}" != "${{ steps.latest-version.outputs.latest }}" ]]; then if [[ "${{ steps.tagged-version.outputs.sonar-scanner-version }}" != "${{ steps.latest-version.outputs.sonar-scanner-version }}" ]]; then
echo "should_update=true" >> $GITHUB_OUTPUT echo "should_update=true" >> $GITHUB_OUTPUT
else else
echo "should_update=false" >> $GITHUB_OUTPUT echo "should_update=false" >> $GITHUB_OUTPUT
@@ -45,23 +43,30 @@ jobs:
update-version: update-version:
name: Prepare pull request for sonar-scanner version update name: Prepare pull request for sonar-scanner version update
needs: check-version needs: check-version
runs-on: ubuntu-latest-large runs-on: github-ubuntu-latest-s
permissions: permissions:
contents: write contents: write
pull-requests: write pull-requests: write
if: needs.check-version.outputs.should_update == 'true' if: needs.check-version.outputs.should_update == 'true'
steps: steps:
- uses: actions/checkout@v5
with:
ref: master
persist-credentials: true
fetch-depth: 0
- run: sudo snap install yq
- name: "Update default version" - name: "Update default version"
shell: bash shell: bash
env: env:
NEW_VERSION: ${{ needs.check-version.outputs.latest-version }} NEW_VERSION: ${{ needs.check-version.outputs.new-version }}
run: | run: |
yq -i '.inputs.scannerVersion.default = strenv(NEW_VERSION)' action.yml yq -i '.inputs.scannerVersion.default = strenv(NEW_VERSION)' action.yml
./scripts/fetch_latest_version.sh > sonar-scanner-version
- name: "Create Pull Request for version update" - name: "Create Pull Request for version update"
shell: bash shell: bash
env: env:
UPDATE_BRANCH: update-to-sonar-scanner-${{ needs.check-version.outputs.latest-version }} UPDATE_BRANCH: update-to-sonar-scanner-${{ needs.check-version.outputs.new-version }}
TITLE: "Update SonarScanner CLI to ${{ needs.check-version.outputs.latest-version }}" TITLE: "Update SonarScanner CLI to ${{ needs.check-version.outputs.new-version }}"
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
git config --global user.name "SonarTech" git config --global user.name "SonarTech"
@@ -74,5 +79,5 @@ jobs:
gh pr list gh pr list
if [[ $(gh pr list -H "${UPDATE_BRANCH}" | grep "${UPDATE_BRANCH}" | wc -l) -eq 0 ]]; then if [[ $(gh pr list -H "${UPDATE_BRANCH}" | grep "${UPDATE_BRANCH}" | wc -l) -eq 0 ]]; then
gh pr create -B master -H ${UPDATE_BRANCH} --title "${TITLE}" --body "Automatic updated of sonar-scanner version value. Needs to be tagged for release." gh pr create -B master -H ${UPDATE_BRANCH} --title "${TITLE}" --body "Automatic update of the sonar-scanner version value. Be sure to trigger the QA workflow by closing and reopening this PR (see https://github.com/orgs/community/discussions/65321)."
fi fi

View File

@@ -33,7 +33,7 @@ runs:
INPUT_SCANNERVERSION: ${{ inputs.scannerVersion }} INPUT_SCANNERVERSION: ${{ inputs.scannerVersion }}
- name: Load Sonar Scanner CLI from cache - name: Load Sonar Scanner CLI from cache
id: sonar-scanner-cli id: sonar-scanner-cli
uses: actions/cache@v4 uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 #v4.2.4
env: env:
# The default value is 60mins. Reaching timeout is treated the same as a cache miss. # The default value is 60mins. Reaching timeout is treated the same as a cache miss.
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1 SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1
@@ -51,11 +51,19 @@ runs:
run: echo "${RUNNER_TEMP}/sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }}/bin" >> $GITHUB_PATH run: echo "${RUNNER_TEMP}/sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }}/bin" >> $GITHUB_PATH
shell: bash shell: bash
- name: Run SonarScanner - name: Run SonarScanner
run: | uses: satackey/action-js-inline@v0.0.2
args=(${{ inputs.args }}) with:
cmd=(${GITHUB_ACTION_PATH}/scripts/run-sonar-scanner-cli.sh "${args[@]}") required-packages: "string-argv"
"${cmd[@]}" script: |
shell: bash const core = require('@actions/core')
const exec = require('@actions/exec')
const { parseArgsStringToArgv } = require('string-argv');
const IS_WINDOWS = process.platform === 'win32'
const runnerTemp = process.env.RUNNER_TEMP
var args = parseArgsStringToArgv(core.getInput('args'));
exec.exec(IS_WINDOWS ? 'sonar-scanner.bat' : 'sonar-scanner', args);
env: env:
INPUT_PROJECTBASEDIR: ${{ inputs.projectBaseDir }} INPUT_ARGS: ${{ inputs.args }}
SONAR_SCANNER_JRE: ${{ runner.temp }}/sonar-scanner-cli-${{ inputs.scannerVersion }}-${{ runner.os }}-${{ runner.arch }}/jre

View File

@@ -28,7 +28,7 @@ parse_arguments() {
} }
verify_download_correctness() { verify_download_correctness() {
echo "${EXPECTED_SHA} ${TMP_ZIP_PATH}" | sha256sum -c echo "${EXPECTED_SHA} ${TMP_ZIP_PATH}" | sha256sum -c -
check_status "Checking sha256 failed" check_status "Checking sha256 failed"
} }

View File

@@ -73,7 +73,17 @@ if [[ -n "${SONAR_ROOT_CERT}" ]]; then
scanner_args+=("-Dsonar.scanner.truststorePassword=$SONAR_SSL_TRUSTSTORE_PASSWORD") scanner_args+=("-Dsonar.scanner.truststorePassword=$SONAR_SSL_TRUSTSTORE_PASSWORD")
fi fi
scanner_args+=("$@") # split input args correctly (passed through INPUT_ARGS env var to avoid execution of injected command)
args=()
if [[ -n "${INPUT_ARGS}" ]]; then
# the regex recognizes args with values in single or double quotes (without character escaping), and args without quotes as well
# more specifically, the following patterns: -Darg="value", -Darg='value', -Darg=value, "-Darg=value" and '-Darg=value'
IFS=$'\n'; args=($(echo ${INPUT_ARGS} | egrep -o '[^" '\'']+="[^"]*"|[^" '\'']+='\''[^'\'']*'\''|[^" '\'']+|"[^"]+"|'\''[^'\'']+'\'''))
fi
for arg in "${args[@]}"; do
scanner_args+=("$arg")
done
set -ux set -ux

6
scripts/run-sonar-scanner.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
# run the sonar scanner cli
cmd=(${GITHUB_ACTION_PATH}/scripts/run-sonar-scanner-cli.sh "${INPUT_ARGS}")
"${cmd[@]}"