|
4 | 4 | push: |
5 | 5 | branches: |
6 | 6 | - main |
| 7 | + - feat/add-version-scanner |
7 | 8 | schedule: |
8 | 9 | - cron: '0 7 * * 2' # Run weekly on Tuesdays at 7 AM UTC (mirrors main.yml) |
9 | 10 | workflow_dispatch: |
10 | 11 |
|
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + issues: write |
| 15 | + |
11 | 16 | jobs: |
12 | 17 | scan: |
13 | 18 | name: Run Version Scanner |
|
27 | 32 | |
28 | 33 | - name: Run Version Scanner |
29 | 34 | run: | |
30 | | - python scripts/version_scanner/version_scanner.py -d python -v 3.7 --stdout |
| 35 | + # We pipe the output to a file so we can read it in the next step |
| 36 | + python scripts/version_scanner/version_scanner.py -d python -v 3.7 --stdout > scanner_output.csv |
| 37 | + |
| 38 | + - name: Create or update issue on finding |
| 39 | + if: failure() |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + run: | |
| 43 | + TITLE="Version Scanner found deprecated dependencies" |
| 44 | + RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 45 | + |
| 46 | + # Read the first 50 lines to prevent blowing up the issue body if it's massive |
| 47 | + CSV_PREVIEW=$(head -n 50 scanner_output.csv) |
| 48 | + |
| 49 | + BODY="The [Version Scanner]($RUN_URL) found deprecated dependencies in the repository. |
| 50 | + |
| 51 | + **Matches Found:** |
| 52 | + \`\`\`csv |
| 53 | + $CSV_PREVIEW |
| 54 | + \`\`\` |
| 55 | + *(If there are more than 50 matches, see the workflow logs for the full list)*" |
| 56 | +
|
| 57 | + # Mirroring regenerate-all.yml: check if an issue already exists to prevent spam |
| 58 | + EXISTING_ISSUE=$(gh issue list --state open --search "in:title \"$TITLE\"" --json number --jq '.[0].number') |
| 59 | + |
| 60 | + if [ -z "$EXISTING_ISSUE" ]; then |
| 61 | + echo "WOULD HAVE CREATED ISSUE:" |
| 62 | + echo "gh issue create --title \"$TITLE\" --body \"$BODY\"" |
| 63 | + # gh issue create --title "$TITLE" --body "$BODY" |
| 64 | + else |
| 65 | + echo "Issue #$EXISTING_ISSUE already exists." |
| 66 | + echo "WOULD HAVE ADDED COMMENT:" |
| 67 | + echo "gh issue comment \"$EXISTING_ISSUE\" --body \"Another scanner run found deprecated dependencies: $RUN_URL\"" |
| 68 | + # gh issue comment "$EXISTING_ISSUE" --body "Another scanner run found deprecated dependencies: $RUN_URL" |
| 69 | + fi |
0 commit comments