Repository Health Scan #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Repository Health Scan | |
| on: | |
| schedule: | |
| - cron: '0 1 * * 5' # Run every Friday at 1 AM | |
| workflow_dispatch: # Manual trigger | |
| inputs: | |
| github_org: | |
| description: 'GitHub organization to scan (optional - overrides other sources)' | |
| required: false | |
| type: string | |
| pr_threshold_days: | |
| description: 'Days threshold for old PRs' | |
| required: false | |
| default: '30' | |
| type: string | |
| jobs: | |
| scan: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch full history to access commit messages | |
| - name: Determine GitHub Organization | |
| id: determine-org | |
| run: | | |
| # Priority order: | |
| # 1. Manual input from workflow_dispatch | |
| # 2. ORG_NAME from variables | |
| GITHUB_ORG="" | |
| # Check manual input first | |
| if [ -n "${{ github.event.inputs.github_org }}" ]; then | |
| GITHUB_ORG="${{ github.event.inputs.github_org }}" | |
| echo "Using GitHub org from manual input: $GITHUB_ORG" | |
| elif [ -n "${{ vars.ORG_NAME }}" ]; then | |
| GITHUB_ORG="${{ vars.ORG_NAME }}" | |
| echo "Using GitHub org from variables: $GITHUB_ORG" | |
| else | |
| echo "Error: No GitHub organization specified. Please either:" | |
| echo "1. Set ORG_NAME variable in repository settings" | |
| echo "2. Provide github_org input when running manually" | |
| exit 1 | |
| fi | |
| echo "github_org=$GITHUB_ORG" >> $GITHUB_OUTPUT | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| pip install -r requirements.txt | |
| - name: Run GitHub Scanner | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.SCANNER_PAT }} | |
| GITHUB_ORG: ${{ steps.determine-org.outputs.github_org }} | |
| OLD_PR_THRESHOLD_DAYS: ${{ github.event.inputs.pr_threshold_days || '30' }} | |
| DELETE_ORPHANED_BRANCHES: ${{ vars.DELETE_ORPHANED_BRANCHES || 'false' }} | |
| run: | | |
| echo "Starting scan for organization: $GITHUB_ORG" | |
| echo "PR threshold: $OLD_PR_THRESHOLD_DAYS days" | |
| echo "Auto-delete branches: $DELETE_ORPHANED_BRANCHES" | |
| mkdir -p reports | |
| python scanner.py --pretty | |
| - name: Upload Report to Discord | |
| env: | |
| DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
| run: | | |
| # Find the generated markdown report | |
| REPORT_FILE=$(ls -t reports/*.md | head -1) | |
| if [ -z "$REPORT_FILE" ]; then | |
| echo "Error: No markdown report found" | |
| exit 1 | |
| fi | |
| echo "Uploading report: $REPORT_FILE" | |
| # Upload file to Discord webhook | |
| curl -F "file=@$REPORT_FILE" \ | |
| -F "content=📊 **GitHub Repository Health Report** - Organization: ${{ steps.determine-org.outputs.github_org }}" \ | |
| "$DISCORD_WEBHOOK_URL" | |
| - name: Upload Report as Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: health-report-${{ steps.determine-org.outputs.github_org }}-${{ github.run_number }} | |
| path: reports/*.md | |
| retention-days: 30 |