Skip to content

Commit 449846d

Browse files
committed
refactor(ci): simplify sonar and schema-linter fork safety
Replace the broken org membership check in sonar.yml with the standard fork-safety pattern (skip fork PRs via head.repo.full_name check). The old check used exit 0 which didn't actually skip subsequent steps, and fork PRs can't access secrets regardless. Simplify schema-linter.yml fork conditional to the same pattern. Also removes the broken "Display Quality gate result" step that referenced a nonexistent step ID (sonarqube-result-front). Relates to #411
1 parent 7abfa1b commit 449846d

2 files changed

Lines changed: 8 additions & 36 deletions

File tree

.github/workflows/schema-linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
run:
1919
runs-on: ubuntu-22.04
2020
name: Lint WPGraphQL Schema
21-
if: contains(github.event.pull_request.labels.*.name, 'safe to test ✔') || github.repository == github.event.repository.full_name || github.event_name == 'push'
21+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
2222

2323
services:
2424
mariadb:

.github/workflows/sonar.yml

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,22 @@
11
on:
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

98
name: SonarQube Analysis
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
1014
jobs:
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@v7
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
@@ -54,13 +30,9 @@ jobs:
5430

5531
- name: SonarQube Quality Gate check
5632
uses: sonarsource/sonarqube-quality-gate-action@v1
57-
# Force to fail step after specific time
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

Comments
 (0)