11on :
2- # Trigger analysis when pushing to main or pull requests, and when creating a pull request.
32 push :
43 branches :
54 - main
65 pull_request :
76 types : [opened, synchronize, reopened]
87
98name : SonarQube Analysis
9+
10+ concurrency :
11+ group : ${{ github.workflow }}-${{ github.ref }}
12+ cancel-in-progress : true
13+
1014jobs :
1115 sonarqube :
16+ # Only run for pushes or same-repo PRs (fork PRs can't access secrets)
17+ if : github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
1218 runs-on : ubuntu-22.04
1319 steps :
14- - name : Check if PR author is an org member
15- id : check-member
16- uses : actions/github-script@v6.3.0 # Updated version to support Node 20
17- with :
18- script : |
19- const org = 'wpengine';
20- const username = context.payload.pull_request.user.login;
21-
22- try {
23- const { data: membership } = await github.rest.orgs.getMembershipForUser({
24- org,
25- username,
26- });
27- console.log({ username, membership });
28- return { isMember: membership.state === 'active' };
29- } catch (error) {
30- console.log(`Error checking membership: ${error}`);
31- return { isMember: false }; // Treat as not a member if any error occurs
32- }
33- env :
34- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
35-
36- # Set an output for the job based on the result of the membership check
37- - name : Set output for isMember
38- run : echo "isMember=${{ steps.check-member.outputs.isMember }}" >> $GITHUB_ENV
39-
40- - name : Skip if not an org member
41- if : env.isMember == 'false'
42- run : echo "Skipping workflow because PR author is not an org member" && exit 0
43-
4420 - uses : actions/checkout@v4
4521 with :
4622 # Disabling shallow clone is recommended for improving relevancy of reporting
4723 fetch-depth : 0
4824
4925 - name : SonarQube Scan
50- uses : sonarsource/sonarqube-scan-action@master
26+ uses : sonarsource/sonarqube-scan-action@v4
5127 env :
5228 SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
5329 SONAR_HOST_URL : ${{ secrets.SONAR_HOST_URL }}
5430
5531 - name : SonarQube Quality Gate check
56- uses : sonarsource/sonarqube-quality-gate-action@master
57- # Force to fail step after specific time
32+ uses : sonarsource/sonarqube-quality-gate-action@v1
5833 timeout-minutes : 5
5934 env :
6035 SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
6136 SONAR_HOST_URL : ${{ secrets.SONAR_HOST_URL }}
6237 with :
6338 scanMetadataReportFile : .scannerwork/report-task.txt
64-
65- - name : " Display Quality gate result"
66- run : echo "Front Quality Gate status ${{ toJSON(steps.sonarqube-result-front) }}"
0 commit comments