Skip to content

auto-commit

auto-commit #793

Workflow file for this run

name: auto-commit
on:
push:
branches:
- main
# Schedule the workflow to run at random times within the specified time range
schedule:
- cron: "0 * * * *"
jobs:
auto_commit:
runs-on: ubuntu-latest
steps:
- name: Check if the random time to commit
run: |
current_hour=$(date '+%H')
# Define a range for random hours, e.g., 9 to 18
random_hour=$(shuf -i 9-18 -n 1)
if [ "$current_hour" == "$random_hour" ]; then
# Randomly decide whether to commit or not
if (( RANDOM % 2 == 0 )); then
echo "Committing..."
touch .commit_marker
else
echo "Not committing."
fi
else
echo "Not committing."
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 }}