Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/update-badges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
schedule:
- cron: '0 0 * * *' # Midnight UTC
workflow_dispatch:
# the release build publishes the release, so the pre-release button is never a day behind
workflow_run:
workflows: ["Build Release APKs"]
types: [completed]

permissions:
contents: write
Expand All @@ -25,6 +29,22 @@ jobs:
VERSION=$(gh api repos/$REPO/releases/latest --jq '.tag_name' | sed 's/^v//' 2>/dev/null || echo "N/A")
echo "version=$VERSION" >> $GITHUB_OUTPUT

# Latest pre-release, shown on the Get Pre-release button. Only while it is newer than the latest
# stable release, otherwise the button has no version. The version comes from the APK name
# (LeanType_4.3.3-...) and the beta number from the tag (beta-433-3).
PRE_VERSION=""
PRE=$(gh api "repos/$REPO/releases?per_page=30" --jq '[.[] | select(.prerelease and (.draft | not))] | first // empty' 2>/dev/null || echo "")
if [ -n "$PRE" ]; then
PRE_TAG=$(printf '%s' "$PRE" | jq -r '.tag_name')
PRE_DATE=$(printf '%s' "$PRE" | jq -r '.published_at')
STABLE_DATE=$(gh api repos/$REPO/releases/latest --jq '.published_at' 2>/dev/null || echo "")
if [ -z "$STABLE_DATE" ] || [[ "$PRE_DATE" > "$STABLE_DATE" ]]; then
BASE=$(printf '%s' "$PRE" | jq -r '[.assets[].name | capture("LeanType_(?<v>[0-9]+(\\.[0-9]+)*)-") | .v] | first // empty')
if [ -n "$BASE" ]; then PRE_VERSION="v${BASE}-beta${PRE_TAG##*-}"; else PRE_VERSION="$PRE_TAG"; fi
fi
fi
echo "pre_version=$PRE_VERSION" >> $GITHUB_OUTPUT

# Total downloads
DOWNLOADS=$(gh api repos/$REPO/releases --paginate --jq '.[] | .assets[]?.download_count' 2>/dev/null | jq -s 'add // 0')
echo "downloads=$DOWNLOADS" >> $GITHUB_OUTPUT
Expand All @@ -36,6 +56,7 @@ jobs:
- name: Generate badge SVGs
env:
VERSION: ${{ steps.stats.outputs.version }}
PRE_VERSION: ${{ steps.stats.outputs.pre_version }}
DOWNLOADS: ${{ steps.stats.outputs.downloads }}
STARS: ${{ steps.stats.outputs.stars }}
run: |
Expand All @@ -50,6 +71,16 @@ jobs:
<svg xmlns="http://www.w3.org/2000/svg" width="94" height="28" viewBox="0 0 94 28"><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="94" height="28" rx="4" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="50" height="28" fill="#555"/><rect x="50" width="44" height="28" fill="#7C4DFF"/><rect width="94" height="28" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11"><text x="25" y="19" fill="#010101" fill-opacity=".3">Version</text><text x="25" y="18">Version</text><text x="72" y="19" fill="#010101" fill-opacity=".3">v${VERSION}</text><text x="72" y="18">v${VERSION}</text></g></svg>
EOF

# Get Pre-release button: the same button as before, with the current pre-release version under the title
if [ -n "$PRE_VERSION" ]; then
BUTTON_TEXT='<text x="60" y="30" font-family="Arial, Helvetica, sans-serif" font-size="17" font-weight="600" fill="#ffffff">Get Pre-release</text><text x="60" y="48" font-family="Arial, Helvetica, sans-serif" font-size="13" fill="#b3b3b3">'"$PRE_VERSION"'</text>'
else
BUTTON_TEXT='<text x="60" y="37" font-family="Arial, Helvetica, sans-serif" font-size="18" font-weight="600" fill="#ffffff">Get Pre-release</text>'
fi
cat > docs/badges/get-pre-release.svg << EOF
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="60" viewBox="0 0 240 60"><rect x="1" y="1" width="238" height="58" rx="10" fill="#000000" stroke="#ffffff" stroke-width="2"/><g transform="translate(20,14) scale(1.3333)"><path fill="#ffffff" d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></g>${BUTTON_TEXT}</svg>
EOF

# Downloads count badge
cat > docs/badges/downloads.svg << EOF
<svg xmlns="http://www.w3.org/2000/svg" width="105" height="28" viewBox="0 0 105 28"><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="105" height="28" rx="4" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="64" height="28" fill="#555"/><rect x="64" width="41" height="28" fill="#7C4DFF"/><rect width="105" height="28" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11"><text x="32" y="19" fill="#010101" fill-opacity=".3">Downloads</text><text x="32" y="18">Downloads</text><text x="84.5" y="19" fill="#010101" fill-opacity=".3">${DOWNLOADS_FMT}</text><text x="84.5" y="18">${DOWNLOADS_FMT}</text></g></svg>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ LeanType is available in two purpose-built flavors designed to match your exact
</td>
<td align="center" valign="middle">
<a href="https://github.com/LeanBitLab/LeanType/releases">
<img alt="Get Pre-release" src="docs/images/get-pre-release.svg" height="55">
<img alt="Get Pre-release" src="docs/badges/get-pre-release.svg" height="55">
</a>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion docs/badges/download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/badges/get-pre-release.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion tools/verify_release_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ def verify_release(project_root: str, version: str, version_code: str) -> bool:
badge_content = f.read()
clean_version = re.sub(r'[-_]?beta.*$', '', version, flags=re.IGNORECASE)
expected_badge_text = f"v{clean_version}"
if expected_badge_text in badge_content:
if "beta" in version.lower():
# the badge shows the latest stable release (set by update-badges.yml), the beta version
# is shown on the Get Pre-release button instead
print(" [OK] docs/badges/download.svg follows the latest stable release (not checked for betas)")
elif expected_badge_text in badge_content:
print(f" [OK] docs/badges/download.svg matches {expected_badge_text}")
else:
print(f" [FAIL] docs/badges/download.svg does not contain '{expected_badge_text}'")
Expand Down