diff --git a/.github/workflows/audit-pr.yml b/.github/workflows/audit-pr.yml index 996958d..a8223d6 100644 --- a/.github/workflows/audit-pr.yml +++ b/.github/workflows/audit-pr.yml @@ -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 @@ -51,6 +51,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" @@ -58,11 +63,11 @@ jobs: - 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: @@ -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 @@ -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" @@ -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({ diff --git a/.github/workflows/audit-security.yml b/.github/workflows/audit-security.yml index 5eead19..b34aa17 100644 --- a/.github/workflows/audit-security.yml +++ b/.github/workflows/audit-security.yml @@ -1,6 +1,9 @@ name: Audit Security on: + push: + branches: + - main issue_comment: types: [created] @@ -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)) @@ -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 @@ -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" @@ -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({