Skip to content

Commit 8a79319

Browse files
authored
Add GitHub Actions workflow to update quote log
1 parent dc75c64 commit 8a79319

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

.github/workflows/quote.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Update Quote Log
2+
3+
on:
4+
schedule:
5+
- cron: "*/5 * * * *"
6+
workflow_dispatch:
7+
push:
8+
paths:
9+
- ".github/workflows/quote.yml"
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
with:
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
fetch-depth: 0
22+
23+
- name: Fetch Random Anime Quote & Write to Log
24+
run: |
25+
# Fetch all quotes
26+
curl -s https://cabrata.github.io/quotesnime-database/quotes.json -o quotes.json
27+
28+
# Ambil random index
29+
COUNT=$(jq length quotes.json)
30+
if [ "$COUNT" -eq 0 ]; then
31+
echo "No quotes found!"
32+
exit 1
33+
fi
34+
INDEX=$((RANDOM % COUNT))
35+
36+
# Ambil field dari quote terpilih
37+
CHAR=$(jq -r ".[$INDEX].character" quotes.json)
38+
ANIME=$(jq -r ".[$INDEX].anime" quotes.json)
39+
QUOTE=$(jq -r ".[$INDEX].quotes" quotes.json)
40+
41+
# Waktu saat ini (WIB)
42+
TIME=$(TZ='Asia/Jakarta' date '+%Y-%m-%d %H:%M:%S WIB')
43+
44+
# Tulis ke log.txt.
45+
# (Timestamp dimasukkan ke dalam file agar isi file SELALU berubah dan memicu commit rutin untuk "penghijauan" profil)
46+
cat > log.txt << EOF
47+
Last updated: $TIME
48+
49+
Character: $CHAR
50+
Anime: $ANIME
51+
52+
"$QUOTE"
53+
EOF
54+
55+
# Hapus file json sementara agar tidak ikut ter-commit ke repo
56+
rm quotes.json
57+
58+
- name: Commit and Push
59+
run: |
60+
git config --global user.name 'RusdiEneri'
61+
git config --global user.email 'nuruddinrusydiilham@gmail.com'
62+
git add log.txt
63+
git diff --cached --quiet || git commit -m "chore: update quote log ($(TZ='Asia/Jakarta' date '+%Y-%m-%d %H:%M WIB'))"
64+
git push

0 commit comments

Comments
 (0)