Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions .github/workflows/audit-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Create source archive
run: |
rm -f /tmp/code.zip
zip -r /tmp/code.zip .
zip -r /tmp/code.zip .

- name: Call audit service
id: audit
Expand All @@ -51,18 +51,23 @@ jobs:
STATUS_URL=$(echo "$RESPONSE" | jq -r '.status_url // empty')
STATUS=$(echo "$RESPONSE" | jq -r '.status // empty')

if [ -z "$REPORT_URL" ] && [ -z "$STATUS_URL" ]; then
echo "Audit service did not return report_url/status_url"
exit 1
fi

echo "report_url=$REPORT_URL" >> "$GITHUB_OUTPUT"
echo "status_url=$STATUS_URL" >> "$GITHUB_OUTPUT"
echo "status=$STATUS" >> "$GITHUB_OUTPUT"

- name: Write summary
run: |
{
echo "## Audit result"
echo "## Audit PR result"
echo ""
echo "- status: ${{ steps.audit.outputs.status }}"
echo "- report_url: ${{ steps.audit.outputs.report_url }}"
echo "- status_url: ${{ steps.audit.outputs.status_url }}"
echo "- report_path: ${{ steps.audit.outputs.report_url }}"
echo "- status_path: ${{ steps.audit.outputs.status_url }}"
} >> "$GITHUB_STEP_SUMMARY"

audit-by-comment:
Expand Down Expand Up @@ -104,7 +109,7 @@ jobs:
- name: Create source archive
run: |
rm -f /tmp/code.zip
zip -r /tmp/code.zip . -x ".git/*"
zip -r /tmp/code.zip .

- name: Call audit service
id: audit
Expand All @@ -123,6 +128,11 @@ jobs:
STATUS_URL=$(echo "$RESPONSE" | jq -r '.status_url // empty')
STATUS=$(echo "$RESPONSE" | jq -r '.status // empty')

if [ -z "$REPORT_URL" ] && [ -z "$STATUS_URL" ]; then
echo "Audit service did not return report_url/status_url"
exit 1
fi

echo "report_url=$REPORT_URL" >> "$GITHUB_OUTPUT"
echo "status_url=$STATUS_URL" >> "$GITHUB_OUTPUT"
echo "status=$STATUS" >> "$GITHUB_OUTPUT"
Expand All @@ -131,16 +141,16 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const reportUrl = `${{ vars.AUDIT_SERVICE_URL }}${{ steps.audit.outputs.report_url }}`;
const statusUrl = `${{ vars.AUDIT_SERVICE_URL }}${{ steps.audit.outputs.status_url }}`;
const reportPath = `${{ steps.audit.outputs.report_url }}`;
const statusPath = `${{ steps.audit.outputs.status_url }}`;
const status = `${{ steps.audit.outputs.status }}`;

const body = [
`Audit PR triggered by @${context.payload.comment.user.login}`,
'',
`Status: ${status}`,
`Report: ${reportUrl}`,
`Status URL: ${statusUrl}`
`Report path: ${reportPath}`,
`Status path: ${statusPath}`
].join('\n');

await github.rest.issues.createComment({
Expand Down
81 changes: 75 additions & 6 deletions .github/workflows/audit-security.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Audit Security

on:
push:
branches:
- main
issue_comment:
types: [created]

Expand All @@ -10,9 +13,70 @@ permissions:
issues: write

jobs:
audit-security:
audit-security-on-main:
name: Audit security on main push
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: [self-hosted, Linux, ARM64, audit-linux]

steps:
- name: Check required variables
run: |
test -n "${{ vars.AUDIT_SERVICE_URL }}"
test -n "${{ vars.AUDIT_SECURITY_SKILL }}"

- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check required tools
run: |
which zip
which jq

- name: Create source archive
run: |
rm -f /tmp/code.zip
zip -r /tmp/code.zip .

- name: Call audit service
id: audit
shell: bash
run: |
RESPONSE=$(curl -s -X POST "${{ vars.AUDIT_SERVICE_URL }}/audit-security/${{ vars.AUDIT_SECURITY_SKILL }}" \
-H "X-API-Key: ${{ secrets.AUDIT_API_KEY }}" \
-F "file=@/tmp/code.zip")

echo "Audit response:"
echo "$RESPONSE" | jq .

REPORT_URL=$(echo "$RESPONSE" | jq -r '.report_url // empty')
STATUS_URL=$(echo "$RESPONSE" | jq -r '.status_url // empty')
STATUS=$(echo "$RESPONSE" | jq -r '.status // empty')

if [ -z "$REPORT_URL" ] && [ -z "$STATUS_URL" ]; then
echo "Audit service did not return report_url/status_url"
exit 1
fi

echo "report_url=$REPORT_URL" >> "$GITHUB_OUTPUT"
echo "status_url=$STATUS_URL" >> "$GITHUB_OUTPUT"
echo "status=$STATUS" >> "$GITHUB_OUTPUT"

- name: Write summary
run: |
{
echo "## Audit Security result"
echo ""
echo "- status: ${{ steps.audit.outputs.status }}"
echo "- report_path: ${{ steps.audit.outputs.report_url }}"
echo "- status_path: ${{ steps.audit.outputs.status_url }}"
} >> "$GITHUB_STEP_SUMMARY"

audit-security-by-comment:
name: Audit security by PR comment
if: >
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/audit-security' &&
contains(format(',{0},', vars.AUDIT_ALLOWED_USERS), format(',{0},', github.event.comment.user.login))
Expand Down Expand Up @@ -53,7 +117,7 @@ jobs:
- name: Create source archive
run: |
rm -f /tmp/code.zip
zip -r /tmp/code.zip . -x ".git/*"
zip -r /tmp/code.zip .

- name: Call audit service
id: audit
Expand All @@ -70,6 +134,11 @@ jobs:
STATUS_URL=$(echo "$RESPONSE" | jq -r '.status_url // empty')
STATUS=$(echo "$RESPONSE" | jq -r '.status // empty')

if [ -z "$REPORT_URL" ] && [ -z "$STATUS_URL" ]; then
echo "Audit service did not return report_url/status_url"
exit 1
fi

echo "report_url=$REPORT_URL" >> "$GITHUB_OUTPUT"
echo "status_url=$STATUS_URL" >> "$GITHUB_OUTPUT"
echo "status=$STATUS" >> "$GITHUB_OUTPUT"
Expand All @@ -78,16 +147,16 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const reportUrl = `${{ vars.AUDIT_SERVICE_URL }}${{ steps.audit.outputs.report_url }}`;
const statusUrl = `${{ vars.AUDIT_SERVICE_URL }}${{ steps.audit.outputs.status_url }}`;
const reportPath = `${{ steps.audit.outputs.report_url }}`;
const statusPath = `${{ steps.audit.outputs.status_url }}`;
const status = `${{ steps.audit.outputs.status }}`;

const body = [
`Audit security triggered by @${context.payload.comment.user.login}`,
'',
`Status: ${status}`,
`Report: ${reportUrl}`,
`Status URL: ${statusUrl}`
`Report path: ${reportPath}`,
`Status path: ${statusPath}`
].join('\n');

await github.rest.issues.createComment({
Expand Down