codemaxxing #67
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: codemaxxing | |
| on: | |
| schedule: | |
| # Run every 30 minutes, 24/7 | |
| - cron: '*/1 * * * *' | |
| workflow_dispatch: | |
| inputs: | |
| lines: | |
| description: 'Lines to generate' | |
| required: false | |
| default: '500000' | |
| sanity: | |
| description: 'Sanity level (0-100)' | |
| required: false | |
| default: '30' | |
| batch_size: | |
| description: 'Files per commit' | |
| required: false | |
| default: '25' | |
| recount: | |
| description: 'Force full recount of stats using scc (slow but accurate)' | |
| required: false | |
| default: 'false' | |
| concurrency: | |
| group: codemaxxing | |
| cancel-in-progress: false | |
| jobs: | |
| generate-slop: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 250000000 # stay under the 30min cron interval | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout codemaxxed | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 1 | |
| - name: Checkout codemaxxing tool | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: jshchnz/codemaxxing | |
| path: .codemaxxing-tool | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install codemaxxing | |
| run: pip install -e .codemaxxing-tool | |
| - name: Install scc | |
| run: | | |
| mkdir -p /tmp/scc-install | |
| curl -sL https://github.com/boyter/scc/releases/download/v3.4.0/scc_Linux_x86_64.tar.gz | tar xz -C /tmp/scc-install | |
| sudo mv /tmp/scc-install/scc /usr/local/bin/ | |
| - name: Configure git | |
| run: | | |
| git config user.name "codemaxxing-bot" | |
| git config user.email "codemaxxing-bot@users.noreply.github.com" | |
| - name: Generate slop | |
| run: | | |
| LINES=${{ inputs.lines || '500000' }} | |
| SANITY=${{ inputs.sanity || '30' }} | |
| BATCH=${{ inputs.batch_size || '25' }} | |
| codemaxxing \ | |
| --turbo \ | |
| --lines "$LINES" \ | |
| --sanity "$SANITY" \ | |
| --batch-size "$BATCH" \ | |
| --branch main \ | |
| --output . \ | |
| --push-every 50 | |
| - name: Update stats and README badges | |
| run: | | |
| RECOUNT="${{ inputs.recount || 'false' }}" | |
| if [ "$RECOUNT" = "true" ] || [ ! -f .session-stats.json ]; then | |
| echo "Running full recount with scc..." | |
| SCC_OUTPUT=$(scc --no-cocomo --no-complexity -f json \ | |
| --include-ext py,java,js,ts,go \ | |
| --exclude-dir .codemaxxing-tool \ | |
| . 2>/dev/null) | |
| LINES=$(echo "$SCC_OUTPUT" | python3 -c " | |
| import json, sys | |
| data = json.load(sys.stdin) | |
| print(sum(lang['Code'] + lang['Comment'] + lang['Blank'] for lang in data)) | |
| ") | |
| FILES=$(echo "$SCC_OUTPUT" | python3 -c " | |
| import json, sys | |
| data = json.load(sys.stdin) | |
| print(sum(lang['Count'] for lang in data)) | |
| ") | |
| else | |
| echo "Using incremental stats from .session-stats.json..." | |
| PREV_LINES=$(python3 -c "import json; print(json.load(open('stats.json')).get('lines', 0))" 2>/dev/null || echo 0) | |
| PREV_FILES=$(python3 -c "import json; print(json.load(open('stats.json')).get('files', 0))" 2>/dev/null || echo 0) | |
| DELTA_LINES=$(python3 -c "import json; print(json.load(open('.session-stats.json')).get('lines_generated', 0))") | |
| DELTA_FILES=$(python3 -c "import json; print(json.load(open('.session-stats.json')).get('files_generated', 0))") | |
| LINES=$((PREV_LINES + DELTA_LINES)) | |
| FILES=$((PREV_FILES + DELTA_FILES)) | |
| fi | |
| # Commits: query GitHub API for accurate count (avoids slow git fetch --unshallow) | |
| REPO="${GITHUB_REPOSITORY:-jshchnz/codemaxxed}" | |
| COMMITS=$(curl -s -H "Authorization: Bearer ${{ github.token }}" \ | |
| "https://api.github.com/repos/${REPO}/commits?per_page=1" \ | |
| -I 2>/dev/null | grep -i '^link:' | sed -n 's/.*page=\([0-9]*\)>; rel="last".*/\1/p') | |
| # Fallback if link header missing (e.g. very few commits) | |
| if [ -z "$COMMITS" ]; then | |
| COMMITS=$(python3 -c "import json; print(json.load(open('stats.json')).get('commits', 0))" 2>/dev/null || echo 0) | |
| fi | |
| # Clean up session file | |
| rm -f .session-stats.json | |
| # format with commas: 1234567 -> 1,234,567 | |
| fmt_num() { echo "$1" | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'; } | |
| LINES_FMT=$(fmt_num "$LINES") | |
| FILES_FMT=$(fmt_num "$FILES") | |
| COMMITS_FMT=$(fmt_num "$COMMITS") | |
| # URL-encode commas for badge URLs: , -> %2C | |
| LINES_URL=$(echo "$LINES_FMT" | sed 's/,/%2C/g') | |
| FILES_URL=$(echo "$FILES_FMT" | sed 's/,/%2C/g') | |
| COMMITS_URL=$(echo "$COMMITS_FMT" | sed 's/,/%2C/g') | |
| # update README badges in-place (img tags between comment markers) | |
| sed -i "s|<img src=\"https://img.shields.io/badge/lines%20of%20code-[^\"]*\" alt=\"Lines of Code\">|<img src=\"https://img.shields.io/badge/lines%20of%20code-${LINES_URL}-brightgreen?style=for-the-badge\" alt=\"Lines of Code\">|" README.md | |
| sed -i "s|<img src=\"https://img.shields.io/badge/files-[^\"]*\" alt=\"Files\">|<img src=\"https://img.shields.io/badge/files-${FILES_URL}-blue?style=for-the-badge\" alt=\"Files\">|" README.md | |
| sed -i "s|<img src=\"https://img.shields.io/badge/commits-[^\"]*\" alt=\"Commits\">|<img src=\"https://img.shields.io/badge/commits-${COMMITS_URL}-orange?style=for-the-badge\" alt=\"Commits\">|" README.md | |
| # also keep stats.json for the codemaxxing repo badges | |
| echo "{\"lines\": $LINES, \"files\": $FILES, \"commits\": $COMMITS, \"lines_fmt\": \"$LINES_FMT\", \"files_fmt\": \"$FILES_FMT\", \"commits_fmt\": \"$COMMITS_FMT\"}" > stats.json | |
| git add stats.json README.md | |
| git commit -m "update stats: ${LINES_FMT} lines, ${FILES_FMT} files, ${COMMITS_FMT} commits" || true | |
| - name: Final push | |
| run: git push origin main |