MahbubHS Auto Commit #2846
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: MahbubHS Auto Commit | |
| on: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: "0 */3 * * *" | |
| jobs: | |
| commit: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| - name: Set up Git | |
| run: | | |
| git config --global pull.rebase true | |
| - name: Loop Commit | |
| run: | | |
| set -e | |
| FILES=(".github/MahbubHS.md" "README.md" ".github/MahbubHS_1.md" ".github/MahbubHS_2.md") | |
| COMMIT_LOOP_COUNT=20 | |
| choose_committer() { | |
| # 0 = your info, 1 = bot info | |
| if [ $((RANDOM % 2)) -eq 0 ]; then | |
| git config --global user.name "${{ github.actor }}" | |
| git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
| echo "Using user info: MahbubHS" | |
| else | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| echo "Using GitHub Actions bot" | |
| fi | |
| } | |
| for FILE in "${FILES[@]}"; do | |
| echo "Checking for file: $FILE" | |
| DIR=$(dirname "$FILE") | |
| if [ "$DIR" != "." ]; then | |
| mkdir -p "$DIR" | |
| fi | |
| for ((i=1; i<=COMMIT_LOOP_COUNT; i++)); do | |
| choose_committer | |
| echo "Iteration $i of $COMMIT_LOOP_COUNT" | |
| if [ ! -f "$FILE" ]; then | |
| echo "File not found, creating $FILE..." | |
| echo "# Git Commit" > "$FILE" | |
| echo "[](https://github.com/MahbubHS/active/actions/workflows/main.yml)" >> "$FILE" | |
| echo "" >> "$FILE" | |
| echo "This file was added - $(date +"%b %d, %Y") " >> "$FILE" | |
| echo "Last commit at UTC - $(date +"%I:%M %p")" >> "$FILE" | |
| echo "" >> "$FILE" | |
| echo "Daily git commit" >> "$FILE" | |
| echo "" >> "$FILE" | |
| echo "commit number: 1" >> "$FILE" | |
| NEXT_COUNT=1 | |
| else | |
| echo "File exists. Updating commit number..." | |
| CURRENT_COUNT=$(grep -oP 'commit number: \K\d+' "$FILE" || echo "0") | |
| echo "Current commit number: $CURRENT_COUNT" | |
| NEXT_COUNT=$((CURRENT_COUNT + 1)) | |
| sed -i "s/commit number: .*/commit number: $NEXT_COUNT/" "$FILE" | |
| sed -i "s/Last commit at UTC -.*/Last commit at UTC - $(date +"%I:%M %p")/" "$FILE" | |
| echo "Updated commit number to: $NEXT_COUNT and time to $(date +"%I:%M %p")" | |
| fi | |
| echo "Contents of the file:" | |
| cat "$FILE" | |
| echo "Staging changes..." | |
| git add "$FILE" | |
| echo "Committing changes..." | |
| git commit -m "Auto commit #$NEXT_COUNT : target - ($FILE)" --allow-empty | |
| sleep 10 | |
| done | |
| echo "Pulling latest changes to ensure we start with the latest commit..." | |
| git pull --rebase origin main | |
| git push origin main | |
| done | |
| echo "All commits completed successfully!" |