|
| 1 | +# Socket Security GitHub Actions Workflow |
| 2 | +# This workflow runs Socket Security scans on every commit to any branch |
| 3 | +# It automatically detects git repository information and handles different event types |
| 4 | + |
| 5 | +name: socket-security-workflow |
| 6 | +run-name: Socket Security Github Action |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: ["**"] # Run on all branches, all commits |
| 11 | + pull_request: |
| 12 | + types: [opened, synchronize, reopened] |
| 13 | + issue_comment: |
| 14 | + types: [created] |
| 15 | + |
| 16 | +# Prevent concurrent runs for the same commit |
| 17 | +concurrency: |
| 18 | + group: socket-scan-${{ github.ref }}-${{ github.sha }} |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + socket-security: |
| 23 | + permissions: |
| 24 | + issues: write |
| 25 | + contents: read |
| 26 | + pull-requests: write |
| 27 | + runs-on: ubuntu-latest |
| 28 | + |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + # For PRs, fetch one additional commit for proper diff analysis |
| 33 | + fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} |
| 34 | + |
| 35 | + - uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: "3.12" |
| 38 | + |
| 39 | + - name: Install Socket CLI |
| 40 | + run: pip install socketsecurity --upgrade |
| 41 | + |
| 42 | + - name: Run Socket Security Scan |
| 43 | + env: |
| 44 | + SOCKET_SECRET: ${{ secrets.SOCKET_SECRET }} |
| 45 | + GH_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + run: | |
| 47 | + # Determine PR number based on event type |
| 48 | + PR_NUMBER=0 |
| 49 | + if [ "${{ github.event_name }}" == "pull_request" ]; then |
| 50 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 51 | + elif [ "${{ github.event_name }}" == "issue_comment" ]; then |
| 52 | + PR_NUMBER=${{ github.event.issue.number }} |
| 53 | + fi |
| 54 | +
|
| 55 | + # Run Socket CLI with minimal required parameters |
| 56 | + # The CLI automatically detects: |
| 57 | + # - Repository name from git |
| 58 | + # - Branch name from git |
| 59 | + # - Commit SHA from git |
| 60 | + # - Commit message from git |
| 61 | + # - Committer information from git |
| 62 | + # - Default branch status from git and GitHub environment |
| 63 | + # - Changed files from git commit |
| 64 | + socketcli \ |
| 65 | + --target-path $GITHUB_WORKSPACE \ |
| 66 | + --scm github \ |
| 67 | + --pr-number $PR_NUMBER |
0 commit comments