|
| 1 | +name: "SigScanner Check" |
| 2 | + |
| 3 | +on: |
| 4 | + merge_group: |
| 5 | + pull_request: |
| 6 | + |
| 7 | +permissions: {} |
| 8 | + |
| 9 | +jobs: |
| 10 | + sigscanner-check: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + # Skip on merge group events |
| 13 | + if: ${{ github.event_name == 'pull_request' }} |
| 14 | + steps: |
| 15 | + - name: "SigScanner checking ${{ github.sha }} by ${{ github.actor }}" |
| 16 | + env: |
| 17 | + API_TOKEN: ${{ secrets.SIGSCANNER_API_TOKEN }} |
| 18 | + API_URL: ${{ secrets.SIGSCANNER_API_URL }} |
| 19 | + COMMIT_SHA: ${{ github.sha }} |
| 20 | + ACTOR: ${{ github.actor }} |
| 21 | + REPOSITORY: ${{ github.repository }} |
| 22 | + EVENT_NAME: ${{ github.event_name }} |
| 23 | + |
| 24 | + run: | |
| 25 | + echo "🔎 Checking commit $COMMIT_SHA by $ACTOR in $REPOSITORY - $EVENT_NAME" |
| 26 | +
|
| 27 | + payload=$(printf '{"commit":"%s","repository":"%s","author":"%s"}' \ |
| 28 | + "$COMMIT_SHA" "$REPOSITORY" "$ACTOR") |
| 29 | +
|
| 30 | + max_attempts=3 |
| 31 | + attempt=1 |
| 32 | +
|
| 33 | + # Retry on 5XXs |
| 34 | + while [[ $attempt -le $max_attempts ]]; do |
| 35 | + echo "Attempt $attempt/$max_attempts" |
| 36 | +
|
| 37 | + CODE=$(curl \ |
| 38 | + --silent \ |
| 39 | + --output /dev/null \ |
| 40 | + --write-out '%{http_code}' \ |
| 41 | + --max-time 20 \ |
| 42 | + -X POST \ |
| 43 | + -H "Content-Type: application/json" \ |
| 44 | + -H "Authorization: $API_TOKEN" \ |
| 45 | + --url "$API_URL" \ |
| 46 | + --data "$payload") |
| 47 | +
|
| 48 | + echo "Received $CODE" |
| 49 | + if [[ "$CODE" == "200" ]]; then |
| 50 | + echo "✅ Commit is verified" |
| 51 | + exit 0 |
| 52 | + elif [[ "$CODE" == "400" ]]; then |
| 53 | + echo "❌ Bad request" |
| 54 | + exit 1 |
| 55 | + elif [[ "$CODE" == "403" ]]; then |
| 56 | + echo "❌ Commit is NOT verified" |
| 57 | + exit 1 |
| 58 | + elif [[ "$CODE" =~ ^5[0-9][0-9]$ ]]; then |
| 59 | + if [[ $attempt -lt $max_attempts ]]; then |
| 60 | + echo "Retrying in 15s..." |
| 61 | + sleep 15 |
| 62 | + fi |
| 63 | + else |
| 64 | + echo "❌ Unexpected response" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +
|
| 68 | + attempt=$((attempt + 1)) |
| 69 | + done |
| 70 | + exit 1 |
0 commit comments