auto-commit #816
This file contains 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: auto-commit | |
on: | |
push: | |
branches: | |
- main | |
# Schedule the workflow to run every hour | |
schedule: | |
- cron: "0 * * * *" | |
jobs: | |
auto_commit: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check if it's time to commit | |
run: | | |
current_hour=$(date '+%H') | |
# Define your desired random intervals or conditions for committing | |
if [ $current_hour -ge 9 ] && [ $current_hour -le 18 ]; then | |
# Within the specified time range (e.g., from 9 AM to 6 PM) | |
if [ $(( RANDOM % 3 )) -eq 0 ]; then | |
echo "Committing..." | |
touch .commit_marker | |
else | |
echo "Not committing." | |
fi | |
else | |
# Outside the specified time range | |
if [ $(( RANDOM % 2 )) -eq 0 ]; then | |
echo "Committing..." | |
touch .commit_marker | |
else | |
echo "Not committing." | |
fi | |
fi | |
id: commit-check | |
- name: Commit if marked | |
if: steps.commit-check.outputs.commit-check == 'Committing...' | |
run: | | |
d=$(date '+%Y-%m-%dT%H:%M:%SZ') | |
echo $d > LAST_UPDATED | |
git config --local user.email "[email protected]" | |
git config --local user.name "WysockiD" | |
git add -A | |
arr=("commit(bot): 🐢 auto commit" "commit(bot): 🦖 auto commit" "commit(bot): 🐉 auto commit" "commit(bot): 🐸 auto commit" "commit(bot): 🦠 auto commit" "commit(bot): 🐊 auto commit" "commit(bot): 💚 auto commit" "commit(bot): 🌿 auto commit" "commit(bot): 🟩 auto commit" "commit(bot): 🌵 auto commit") | |
rand=$((RANDOM % ${#arr[@]})) | |
git commit -m "${arr[$rand]}" | |
touch .commit_marker | |
- name: GitHub Push | |
if: steps.commit-check.outputs.commit-check == 'Committing...' | |
uses: ad-m/github-push-action@master | |
with: | |
force: true | |
directory: "." | |
github_token: ${{ secrets.GITHUB_TOKEN }} |