Skip to content

Commit d86373f

Browse files
committed
feat(sonar): Add analyze workflow for quality gate approval
It relies on project env var for setting host and secret for token Origin: SiliconLabsSoftware/z-wave-engine-application-layer#73 Relate-to: #100 (cherry picked from commit cbd57b4cbc041bd66c9c76c868711df6b0f8dd6e) Forwarded: #134 Signed-off-by: Philippe Coval <[email protected]>
1 parent 2ea468f commit d86373f

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

.github/workflows/analyze.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# YAML -*- mode: yaml; tab-width: 2; indent-tabs-mode: nil; coding: utf-8 -*-
2+
# SPDX-License-Identifier: Zlib
3+
# SPDX-FileCopyrightText: Silicon Laboratories Inc. https://www.silabs.com
4+
---
5+
6+
name: analyze
7+
8+
# yamllint disable-line rule:line-length
9+
run-name: "analyze: ${{ github.event.workflow_run.head_branch }}#${{ github.event.workflow_run.head_commit.id }}"
10+
11+
on: # yamllint disable-line rule:truthy
12+
workflow_run:
13+
workflows: ["build"]
14+
types:
15+
- completed
16+
17+
jobs:
18+
test:
19+
permissions:
20+
contents: read
21+
statuses: write
22+
env:
23+
SONAR_OUT_DIR: sonar
24+
runs-on: ${{ vars.RUNNER || 'ubuntu-24.04' }}
25+
# yamllint disable-line rule:line-length
26+
if: ${{ vars.SONAR_HOST_URL && github.event.workflow_run.conclusion == 'success' }}
27+
steps:
28+
- id: download
29+
name: Download analyze artifacts
30+
# yamllint disable-line rule:line-length
31+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
32+
with:
33+
# yamllint disable-line rule:line-length
34+
name: ${{ github.event.repository.name }}-analyze
35+
github-token: ${{ secrets.GH_SL_ACCESS_TOKEN }}
36+
run-id: ${{ github.event.workflow_run.id }}
37+
38+
- name: Extract sonar files
39+
env:
40+
# yamllint disable-line rule:line-length
41+
file: ${{ steps.download.outputs.download-path }}/${{ env.SONAR_OUT_DIR }}/dist.tar.gz
42+
run: |
43+
set -x
44+
tar xfva ${{ env.file }}
45+
rm -f ${{ env.file }}
46+
47+
# Check the Quality Gate status.
48+
- name: SonarQube Quality Gate check
49+
id: sonarqube-quality-gate-check
50+
# yamllint disable-line rule:line-length
51+
uses: sonarsource/sonarqube-quality-gate-action@cf038b0e0cdecfa9e56c198bbb7d21d751d62c3b # v1.2.0
52+
env:
53+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
54+
SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }}
55+
if: ${{ env.SONAR_HOST_URL }}
56+
57+
- name: Propagate status on fail
58+
# yamllint disable-line rule:line-length
59+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
60+
if: failure()
61+
env:
62+
status: ${{ steps.sonarqube-quality-gate-check.outcome }}
63+
sha: ${{ github.event.workflow_run.head_commit.id }}
64+
with:
65+
script: |
66+
await github.rest.repos.createCommitStatus({
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
sha: process.env.sha,
70+
state: 'failure'
71+
})
72+
core.setFailed(`Status: ${process.env.status}`);

0 commit comments

Comments
 (0)