@@ -16,17 +16,39 @@ concurrency:
1616 cancel-in-progress : true
1717
1818jobs :
19+ tests-preflight :
20+ name : Preflight Check
21+ runs-on : ubuntu-latest
22+ outputs :
23+ PR_EXISTS : ${{ steps.pr-check.outputs.PR_EXISTS }}
24+ timeout-minutes : 10
25+ permissions :
26+ contents : read
27+ steps :
28+ - name : Short circuit if open PR exists for this branch (on push)
29+ id : pr-check
30+ if : github.event_name == 'push'
31+ env :
32+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
33+ run : |
34+ sleep 10
35+ prs=$(gh pr list --head "${{ github.ref_name }}" --state open --repo "${{ github.repository }}" --json number --jq '.[].number')
36+ if [ -n "$prs" ]; then
37+ echo "PR_EXISTS=true" >> $GITHUB_OUTPUT
38+ else
39+ echo "PR_EXISTS=false" >> $GITHUB_OUTPUT
40+ fi
41+
1942 test-app :
2043 name : Unit Tests (App)
44+ needs : tests-preflight
45+ if : needs.tests-preflight.outputs.PR_EXISTS != 'true'
2146 runs-on : ubuntu-latest
22- if : |
23- github.event_name == 'push' ||
24- (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)
2547 defaults :
2648 run :
2749 working-directory : app
2850 outputs :
29- HAS_CC_SECRETS : ${{ steps.check-secrets.outputs.HAS_CC_SECRETS }}
51+ HAS_SONAR_SECRETS : ${{ steps.check-secrets.outputs.HAS_SONAR_SECRETS }}
3052 timeout-minutes : 10
3153 strategy :
3254 fail-fast : true
@@ -37,10 +59,10 @@ jobs:
3759 steps :
3860 - name : Checkout Repository
3961 uses : actions/checkout@v4
40- - name : Check CodeClimate Secrets
62+ - name : Check Sonar Secrets
4163 id : check-secrets
4264 run : |
43- echo "HAS_CC_SECRETS =${{ secrets.CC_TEST_REPORTER_ID != '' }}" >> $GITHUB_OUTPUT
65+ echo "HAS_SONAR_SECRETS =${{ secrets.SONAR_TOKEN_APP != '' }}" >> $GITHUB_OUTPUT
4466 - name : Use Node.js ${{ matrix.node-version }}
4567 uses : actions/setup-node@v4
4668 with :
7496 path : ${{ github.workspace }}/app/coverage
7597 retention-days : 1
7698 - name : Monitor Coverage
77- if : " matrix.node-version == '22.x' && ! github.event.pull_request.head.repo.fork"
78- uses : slavcodev/coverage-monitor-action@v1
99+ if : " matrix.node-version == '22.x' && github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork"
100+ uses : slavcodev/coverage-monitor-action@398c4cbbb710e549a8407fdef96ae8b9454d0463 # 1.10.0
79101 with :
80102 comment_mode : update
81103 comment_footer : false
@@ -87,15 +109,14 @@ jobs:
87109
88110 test-frontend :
89111 name : Unit Tests (Frontend)
112+ needs : tests-preflight
113+ if : needs.tests-preflight.outputs.PR_EXISTS != 'true'
90114 runs-on : ubuntu-latest
91- if : |
92- github.event_name == 'push' ||
93- (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)
94115 defaults :
95116 run :
96117 working-directory : frontend
97118 outputs :
98- HAS_CC_SECRETS : ${{ steps.check-secrets.outputs.HAS_CC_SECRETS }}
119+ HAS_SONAR_SECRETS : ${{ steps.check-secrets.outputs.HAS_SONAR_SECRETS }}
99120 timeout-minutes : 10
100121 strategy :
101122 fail-fast : true
@@ -106,10 +127,10 @@ jobs:
106127 steps :
107128 - name : Checkout Repository
108129 uses : actions/checkout@v4
109- - name : Check CodeClimate Secrets
130+ - name : Check Sonar Secrets
110131 id : check-secrets
111132 run : |
112- echo "HAS_CC_SECRETS =${{ secrets.CC_TEST_REPORTER_ID != '' }}" >> $GITHUB_OUTPUT
133+ echo "HAS_SONAR_SECRETS =${{ secrets.SONAR_TOKEN_FRONTEND != '' }}" >> $GITHUB_OUTPUT
113134 - name : Use Node.js ${{ matrix.node-version }}
114135 uses : actions/setup-node@v4
115136 with :
@@ -141,8 +162,8 @@ jobs:
141162 path : ${{ github.workspace }}/frontend/coverage
142163 retention-days : 1
143164 - name : Monitor Coverage
144- if : " matrix.node-version == '22.x' && ! github.event.pull_request.head.repo.fork"
145- uses : slavcodev/coverage-monitor-action@v1
165+ if : " matrix.node-version == '22.x' && github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork"
166+ uses : slavcodev/coverage-monitor-action@398c4cbbb710e549a8407fdef96ae8b9454d0463 # 1.10.0
146167 with :
147168 comment_mode : update
148169 comment_footer : false
@@ -152,24 +173,50 @@ jobs:
152173 threshold_alert : 50
153174 threshold_warning : 80
154175
155- test-coverage :
156- name : Publish to Code Climate
176+ test-coverage-app :
177+ name : Publish App Coverage to SonarCloud
157178 needs :
158179 - test-app
180+ if : needs.test-app.outputs.HAS_SONAR_SECRETS == 'true'
181+ runs-on : ubuntu-latest
182+ timeout-minutes : 10
183+ permissions :
184+ contents : read
185+ steps :
186+ - name : Checkout Repository
187+ uses : actions/checkout@v4.2.2
188+ - name : Restore Coverage Results
189+ uses : actions/download-artifact@v4.3.0
190+ with :
191+ name : coverage-app
192+ path : ${{ github.workspace }}/app/coverage
193+ - name : SonarCloud Scan
194+ uses : SonarSource/sonarqube-scan-action@8c71dc039c2dd71d3821e89a2b58ecc7fee6ced9 # v5.3.0
195+ env :
196+ SONAR_TOKEN : ${{ secrets.SONAR_TOKEN_APP }}
197+ with :
198+ projectBaseDir : app
199+
200+ test-coverage-frontend :
201+ name : Publish Frontend Coverage to SonarCloud
202+ needs :
159203 - test-frontend
160- if : needs.test-app .outputs.HAS_CC_SECRETS == 'true'
204+ if : needs.test-frontend .outputs.HAS_SONAR_SECRETS == 'true'
161205 runs-on : ubuntu-latest
162206 timeout-minutes : 10
207+ permissions :
208+ contents : read
163209 steps :
164210 - name : Checkout Repository
165- uses : actions/checkout@v4
211+ uses : actions/checkout@v4.2.2
166212 - name : Restore Coverage Results
167- uses : actions/download-artifact@v4
168- - name : Publish code coverage
169- uses : paambaati/codeclimate-action@v9
213+ uses : actions/download-artifact@v4.3.0
214+ with :
215+ name : coverage-frontend
216+ path : ${{ github.workspace }}/frontend/coverage
217+ - name : SonarCloud Scan
218+ uses : SonarSource/sonarqube-scan-action@8c71dc039c2dd71d3821e89a2b58ecc7fee6ced9 # v5.3.0
170219 env :
171- CC_TEST_REPORTER_ID : ${{ secrets.CC_TEST_REPORTER_ID }}
220+ SONAR_TOKEN : ${{ secrets.SONAR_TOKEN_FRONTEND }}
172221 with :
173- coverageLocations : |
174- ${{ github.workspace }}/**/lcov.info:lcov
175- prefix : ${{ github.workplace }}
222+ projectBaseDir : frontend
0 commit comments