sonar correct analysisId #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and SonarQube Analysis | |
on: | |
pull_request: | |
branches: | |
- dev | |
- main | |
push: | |
branches: | |
- dev | |
- main | |
jobs: | |
build-and-test: | |
runs-on: macos-latest | |
env: | |
PORT: 4201 | |
APP_PORT: 4200 | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Set Up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20.16.0 | |
- name: Install Dependencies | |
run: | | |
echo "\nInstalling dependencies\n\n" | |
npm ci | |
- name: Run Translation Validation | |
run: | | |
echo "\nRunning translation validation\n\n" | |
cd tests/translation && npx ts-node translation-validation.ts | |
- name: Build the Client | |
run: | | |
echo "\nBuilding the client\n\n" | |
cd client && npm run build | |
- name: Run Server Tests | |
run: | | |
echo "\nRunning server tests\n\n" | |
cd server && npm test | |
- name: Run Client Tests | |
run: | | |
echo "\nRunning client tests\n\n" | |
cd client && npm test | |
# #e2e Tests | |
# TODO uncomment once testcafe works with chrome latest | |
# - name: Start Angular server | |
# run: npm run prod & | |
# - name: Wait for Angular server to start | |
# run: | | |
# until curl --output /dev/null --silent --head --fail http://localhost:4200; do | |
# echo 'Waiting for Angular server...' | |
# sleep 5 | |
# done | |
# - name: Run E2E Tests | |
# run: | | |
# echo "\nRunning e2e tests\n\n" | |
# cd tests/e2e && node clean_screenshots && node test_runner | |
# - name: Run Screenshot Diff Tests | |
# run: | | |
# echo "\nRunning screenshot diff tests\n\n" | |
# cd tests/e2e && npx testcafe-blink-diff screenshots --compare accepted:tested --open --threshold 0.003 | |
sonarqube: | |
name: SonarQube | |
runs-on: macos-latest | |
needs: build-and-test # Waits for 'build-and-test' to complete | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Disable shallow clone for better analysis relevance | |
- name: Install SonarScanner | |
run: | | |
curl -sSLo sonar-scanner-cli.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.2.1.4610-macosx-aarch64.zip | |
unzip -q sonar-scanner-cli.zip -d $HOME/sonar-scanner | |
echo "$HOME/sonar-scanner/sonar-scanner-6.2.1.4610-macosx-aarch64/bin" >> $GITHUB_PATH | |
- name: Run SonarScanner | |
run: | | |
sonar-scanner \ | |
-Dsonar.projectKey=TheGameKnave_angular-boilerplate \ | |
-Dsonar.organization=thegameknave \ | |
-Dsonar.host.url=https://sonarcloud.io | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
- name: Wait for Quality Gate | |
run: | | |
TASK_ID=$(cat .scannerwork/report-task.txt | grep ceTaskId | cut -d= -f2) | |
echo "Fetching task status... for $TASK_ID" | |
curl -s -u "${{ secrets.SONAR_TOKEN }}:" "https://sonarcloud.io/api/ce/task?id=$TASK_ID" -o task.json | |
echo "Task API Response:" | |
cat task.json | |
STATUS=$(grep -o '"status":"[^"]*"' task.json | cut -d: -f2 | tr -d '"') | |
if [[ "$STATUS" != "SUCCESS" ]]; then | |
echo "Analysis did not complete successfully!" | |
exit 1 | |
fi | |
echo "Fetching Quality Gate status..." | |
ANALYSIS_ID=$(grep -o '"analysisId":"[^"]*"' task.json | cut -d: -f2 | tr -d '"') | |
curl -s -u "${{ secrets.SONAR_TOKEN }}:" "https://sonarcloud.io/api/qualitygates/project_status?analysisId=$ANALYSIS_ID" -o gate.json | |
echo "Quality Gate API Response:" | |
cat gate.json | |
GATE_STATUS=$(jq -r '.projectStatus.status' gate.json) | |
if [[ "$GATE_STATUS" != "OK" ]]; then | |
echo "Quality Gate failed!" | |
exit 1 | |
fi | |
echo "Quality Gate passed successfully!" | |
shell: bash |