Last active
September 10, 2024 11:14
-
-
Save Xnuvers007/9bb8bcbe0d2927f38eec6527f5b11c06 to your computer and use it in GitHub Desktop.
automation yml for github action to auto commit
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
#!/bin/bash | |
REPO_DIR="$(pwd)" | |
LOG_DIR="$REPO_DIR/logs" | |
LOG_FILE="$LOG_DIR/log.md" | |
if [ ! -d "$LOG_DIR" ]; then | |
mkdir -p "$LOG_DIR" | |
echo "Logs directory created." | |
else | |
echo "Logs directory already exists." | |
fi | |
DATE=$(TZ='Asia/Jakarta' date +"%A, %d %B %Y %H:%M:%S") | |
echo "Log updated at: $DATE (WIB)" > "$LOG_FILE" | |
git add "$LOG_FILE" | |
git config user.name 'Xnuvers007' | |
git config user.email '[email protected]' | |
git commit -m "Jangan Lupa Follow ig: @indradwi.25 web: https://mykingbee.blogspot.com" | |
git push | |
RESPONSE=$(curl -s 'https://quote-generator-api-six.vercel.app/api/quotes/random') | |
QUOTE=$(echo "$RESPONSE" | grep -oP '"quote":\s*"\K[^"]+') | |
CATEGORY=$(echo "$RESPONSE" | grep -oP '"category":\s*"\K[^"]+') | |
if [ -n "$QUOTE" ] || [ -n "$CATEGORY" ]; then | |
echo "Inspirational Quote: \"$QUOTE\" (Category: $CATEGORY)" >> "$LOG_FILE" | |
echo "\n\nSuccessfully fetched the inspirational quote and category." >> "$LOG_FILE" | |
echo "Log file: $LOG_FILE" | |
echo "Log directory: $LOG_DIR" | |
echo "Done!" | |
else | |
echo "Failed to fetch the inspirational quote and category." >> "$LOG_FILE" | |
fi |
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: CI | |
on: | |
push: | |
branches: [ main ] | |
workflow_dispatch: | |
schedule: | |
- cron: '0 */1 * * *' # Runs every 1 hours | |
pull_request: | |
branches: [ main ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository to work with | |
- uses: actions/checkout@v3 | |
# Overwrite log.md with the current Indonesian time (WIB - UTC+7) | |
- name: Overwrite log with Indonesian time | |
run: | | |
# Get the current date and time in Indonesian time (WIB) | |
DATE=$(TZ='Asia/Jakarta' date +"%A, %d %B %Y %H:%M:%S") | |
# Overwrite log.md with the new date and time | |
echo "Log updated at: $DATE (WIB)" > log.md | |
# Add and commit the changes | |
git add log.md | |
git config user.name 'Xnuvers007' | |
git config user.email '[email protected]' | |
git commit -m "Jangan Lupa Follow @indradwi.25" | |
git push || echo "No changes to push" | |
# Display a simple confirmation message | |
- name: Show Message | |
run: echo "log.md overwritten with new Indonesian time. Commit complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment