sentinel-v1 #2240
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: sentinel-v1 | |
| on: | |
| schedule: | |
| - cron: "*/7 * * * *" | |
| push: | |
| branches: [main, master] | |
| workflow_dispatch: | |
| jobs: | |
| update_repository: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Update repository data | |
| run: | | |
| # Create timestamp variables | |
| TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
| RUN_NUMBER=${{ github.run_number }} | |
| RUN_ATTEMPT=${{ github.run_attempt }} | |
| # === FILE 1: Update single rotating metrics file (always changes) === | |
| mkdir -p metrics | |
| cat > metrics/current.json << EOF | |
| { | |
| "timestamp": "$TIMESTAMP", | |
| "run_number": $RUN_NUMBER, | |
| "run_attempt": $RUN_ATTEMPT, | |
| "random": $((RANDOM % 10000)), | |
| "nano": $(date +%s%N) | |
| } | |
| EOF | |
| # === FILE 2: Update README badge section (always changes) === | |
| if [ -f "README.md" ]; then | |
| # Remove old timestamp line | |
| sed -i '/<!-- TIMESTAMP -->/d' README.md 2>/dev/null || true | |
| # Insert new timestamp with unique marker | |
| sed -i '1s/^/<!-- TIMESTAMP -->\n/' README.md 2>/dev/null || echo "<!-- TIMESTAMP -->" > README.md | |
| fi | |
| # === FILE 3: Update single activity log (append + rotate) === | |
| mkdir -p .github/logs | |
| echo "$TIMESTAMP,$RUN_NUMBER,$RUN_ATTEMPT,$RANDOM" >> .github/logs/current.csv | |
| # Keep only last 100 lines to prevent growth | |
| tail -n 100 .github/logs/current.csv > .github/logs/current.csv.tmp | |
| mv .github/logs/current.csv.tmp .github/logs/current.csv | |
| # === FILE 4: Update counter file (always increments) === | |
| mkdir -p .github/counter | |
| if [ -f ".github/counter/run-counter.txt" ]; then | |
| COUNT=$(cat .github/counter/run-counter.txt) | |
| echo $((COUNT + 1)) > .github/counter/run-counter.txt | |
| else | |
| echo "1" > .github/counter/run-counter.txt | |
| fi | |
| # === FILE 5: Update timestamp in LAST_UPDATED === | |
| echo "$TIMESTAMP - Run #$RUN_NUMBER (Attempt $RUN_ATTEMPT)" > LAST_UPDATED | |
| # === FILE 6: Update CHANGELOG_AUTO.md (single entry) === | |
| # Keep only last 10 entries | |
| if [ -f "CHANGELOG_AUTO.md" ]; then | |
| head -n 20 CHANGELOG_AUTO.md > CHANGELOG_AUTO.md.tmp 2>/dev/null || true | |
| mv CHANGELOG_AUTO.md.tmp CHANGELOG_AUTO.md 2>/dev/null || true | |
| fi | |
| echo "- $TIMESTAMP: Run #$RUN_NUMBER" >> CHANGELOG_AUTO.md | |
| # === FILE 7: Update random seed file === | |
| echo "RANDOM_SEED=$RANDOM-$RANDOM-$RANDOM" > .github/random.txt | |
| # === FILE 8: Update status file === | |
| cat > .github/status.json << EOF | |
| { | |
| "last_run": "$TIMESTAMP", | |
| "run_number": $RUN_NUMBER, | |
| "attempt": $RUN_ATTEMPT, | |
| "healthy": true | |
| } | |
| EOF | |
| - name: Create and push commit | |
| run: | | |
| # Configure Git | |
| git config --local user.email "155255765+zuck30@users.noreply.github.com" | |
| git config --local user.name "zuck30" | |
| # Add all changes (all tracked files) | |
| git add -A | |
| # This will ALWAYS have changes because we update existing files | |
| RUN_NUMBER=${{ github.run_number }} | |
| # Create commit message | |
| COMMIT_MSG="chore: auto-update #$RUN_NUMBER [$(date +%H:%M)]" | |
| # Commit | |
| git commit -m "$COMMIT_MSG" | |
| # Push with retry | |
| MAX_RETRIES=3 | |
| RETRY=0 | |
| until [ $RETRY -ge $MAX_RETRIES ] | |
| do | |
| git pull --rebase origin HEAD && git push origin HEAD && break | |
| RETRY=$((RETRY+1)) | |
| echo "Push failed, retry $RETRY/$MAX_RETRIES in 5 seconds..." | |
| sleep 5 | |
| done |