Harwest Submissions #56
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: Harwest Submissions | |
| on: | |
| # Daily schedule - 11:00 PM BDT (5:00 PM UTC) | |
| schedule: | |
| - cron: '0 17 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| platform: | |
| description: 'Platform to harvest (codeforces, atcoder, or all)' | |
| required: false | |
| default: 'all' | |
| full_scan: | |
| description: 'Perform full scan' | |
| required: false | |
| type: boolean | |
| default: false | |
| # ========================== | |
| # GLOBAL TIMEZONE (BDT) | |
| # ========================== | |
| env: | |
| PYTHON_VERSION: '3.9' | |
| TZ: Asia/Dhaka | |
| jobs: | |
| check-activity: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| outputs: | |
| should_run: ${{ steps.activity.outputs.should_run }} | |
| days_since_commit: ${{ steps.activity.outputs.days_since_commit }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check repository activity | |
| id: activity | |
| run: | | |
| LAST_COMMIT_DATE=$(git log -1 --format=%ct --author-date-order --all --invert-grep --grep="^Harwest Submissions\|^GitHub Actions" || git log -1 --format=%ct) | |
| CURRENT_DATE=$(date +%s) | |
| DAYS_DIFF=$(( (CURRENT_DATE - LAST_COMMIT_DATE) / 86400 )) | |
| echo "days_since_commit=$DAYS_DIFF" >> $GITHUB_OUTPUT | |
| echo "📅 Days since last commit: $DAYS_DIFF" | |
| if [ "${{ github.event_name }}" = "schedule" ]; then | |
| if [ $DAYS_DIFF -gt 30 ]; then | |
| CURRENT_DAY=$(date +%d) | |
| if [ "$CURRENT_DAY" = "01" ]; then | |
| echo "should_run=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "should_run=false" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "should_run=true" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "should_run=true" >> $GITHUB_OUTPUT | |
| fi | |
| harvest: | |
| needs: check-activity | |
| if: needs.check-activity.outputs.should_run == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| # ========================== | |
| # AUTO GITHUB OWNER CONFIG | |
| # ========================== | |
| - name: Configure Git Identity | |
| run: | | |
| OWNER="${GITHUB_REPOSITORY_OWNER}" | |
| echo "Using repository owner: $OWNER" | |
| git config --local user.name "$OWNER" | |
| git config --local user.email "$OWNER@users.noreply.github.com" | |
| - name: Check configuration | |
| id: check_config | |
| run: | | |
| if [ ! -f config/users.json ]; then | |
| echo "❌ Error: config/users.json not found" | |
| exit 1 | |
| fi | |
| CODEFORCES_COUNT=$(python3 -c "import json; d=json.load(open('config/users.json')); print(len(d.get('codeforces', [])))") | |
| ATCODER_COUNT=$(python3 -c "import json; d=json.load(open('config/users.json')); print(len(d.get('atcoder', [])))") | |
| if [ "$CODEFORCES_COUNT" -eq 0 ] && [ "$ATCODER_COUNT" -eq 0 ]; then | |
| echo "has_users=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_users=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set environment variables | |
| if: steps.check_config.outputs.has_users == 'true' | |
| run: | | |
| echo "SUBMISSIONS_DIR=${{ vars.SUBMISSIONS_DIR || './submissions' }}" >> $GITHUB_ENV | |
| echo "GITHUB_REPOSITORY_URL=${{ github.server_url }}/${{ github.repository }}.git" >> $GITHUB_ENV | |
| echo "GITHUB_REF_NAME=${{ github.ref_name }}" >> $GITHUB_ENV | |
| - name: Harvest Codeforces submissions | |
| if: steps.check_config.outputs.has_users == 'true' && (github.event_name == 'schedule' || github.event.inputs.platform == 'codeforces' || github.event.inputs.platform == 'all' || github.event.inputs.platform == '') | |
| run: | | |
| FULL_SCAN_FLAG="" | |
| CURRENT_DAY=$(date +%d) | |
| if [ "${{ github.event_name }}" = "schedule" ] && [ "$CURRENT_DAY" = "01" ]; then | |
| FULL_SCAN_FLAG="--full-scan" | |
| fi | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.full_scan }}" = "true" ]; then | |
| FULL_SCAN_FLAG="--full-scan" | |
| fi | |
| python3 -m harwest codeforces $FULL_SCAN_FLAG --auto | |
| - name: Harvest AtCoder submissions | |
| if: steps.check_config.outputs.has_users == 'true' && (github.event_name == 'schedule' || github.event.inputs.platform == 'atcoder' || github.event.inputs.platform == 'all' || github.event.inputs.platform == '') | |
| run: | | |
| FULL_SCAN_FLAG="" | |
| CURRENT_DAY=$(date +%d) | |
| if [ "${{ github.event_name }}" = "schedule" ] && [ "$CURRENT_DAY" = "01" ]; then | |
| FULL_SCAN_FLAG="--full-scan" | |
| fi | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.full_scan }}" = "true" ]; then | |
| FULL_SCAN_FLAG="--full-scan" | |
| fi | |
| python3 -m harwest atcoder $FULL_SCAN_FLAG --auto | |
| # ========================== | |
| # COMMIT + PUSH (BDT TIME) | |
| # ========================== | |
| - name: Push changes | |
| if: steps.check_config.outputs.has_users == 'true' | |
| run: | | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git add . | |
| git commit \ | |
| --author="$GITHUB_REPOSITORY_OWNER <$GITHUB_REPOSITORY_OWNER@users.noreply.github.com>" \ | |
| -m "Auto updated submissions - $(date +'%Y-%m-%d %H:%M:%S')" | |
| git push | |
| else | |
| echo "ℹ️ No new submissions found" | |
| fi | |
| - name: Log schedule status | |
| if: always() | |
| run: | | |
| DAYS=${{ needs.check-activity.outputs.days_since_commit }} | |
| if [ "$DAYS" -gt 30 ]; then | |
| echo "📅 Schedule Status: MONTHLY (inactive for $DAYS days)" | |
| else | |
| echo "📅 Schedule Status: DAILY (last activity $DAYS days ago)" | |
| echo "Next run: Tomorrow at 11:00 PM BDT" | |
| fi |