Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
yml 103 lines 3.83 KB
Raw
1 name: Secrets Detection
2
3 on:
4 pull_request:
5 types: [opened, synchronize, reopened]
6 branches:
7 - master
8 - next
9 - main
10
11 permissions:
12 contents: read
13
14 jobs:
15 secrets:
16 name: Detect Secrets (GitHub Advanced Security)
17 runs-on: ubuntu-latest
18 permissions:
19 contents: read
20 pull-requests: write
21 issues: write
22 security-events: write
23
24 steps:
25 - name: Check for secret scanning alerts
26 id: secret-scan
27 uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
28 with:
29 github-token: ${{ secrets.GITHUB_TOKEN }}
30 script: |
31 const prNumber = context.payload.pull_request?.number;
32 if (!prNumber) {
33 core.info('Not a PR event, skipping secret scanning alert check.');
34 return;
35 }
36
37 try {
38 const { data: alerts } = await github.rest.secretScanning.listAlertsForRepo({
39 owner: context.repo.owner,
40 repo: context.repo.repo,
41 state: 'open',
42 per_page: 100,
43 });
44
45 if (alerts.length > 0) {
46 core.setOutput('secrets_found', 'true');
47 core.setOutput('alert_count', alerts.length.toString());
48 core.setFailed(
49 `Found ${alerts.length} open secret scanning alert(s). ` +
50 `Review them at https://github.com/${context.repo.owner}/${context.repo.repo}/security/secret-scanning`
51 );
52 } else {
53 core.info('No open secret scanning alerts found.');
54 core.setOutput('secrets_found', 'false');
55 }
56 } catch (error) {
57 if (error.status === 404 || error.status === 403) {
58 core.warning(
59 'GitHub Advanced Security secret scanning is not accessible. ' +
60 'Ensure it is enabled and the workflow has security-events permission.'
61 );
62 } else {
63 throw error;
64 }
65 }
66
67 - name: Comment on PR if secrets found
68 if: failure() && steps.secret-scan.outputs.secrets_found == 'true'
69 uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
70 with:
71 github-token: ${{ secrets.GITHUB_TOKEN }}
72 script: |
73 const alertCount = '${{ steps.secret-scan.outputs.alert_count }}';
74 const prNumber = context.payload.pull_request?.number;
75 if (!prNumber) return;
76
77 await github.rest.issues.createComment({
78 owner: context.repo.owner,
79 repo: context.repo.repo,
80 issue_number: prNumber,
81 body: `## :warning: Secrets Detection Alert
82
83 **${alertCount} open secret scanning alert(s) detected by GitHub Advanced Security.**
84
85 Review and resolve them at https://github.com/${context.repo.owner}/${context.repo.repo}/security/secret-scanning before merging.
86
87 cc: @${context.actor}`,
88 });
89
90 - name: Notify Slack if secrets are found
91 if: failure() && steps.secret-scan.outputs.secrets_found == 'true'
92 uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
93 with:
94 webhook: ${{ secrets.SLACK_TECH_WEBHOOK }}
95 webhook-type: incoming-webhook
96 payload: |
97 text: |
98 :rotating_light: Secrets detected in ${{ github.repository }}
99 Branch: ${{ github.head_ref || github.ref_name }}
100 Author: ${{ github.actor }}
101 Alerts: ${{ steps.secret-scan.outputs.alert_count }}
102 Review: https://github.com/${{ github.repository }}/security/secret-scanning
103 Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}