1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# =============================================================================
# RepoLens GitHub Actions Reusable Workflow
# =============================================================================
#
# This is a reusable workflow that can be called from other workflows in your
# repository or from other repositories.
#
# USAGE:
# 1. Copy this file to `.github/workflows/repolens.yml` in your repository
# 2. Call it from another workflow or use it directly
#
# CALLING FROM ANOTHER WORKFLOW:
# ```yaml
# jobs:
# audit:
# uses: ./.github/workflows/repolens.yml
# with:
# preset: 'opensource'
# format: 'json'
# fail-on: 'critical'
# ```
#
# OR USING THE OFFICIAL ACTION:
# ```yaml
# - uses: systm-d/repolens@main
# with:
# preset: 'opensource'
# ```
#
# =============================================================================
name: RepoLens Audit
on:
# Allow this workflow to be called from other workflows
workflow_call:
inputs:
preset:
description: 'Audit preset (opensource, enterprise, strict)'
required: false
type: string
default: 'opensource'
format:
description: 'Output format (terminal, json, sarif, markdown, html)'
required: false
type: string
default: 'json'
fail-on:
description: 'Fail on severity level (critical, high, medium, low, none)'
required: false
type: string
default: 'critical'
version:
description: 'RepoLens version to use'
required: false
type: string
default: 'latest'
config:
description: 'Path to custom .repolens.toml config file'
required: false
type: string
default: ''
upload-artifact:
description: 'Upload report as artifact'
required: false
type: boolean
default: true
upload-sarif:
description: 'Upload SARIF to GitHub Security'
required: false
type: boolean
default: false
outputs:
report-path:
description: 'Path to the generated report'
value: ${{ jobs.audit.outputs.report-path }}
findings-count:
description: 'Number of findings detected'
value: ${{ jobs.audit.outputs.findings-count }}
exit-code:
description: 'Exit code from the audit'
value: ${{ jobs.audit.outputs.exit-code }}
# Also allow direct triggering
workflow_dispatch:
inputs:
preset:
description: 'Audit preset'
required: false
type: choice
options:
- opensource
- enterprise
- strict
default: 'opensource'
format:
description: 'Output format'
required: false
type: choice
options:
- terminal
- json
- sarif
- markdown
- html
default: 'json'
fail-on:
description: 'Fail on severity'
required: false
type: choice
options:
- critical
- high
- medium
- low
- none
default: 'critical'
# Concurrency control
concurrency:
group: repolens-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
audit:
name: RepoLens Audit
runs-on: ubuntu-latest
outputs:
report-path: ${{ steps.audit.outputs.report-path }}
findings-count: ${{ steps.audit.outputs.findings-count }}
exit-code: ${{ steps.audit.outputs.exit-code }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Determine version
id: version
run: |
VERSION="${{ inputs.version || 'latest' }}"
if [ "$VERSION" = "latest" ]; then
RELEASE_TAG=$(curl -s https://api.github.com/repos/systm-d/repolens/releases/latest | grep '"tag_name"' | sed -E 's/.*"tag_name": *"([^"]+)".*/\1/')
if [ -z "$RELEASE_TAG" ] || [ "$RELEASE_TAG" = "null" ]; then
echo "::error::Failed to determine latest RepoLens version"
exit 1
fi
VERSION="${RELEASE_TAG#v}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=v${VERSION}" >> "$GITHUB_OUTPUT"
echo "Installing RepoLens version: ${VERSION}"
- name: Cache RepoLens binary
id: cache
uses: actions/cache@v4
with:
path: /usr/local/bin/repolens
key: repolens-${{ runner.os }}-${{ steps.version.outputs.version }}
- name: Install RepoLens
if: steps.cache.outputs.cache-hit != 'true'
run: |
DOWNLOAD_URL="https://github.com/systm-d/repolens/releases/download/${{ steps.version.outputs.tag }}/repolens-linux-x86_64.tar.gz"
echo "Downloading RepoLens from ${DOWNLOAD_URL}..."
curl -sL "${DOWNLOAD_URL}" -o /tmp/repolens.tar.gz
if ! file /tmp/repolens.tar.gz | grep -q 'gzip'; then
echo "::error::Downloaded file is not a valid gzip archive"
exit 1
fi
tar xzf /tmp/repolens.tar.gz -C /tmp
chmod +x /tmp/repolens
sudo mv /tmp/repolens /usr/local/bin/repolens
rm -f /tmp/repolens.tar.gz
echo "RepoLens installed successfully"
- name: Verify installation
run: repolens --version
- name: Run RepoLens audit
id: audit
run: |
# Configuration
PRESET="${{ inputs.preset || 'opensource' }}"
FORMAT="${{ inputs.format || 'json' }}"
FAIL_ON="${{ inputs.fail-on || 'critical' }}"
CONFIG="${{ inputs.config }}"
# Determine file extension
case "${FORMAT}" in
json) EXT="json" ;;
sarif) EXT="sarif" ;;
markdown) EXT="md" ;;
html) EXT="html" ;;
*) EXT="txt" ;;
esac
REPORT_FILE="${{ runner.temp }}/repolens-report.${EXT}"
# Build command
CMD="repolens plan --preset ${PRESET} --format ${FORMAT}"
[ -n "${CONFIG}" ] && CMD="${CMD} --config ${CONFIG}"
[ "${FORMAT}" != "terminal" ] && CMD="${CMD} --output ${REPORT_FILE}"
# Run audit
set +e
eval "${CMD}"
AUDIT_EXIT_CODE=$?
set -e
# Set outputs
echo "exit-code=${AUDIT_EXIT_CODE}" >> "$GITHUB_OUTPUT"
echo "report-path=${REPORT_FILE}" >> "$GITHUB_OUTPUT"
# Count findings (for JSON/SARIF)
FINDINGS_COUNT=0
if [ "${FORMAT}" = "json" ] && [ -f "${REPORT_FILE}" ]; then
FINDINGS_COUNT=$(python3 -c "
import sys, json
try:
data = json.load(open('${REPORT_FILE}'))
if isinstance(data, list):
print(len(data))
elif isinstance(data, dict) and 'findings' in data:
print(len(data['findings']))
else:
print(0)
except:
print(0)
" 2>/dev/null || echo "0")
fi
echo "findings-count=${FINDINGS_COUNT}" >> "$GITHUB_OUTPUT"
echo "::notice::RepoLens audit completed with ${FINDINGS_COUNT} finding(s)"
# Handle fail-on logic
if [ "${FAIL_ON}" = "none" ]; then
echo "fail-on is 'none', ignoring exit code"
exit 0
fi
if [ ${AUDIT_EXIT_CODE} -ne 0 ]; then
case "${FAIL_ON}" in
critical)
[ ${AUDIT_EXIT_CODE} -eq 1 ] && exit 1
;;
high|medium|low)
exit 1
;;
esac
fi
- name: Upload report artifact
if: ${{ (inputs.upload-artifact == true || inputs.upload-artifact == 'true') && inputs.format != 'terminal' }}
uses: actions/upload-artifact@v4
with:
name: repolens-report
path: ${{ steps.audit.outputs.report-path }}
retention-days: 30
if-no-files-found: ignore
- name: Generate SARIF for Security tab
if: ${{ inputs.upload-sarif == true || inputs.upload-sarif == 'true' }}
run: |
repolens plan \
--preset ${{ inputs.preset || 'opensource' }} \
--format sarif \
--output ${{ runner.temp }}/repolens-security.sarif
- name: Upload SARIF to GitHub Security
if: ${{ inputs.upload-sarif == true || inputs.upload-sarif == 'true' }}
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ runner.temp }}/repolens-security.sarif
category: 'repolens'
# =============================================================================
# Example: Standalone Workflow
# =============================================================================
# To use this as a standalone workflow (not reusable), add these triggers:
#
# on:
# push:
# branches: [main, develop]
# pull_request:
# branches: [main]
#
# And remove the workflow_call trigger.
# =============================================================================
# Example: Calling This Workflow
# =============================================================================
# Create a workflow file that calls this reusable workflow:
#
# name: CI
# on: [push, pull_request]
#
# jobs:
# lint:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - run: npm run lint
#
# audit:
# needs: lint
# uses: ./.github/workflows/repolens.yml
# with:
# preset: 'opensource'
# format: 'sarif'
# upload-sarif: true
#
# deploy:
# needs: [lint, audit]
# if: github.ref == 'refs/heads/main'
# runs-on: ubuntu-latest
# steps:
# - run: echo "Deploying..."
# =============================================================================
# Example: Using the Official Action Instead
# =============================================================================
# If you prefer to use the official RepoLens action:
#
# jobs:
# audit:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: systm-d/repolens@main
# with:
# preset: 'opensource'
# format: 'sarif'
# fail-on: 'critical'