Skip to content

Commit 6fef4ee

Browse files
committed
test secrets on branch
1 parent 9e0eaa6 commit 6fef4ee

1 file changed

Lines changed: 85 additions & 16 deletions

File tree

Lines changed: 85 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,101 @@
11
name: SonarCloud code analysis
22

3-
on:
4-
workflow_run:
5-
workflows: [ "Maven build" ]
6-
types: [ completed ]
3+
on: [push]
74

85
jobs:
96
analyze:
107
name: Analyze
11-
if: >
12-
github.repository == 'svenzik/wallet' &&
13-
github.event.workflow_run.conclusion == 'success'
14-
runs-on: ubuntu-latest
8+
runs-on: windows-latest
159

1610
steps:
11+
- name: Unset CACHE_VERSION
12+
shell: powershell
13+
run: |
14+
Remove-Item Env:CACHE_VERSION -ErrorAction SilentlyContinue
15+
Write-Host "CACHE_VERSION has been unset"
16+
1717
- uses: actions/checkout@v4
1818
with:
19-
repository: ${{ github.event.workflow_run.head_repository.full_name }}
20-
ref: ${{ github.event.workflow_run.head_branch }}
2119
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
22-
- name: Set up JDK 17
23-
uses: actions/setup-java@v3
20+
21+
- name: Setup dotnet
22+
uses: actions/setup-dotnet@v4
23+
with:
24+
dotnet-version: 9.0.x # SDK Version to use.
25+
26+
- name: Set up JDK 21
27+
uses: actions/setup-java@v4
2428
with:
25-
distribution: zulu
26-
java-version: 17
29+
distribution: temurin
30+
java-version: 21
31+
32+
- name: Test SonarCloud API with Bearer Token
33+
shell: powershell
34+
run: |
35+
$uri = 'https://sonarcloud.io/api/settings/values?component=unknown'
36+
$headers = @{
37+
'Authorization' = 'Bearer ${{ secrets.SONAR_TOKEN }}'
38+
}
39+
try {
40+
$response = Invoke-WebRequest -Uri $uri -Headers $headers -Method Get -UseBasicParsing
41+
Write-Host "HTTP Status Code: $($response.StatusCode)"
42+
Write-Host "Token-Expiration: $($response.Headers['SonarQube-Authentication-Token-Expiration'])"
43+
}
44+
catch {
45+
$statusCode = $_.Exception.Response.StatusCode.value__
46+
Write-Host "HTTP Status Code: $statusCode"
47+
Write-Host "Error: $($_.Exception.Message)"
48+
Write-Host "Token-Expiration: $($_.Exception.Response.Headers['SonarQube-Authentication-Token-Expiration'])"
49+
}
50+
51+
- name: Test SonarCloud API with Basic
52+
shell: powershell
53+
run: |
54+
$uri = 'https://sonarcloud.io/api/settings/values?component=unknown'
55+
$token = '${{ secrets.SONAR_TOKEN }}'
56+
$encodedCreds = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${token}:"))
57+
$headers = @{
58+
'Authorization' = "Basic $encodedCreds"
59+
}
60+
try {
61+
$response = Invoke-WebRequest -Uri $uri -Headers $headers -Method Get -UseBasicParsing
62+
Write-Host "HTTP Status Code: $($response.StatusCode)"
63+
Write-Host "Token-Expiration: $($response.Headers['SonarQube-Authentication-Token-Expiration'])"
64+
}
65+
catch {
66+
$statusCode = $_.Exception.Response.StatusCode.value__
67+
Write-Host "HTTP Status Code: $statusCode"
68+
Write-Host "Error: $($_.Exception.Message)"
69+
Write-Host "Token-Expiration: $($_.Exception.Response.Headers['SonarQube-Authentication-Token-Expiration'])"
70+
}
71+
72+
- name: Install SonarCloud scanner
73+
shell: powershell
74+
run: |
75+
dotnet tool install --global dotnet-sonarscanner
76+
2777
- name: Build and analyze
2878
env:
2979
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
3080
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
31-
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
32-
81+
REPO_SONAR_TOKEN: ${{ secrets.REPO_SONAR_TOKEN }}
82+
shell: powershell
83+
run: |
84+
if ("${{ secrets.SONAR_TOKEN }}" -eq "") {
85+
Write-Host "SONAR_TOKEN is missing"
86+
} else {
87+
Write-Host "SONAR_TOKEN is available -8 (length: $('${{ secrets.SONAR_TOKEN }}'.Length))"
88+
}
89+
if ("${{ secrets.TEST_ENVIR_SONAR_TOKEN }}" -eq "") {
90+
Write-Host "TEST_ENVIR_SONAR_TOKEN is missing"
91+
} else {
92+
Write-Host "TEST_ENVIR_SONAR_TOKEN is available -8 (length: $('${{ secrets.TEST_ENVIR_SONAR_TOKEN }}'.Length))"
93+
}
94+
if ("${{ secrets.REPO_SONAR_TOKEN }}" -eq "") {
95+
Write-Host "REPO_SONAR_TOKEN is missing"
96+
} else {
97+
Write-Host "REPO_SONAR_TOKEN is available -8 (length: $('${{ secrets.REPO_SONAR_TOKEN }}'.Length))"
98+
}
99+
Write-Output 'dotnet sonarscanner begin /k:"prj" /o:"org" /d:sonar.token="${{ secrets.REPO_SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.verbose=true /d:sonar.branch.name="${{ github.ref_name }}"'
100+
Write-Output 'dotnet sonarscanner begin /k:"prj" /o:"org" /d:sonar.token="$env:REPO_SONAR_TOKEN" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.verbose=true /d:sonar.branch.name="${{ github.ref_name }}"'
101+
Write-Output "dotnet sonarscanner begin /k:`"prj`" /o:`"org`" /d:sonar.token=`"$env:REPO_SONAR_TOKEN`" /d:sonar.host.url=`"https://sonarcloud.io`" /d:sonar.verbose=true /d:sonar.branch.name=`"${{ github.ref_name }}`""

0 commit comments

Comments
 (0)