Skip to content

Commit 8d38ac4

Browse files
author
LeanBitLab
committed
ci: add scheduled workflow to update badges
1 parent e1ddfa0 commit 8d38ac4

4 files changed

Lines changed: 56 additions & 2 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Update Badges Daily
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
update-badges:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@v4
17+
18+
- name: Fetch Stars and Downloads and Download Badges
19+
run: |
20+
# Fetch repository stars count
21+
STARS=$(curl -s "https://api.github.com/repos/LeanBitLab/Lwidget" | jq '.stargazers_count')
22+
if [ "$STARS" = "null" ] || [ -z "$STARS" ]; then
23+
STARS=0
24+
fi
25+
echo "Stars: $STARS"
26+
27+
# Fetch releases and calculate total download count
28+
RELEASES_JSON=$(curl -s "https://api.github.com/repos/LeanBitLab/Lwidget/releases")
29+
DOWNLOADS=$(echo "$RELEASES_JSON" | jq '[.[].assets[].download_count] | add')
30+
if [ "$DOWNLOADS" = "null" ] || [ -z "$DOWNLOADS" ]; then
31+
DOWNLOADS=0
32+
fi
33+
echo "Downloads: $DOWNLOADS"
34+
35+
# Create directory if it doesn't exist
36+
mkdir -p docs/images
37+
38+
# Download badges from Shields.io
39+
curl -L -o docs/images/stars_badge.svg "https://img.shields.io/badge/Stars-${STARS}-7C4DFF?style=flat-square"
40+
curl -L -o docs/images/downloads_badge.svg "https://img.shields.io/badge/Downloads-${DOWNLOADS}-7C4DFF?style=flat-square"
41+
42+
- name: Commit and Push Badges
43+
run: |
44+
git config --global user.name "github-actions[bot]"
45+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
46+
git add docs/images/stars_badge.svg docs/images/downloads_badge.svg
47+
if git diff --staged --quiet; then
48+
echo "No changes in badge metrics"
49+
else
50+
git commit -m "chore: update daily downloads and stars badges [skip ci]"
51+
git push
52+
fi

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
<p align="center">
1010
<a href="https://github.com/LeanBitLab/Lwidget/releases/latest"><img src="https://img.shields.io/github/v/release/LeanBitLab/Lwidget?label=Download&style=flat-square&color=7C4DFF" alt="Download"></a>
11-
<a href="https://github.com/LeanBitLab/Lwidget/releases"><img src="https://img.shields.io/github/downloads/LeanBitLab/Lwidget/total?style=flat-square&color=7C4DFF&label=Downloads" alt="Downloads"></a>
12-
<a href="https://github.com/LeanBitLab/Lwidget/stargazers"><img src="https://img.shields.io/github/stars/LeanBitLab/Lwidget?style=flat-square&color=7C4DFF" alt="Stars"></a>
11+
<a href="https://github.com/LeanBitLab/Lwidget/releases"><img src="docs/images/downloads_badge.svg" alt="Downloads"></a>
12+
<a href="https://github.com/LeanBitLab/Lwidget/stargazers"><img src="docs/images/stars_badge.svg" alt="Stars"></a>
1313
</p>
1414

1515
**Lwidget** is a modern, open-source Android widget built with **Kotlin** and **Material 3** design principles. It provides essential information at a glance while adhering to your device's dynamic theme.

docs/images/downloads_badge.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/images/stars_badge.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)