GitHub Actions Integration
Automate Alprina security scans in your GitHub Actions workflows.
Quick Start
Create .github/workflows/security-scan.yml:
name: Security Scan
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
alprina-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install Alprina
run: pip install alprina-cli
- name: Run security scan
run: alprina scan ./src --output results.json --fail-on high
env:
ALPRINA_API_KEY: ${{ secrets.ALPRINA_API_KEY }}
- name: Upload results
if: always()
uses: actions/upload-artifact@v3
with:
name: alprina-results
path: results.jsonSetup Steps
1. Add API Key to Secrets
- Go to your repository on GitHub
- Navigate to Settings → Secrets and variables → Actions
- Click New repository secret
- Name:
ALPRINA_API_KEY - Value: Your API key from dashboard
- Click Add secret
2. Create Workflow File
Create .github/workflows/security-scan.yml with the configuration above.
3. Commit and Push
git add .github/workflows/security-scan.yml
git commit -m "Add Alprina security scanning"
git pushWorkflow Configurations
Basic Scan on Push
Scan code on every push to main:
name: Security Scan
on:
push:
branches: [main]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: pip install alprina-cli
- run: alprina scan ./src
env:
ALPRINA_API_KEY: ${{ secrets.ALPRINA_API_KEY }}Fail Build on High Severity
Block merges if high-severity vulnerabilities are found:
- name: Security scan with failure threshold
run: alprina scan ./src --fail-on high
env:
ALPRINA_API_KEY: ${{ secrets.ALPRINA_API_KEY }}Scan Only Changed Files
Optimize scan performance by scanning only changed files:
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v39
- name: Scan changed files
if: steps.changed-files.outputs.all_changed_files != ''
run: |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
alprina scan "$file" || true
done
env:
ALPRINA_API_KEY: ${{ secrets.ALPRINA_API_KEY }}Matrix Strategy for Multiple Languages
Scan different parts of a monorepo in parallel:
strategy:
matrix:
target:
- path: './frontend'
language: 'javascript'
- path: './backend'
language: 'python'
- path: './api'
language: 'go'
steps:
- uses: actions/checkout@v3
- run: pip install alprina-cli
- name: Scan ${{ matrix.target.path }}
run: alprina scan ${{ matrix.target.path }} --language ${{ matrix.target.language }}
env:
ALPRINA_API_KEY: ${{ secrets.ALPRINA_API_KEY }}Schedule Weekly Deep Scans
Run comprehensive scans weekly:
on:
schedule:
- cron: '0 0 * * 0' # Every Sunday at midnight
jobs:
comprehensive-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: pip install alprina-cli
- run: alprina scan ./src --profile comprehensive --output weekly-scan.json
env:
ALPRINA_API_KEY: ${{ secrets.ALPRINA_API_KEY }}
- uses: actions/upload-artifact@v3
with:
name: weekly-scan
path: weekly-scan.json
retention-days: 90Advanced Configurations
With Caching
Speed up workflow by caching pip packages:
- name: Cache pip packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Alprina
run: pip install alprina-cliComment on PR with Results
Post scan results as PR comments:
- name: Run scan
id: scan
run: alprina scan ./src --output results.json
continue-on-error: true
env:
ALPRINA_API_KEY: ${{ secrets.ALPRINA_API_KEY }}
- name: Comment PR
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
script: |
const fs = require('fs');
const results = JSON.parse(fs.readFileSync('results.json', 'utf8'));
const comment = `
## Alprina Security Scan Results
**Findings:** ${results.summary.total_findings}
- Critical: ${results.summary.critical || 0}
- High: ${results.summary.high || 0}
- Medium: ${results.summary.medium || 0}
- Low: ${results.summary.low || 0}
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});Generate HTML Report
Create and publish HTML reports:
- name: Run scan
run: alprina scan ./src --output report.html
env:
ALPRINA_API_KEY: ${{ secrets.ALPRINA_API_KEY }}
- name: Deploy report to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./
keep_files: trueConditional Scans
Run scans only on specific conditions:
- name: Check if security-sensitive files changed
id: security-check
run: |
if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '(auth|security|crypto)'; then
echo "security_changed=true" >> $GITHUB_OUTPUT
fi
- name: Run security scan
if: steps.security-check.outputs.security_changed == 'true'
run: alprina scan ./src --fail-on medium
env:
ALPRINA_API_KEY: ${{ secrets.ALPRINA_API_KEY }}Integration with Branch Protection
Require security scans to pass before merging:
1. Add Status Check
Your workflow must have a clear job name:
jobs:
security-scan: # This name appears in branch protection
runs-on: ubuntu-latest
steps:
# ... scan steps2. Configure Branch Protection
- Go to Settings → Branches
- Add rule for
mainbranch - Enable Require status checks to pass
- Select security-scan from the list
- Save changes
Now PRs cannot be merged until the security scan passes.
Troubleshooting
API Key Not Found
Error: ALPRINA_API_KEY not set
Solution:
- Verify secret is added to repository
- Check secret name matches workflow file
- Ensure secret is not empty
Permission Denied
Error: 403 Forbidden
Solution:
- Regenerate API key in dashboard
- Update GitHub secret
- Retry workflow
Scan Timeout
Error: Workflow times out after 6 hours
Solution:
jobs:
scan:
timeout-minutes: 30 # Add timeoutCache Issues
Clear cache if builds become inconsistent:
- Go to Actions tab
- Click Caches in sidebar
- Delete old caches
Best Practices
- Use Secrets: Never hardcode API keys
- Cache Dependencies: Reduce build time
- Fail on High Severity: Block critical vulnerabilities
- Save Artifacts: Keep scan results for compliance
- Run on PRs: Catch issues before merging
- Schedule Deep Scans: Regular comprehensive audits
- Monitor Credits: Track usage in dashboard
Examples Repository
See complete examples at: