Skip to content

Commit eacfe7c

Browse files
authored
Add GitHub Actions workflow for secret scanning and release
1 parent 99d8d0d commit eacfe7c

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

.github/workflows/main.yml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: Secret Scanning & Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: write # needed for tags + releases
13+
id-token: write
14+
issues: write
15+
pull-requests: write
16+
17+
jobs:
18+
trufflehog:
19+
runs-on: ubuntu-latest
20+
env:
21+
TRUFFLEHOG_VERSION: v3.76.0
22+
defaults:
23+
run:
24+
shell: bash
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
32+
- name: TruffleHog OSS
33+
id: trufflehog
34+
uses: trufflesecurity/[email protected]
35+
continue-on-error: true
36+
with:
37+
path: ./
38+
base: ${{ github.event.repository.default_branch }}
39+
head: HEAD
40+
extra_args: --debug --only-verified
41+
42+
# --- Notifications on failure ---
43+
44+
- name: Notify on PR (comment)
45+
if: steps.trufflehog.outcome == 'failure' && github.event_name == 'pull_request'
46+
uses: actions/github-script@v7
47+
with:
48+
github-token: ${{ secrets.GITHUB_TOKEN }}
49+
script: |
50+
const pr = context.payload.pull_request;
51+
const body = [
52+
'🚨 **TruffleHog secret scan failed**',
53+
'',
54+
`- Scanner version: ${process.env.TRUFFLEHOG_VERSION}`,
55+
`- Workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
56+
'',
57+
'TruffleHog detected one or more **verified** secrets in this PR diff.',
58+
'',
59+
'Please rotate affected credentials and remove them from the code and git history.',
60+
].join('\n');
61+
62+
await github.rest.issues.createComment({
63+
owner: context.repo.owner,
64+
repo: context.repo.repo,
65+
issue_number: pr.number,
66+
body
67+
});
68+
69+
- name: Notify via issue (push to main)
70+
if: steps.trufflehog.outcome == 'failure' && github.event_name == 'push'
71+
uses: actions/github-script@v7
72+
with:
73+
github-token: ${{ secrets.GITHUB_TOKEN }}
74+
script: |
75+
const title = `🚨 Secret scan failed on ${context.ref}`;
76+
const body = [
77+
'TruffleHog secret scan failed on a push to the default branch.',
78+
'',
79+
`- Scanner version: ${process.env.TRUFFLEHOG_VERSION}`,
80+
`- Commit: ${context.sha}`,
81+
`- Workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
82+
'',
83+
'TruffleHog detected one or more **verified** secrets in the changes.',
84+
'',
85+
'Watchers of this repository will receive notifications for this issue based on their GitHub notification settings.',
86+
].join('\n');
87+
88+
await github.rest.issues.create({
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
title,
92+
body,
93+
labels: ['security', 'secret-scan']
94+
});
95+
96+
- name: Fail if secrets found
97+
if: steps.trufflehog.outcome == 'failure'
98+
run: |
99+
echo "TruffleHog ${TRUFFLEHOG_VERSION} found verified secrets."
100+
exit 1
101+
102+
release:
103+
# Only run for clean pushes to main, *after* trufflehog passes
104+
needs: trufflehog
105+
if: >
106+
github.event_name == 'push' &&
107+
github.ref == 'refs/heads/main' &&
108+
needs.trufflehog.result == 'success'
109+
runs-on: ubuntu-latest
110+
defaults:
111+
run:
112+
shell: bash
113+
114+
steps:
115+
- name: Checkout code
116+
uses: actions/checkout@v4
117+
with:
118+
fetch-depth: 0
119+
120+
- name: Fetch tags
121+
run: git fetch --tags --force
122+
123+
- name: Determine next version (1.(N+1).0)
124+
id: version
125+
run: |
126+
# Pull minor versions from tags like v_1_X_0 or Release_1_X
127+
MINORS=$(git tag --list 'v_1_*_0' 'Release_1_*' | \
128+
sed -E 's/^v_1_([0-9]+)_0$/\1/; s/^Release_1_([0-9]+)$/\1/' | \
129+
sort -n)
130+
131+
if [ -z "$MINORS" ]; then
132+
LATEST_MINOR=0
133+
else
134+
LATEST_MINOR=$(echo "$MINORS" | tail -n1)
135+
fi
136+
137+
NEW_MINOR=$((LATEST_MINOR + 1))
138+
NEW_VERSION="1.${NEW_MINOR}.0"
139+
NEW_TAG="v_1_${NEW_MINOR}_0" # matches existing tag style
140+
141+
echo "LATEST_MINOR=$LATEST_MINOR"
142+
echo "NEW_MINOR=$NEW_MINOR"
143+
echo "NEW_VERSION=$NEW_VERSION"
144+
echo "NEW_TAG=$NEW_TAG"
145+
146+
echo "NEW_VERSION=$NEW_VERSION" >> "$GITHUB_ENV"
147+
echo "NEW_TAG=$NEW_TAG" >> "$GITHUB_ENV"
148+
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
149+
echo "tag=$NEW_TAG" >> "$GITHUB_OUTPUT"
150+
151+
- name: Create versioned zip
152+
run: |
153+
mkdir -p dist
154+
zip -r "dist/ai-siem-v${NEW_VERSION}.zip" . \
155+
-x ".git/*" \
156+
".github/workflows/*"
157+
158+
- name: Create git tag
159+
run: |
160+
git config user.name "github-actions[bot]"
161+
git config user.email "github-actions[bot]@users.noreply.github.com"
162+
163+
git tag -a "$NEW_TAG" -m "ai-siem v${NEW_VERSION}" "$GITHUB_SHA"
164+
git push origin "$NEW_TAG"
165+
166+
- name: Create GitHub Release with asset
167+
uses: softprops/action-gh-release@v2
168+
with:
169+
tag_name: ${{ env.NEW_TAG }} # e.g. v_1_7_0
170+
name: v${{ env.NEW_VERSION }} # e.g. v1.7.0 (matches existing releases)
171+
generate_release_notes: true
172+
files: dist/ai-siem-v${{ env.NEW_VERSION }}.zip
173+
env:
174+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)