|
6 | 6 |
|
7 | 7 | jobs: |
8 | 8 | precheck: |
| 9 | + if: ${{ github.repository == 'PaloAltoNetworks/docusaurus-openapi-docs' }} |
9 | 10 | name: Precheck |
10 | 11 | runs-on: ubuntu-latest |
11 | 12 | permissions: |
12 | 13 | contents: read |
13 | | - security-events: write |
14 | 14 | outputs: |
15 | 15 | is-org-member-result: ${{ steps.is-org-member.outputs.is-org-member-result }} |
16 | 16 | steps: |
17 | 17 | - name: Check if actor is org member |
18 | 18 | id: is-org-member |
19 | | - run: echo "is-org-member-result=$(gh api -X GET orgs/PaloAltoNetworks/memberships/${{ github.actor }} | jq -r .message)" >> "$GITHUB_OUTPUT" |
20 | | - env: |
21 | | - GH_TOKEN: ${{ secrets.PAT }} |
| 19 | + run: | |
| 20 | + status=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer $GH_TOKEN" \ |
| 21 | + https://api.github.com/orgs/PaloAltoNetworks/members/${{ github.actor }}) |
| 22 | + if [ "$status" = "204" ]; then |
| 23 | + echo "is-org-member-result=true" >> "$GITHUB_OUTPUT" |
| 24 | + else |
| 25 | + echo "is-org-member-result=false" >> "$GITHUB_OUTPUT" |
| 26 | + fi |
| 27 | + env: |
| 28 | + GH_TOKEN: ${{ secrets.PAT }} |
22 | 29 |
|
23 | 30 | analyze: |
24 | | - if: github.repository_owner == 'PaloAltoNetworks' && needs.precheck.outputs.is-org-member-result == 'null' |
| 31 | + if: github.repository == 'PaloAltoNetworks/docusaurus-openapi-docs' && needs.precheck.outputs.is-org-member-result == 'true' |
25 | 32 | name: Analyze |
26 | 33 | needs: precheck |
27 | 34 | runs-on: ubuntu-latest |
|
49 | 56 | uses: github/codeql-action/analyze@1b549b9259bda1cb5ddde3b41741a82a2d15a841 # v3 |
50 | 57 |
|
51 | 58 | analyze_unsafe: |
52 | | - if: github.repository_owner == 'PaloAltoNetworks' && needs.precheck.outputs.is-org-member-result != 'null' |
| 59 | + if: github.repository == 'PaloAltoNetworks/docusaurus-openapi-docs' && needs.precheck.outputs.is-org-member-result == 'false' |
53 | 60 | name: Analyze Unsafe |
54 | 61 | needs: precheck |
55 | 62 | runs-on: ubuntu-latest |
|
81 | 88 | name: Build |
82 | 89 | needs: [analyze, analyze_unsafe] |
83 | 90 | if: | |
84 | | - !failure() && !cancelled() && |
| 91 | + github.repository == 'PaloAltoNetworks/docusaurus-openapi-docs' && |
| 92 | + !failure() && !cancelled() && |
85 | 93 | (success('analyze') || success('analyze_unsafe')) |
86 | 94 | runs-on: ubuntu-latest |
87 | 95 | permissions: |
@@ -116,8 +124,14 @@ jobs: |
116 | 124 | deploy: |
117 | 125 | name: Deploy |
118 | 126 | needs: build |
119 | | - if: ${{ !failure() && !cancelled() }} |
| 127 | + if: ${{ github.repository == 'PaloAltoNetworks/docusaurus-openapi-docs' && !failure() && !cancelled() }} |
120 | 128 | runs-on: ubuntu-latest |
| 129 | + permissions: |
| 130 | + contents: read |
| 131 | + pull-requests: write |
| 132 | + checks: write |
| 133 | + outputs: |
| 134 | + preview_url: ${{ steps.deploy_preview.outputs.details_url }} |
121 | 135 |
|
122 | 136 | steps: |
123 | 137 | - name: Checkout repository |
@@ -147,3 +161,66 @@ jobs: |
147 | 161 | channelId: "pr${{ github.event.number }}" |
148 | 162 | env: |
149 | 163 | FIREBASE_CLI_PREVIEWS: hostingchannels |
| 164 | + |
| 165 | + visual_diff: |
| 166 | + name: Visual Diff |
| 167 | + needs: deploy |
| 168 | + if: ${{ github.repository == 'PaloAltoNetworks/docusaurus-openapi-docs' && !failure() && !cancelled() }} |
| 169 | + runs-on: ubuntu-latest |
| 170 | + permissions: |
| 171 | + contents: read |
| 172 | + |
| 173 | + steps: |
| 174 | + - name: Checkout repository |
| 175 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 176 | + with: |
| 177 | + ref: ${{ github.event.pull_request.head.sha }} |
| 178 | + |
| 179 | + - name: Setup node |
| 180 | + uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4 |
| 181 | + with: |
| 182 | + node-version: "20" |
| 183 | + cache: "yarn" |
| 184 | + |
| 185 | + - name: Install dependencies |
| 186 | + run: yarn --prefer-offline |
| 187 | + |
| 188 | + - name: Install Playwright |
| 189 | + run: npx playwright install --with-deps chromium |
| 190 | + |
| 191 | + - name: Run visual diff |
| 192 | + run: yarn ts-node scripts/sitemap-visual-diff.ts --preview-url ${{ needs.deploy.outputs.preview_url }} --summary-file visual_diffs/results.json --concurrency 4 --paths "/tests/" |
| 193 | + |
| 194 | + - name: Generate report and summary |
| 195 | + run: yarn ts-node scripts/generate-visual-diff-report.ts visual_diffs/results.json visual_diffs/index.html |
| 196 | + |
| 197 | + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 |
| 198 | + if: always() |
| 199 | + with: |
| 200 | + name: visual_diffs |
| 201 | + path: visual_diffs |
| 202 | + |
| 203 | + # - name: Comment PR with results |
| 204 | + # if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' |
| 205 | + # uses: actions/github-script@v7 |
| 206 | + # with: |
| 207 | + # github-token: ${{ secrets.GITHUB_TOKEN }} |
| 208 | + # script: | |
| 209 | + # const fs = require('fs'); |
| 210 | + # const results = JSON.parse(fs.readFileSync('visual_diffs/results.json', 'utf8')); |
| 211 | + # const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`; |
| 212 | + # let body = `### Visual Diff Summary\n\n[View Logs](${runUrl})\n\n`; |
| 213 | + # body += `Total: ${results.summary.total}, Matches: ${results.summary.matches}, Diffs: ${results.summary.mismatches}, Skipped: ${results.summary.skipped}\n\n`; |
| 214 | + # if (results.pages.length) { |
| 215 | + # body += '| Page | Status |\n| --- | --- |\n'; |
| 216 | + # for (const p of results.pages) { |
| 217 | + # if (p.status !== 'match') { |
| 218 | + # body += `| ${p.path} | ${p.status} |\n`; |
| 219 | + # } |
| 220 | + # } |
| 221 | + # } |
| 222 | + # await github.rest.issues.createComment({ |
| 223 | + # ...context.repo, |
| 224 | + # issue_number: context.issue.number, |
| 225 | + # body |
| 226 | + # }); |
0 commit comments