-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ghactions to auto update readme with links to latest releases
- Loading branch information
1 parent
eb9f001
commit 0e10e64
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import re | ||
from github import Github | ||
|
||
GITHUB_TOKEN = os.environ["GITHUB_TOKEN"] | ||
REPO_NAME = os.environ["GITHUB_ACTION_REPOSITORY"] | ||
|
||
g = Github(GITHUB_TOKEN) | ||
repo = g.get_repo(REPO_NAME) | ||
latest_release = repo.get_latest_release() | ||
|
||
assets = latest_release.get_assets() | ||
asset_links = { | ||
"windows": "", | ||
"mac": "", | ||
"linux_deb": "", | ||
"linux_appimage": "", | ||
"linux_rpm": "", | ||
} | ||
|
||
for asset in assets: | ||
if asset.name.endswith(".exe"): | ||
asset_links["windows"] = asset.browser_download_url | ||
elif asset.name.endswith(".dmg"): | ||
asset_links["mac"] = asset.browser_download_url | ||
elif asset.name.endswith(".deb"): | ||
asset_links["linux_deb"] = asset.browser_download_url | ||
elif asset.name.endswith(".AppImage"): | ||
asset_links["linux_appimage"] = asset.browser_download_url | ||
elif asset.name.endswith(".rpm"): | ||
asset_links["linux_rpm"] = asset.browser_download_url | ||
|
||
with open("README.md", "r") as f: | ||
readme_content = f.read() | ||
|
||
new_readme_content = re.sub( | ||
r"<!-- ASSETS_START -->(.|\n)*?<!-- ASSETS_END -->", | ||
f"<!-- ASSETS_START -->\n" | ||
f"### Download links\n\n" | ||
f"| Platform | Download |\n" | ||
f"| -------------- | -------- |\n" | ||
f"| Windows | [Download .exe]({asset_links['windows']}) |\n" | ||
f"| Mac | [Download .dmg]({asset_links['mac']}) |\n" | ||
f"| Linux | |\n" | ||
f"|  Debian/Ubuntu | [Download .deb]({asset_links['linux_deb']}) |\n" | ||
f"|  AppImage | [Download .appimage]({asset_links['linux_appimage']}) |\n" | ||
f"|  RPM-based | [Download .rpm]({asset_links['linux_rpm']}) |\n" | ||
f"<!-- ASSETS_END -->", | ||
readme_content, | ||
) | ||
|
||
with open("README.md", "w") as f: | ||
f.write(new_readme_content) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Update README with Releases | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
update-readme: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Setup Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.x" | ||
- name: Install dependencies | ||
run: pip install PyGithub | ||
- name: Update README.md | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_ACTION_REPOSITORY: ${{ github.repository }} | ||
run: python .github/scripts/update_readme.py | ||
|
||
- name: Commit and push changes | ||
run: | | ||
git config user.name "GitHub Actions Bot" | ||
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" | ||
git add README.md | ||
git commit -m "Update README.md with latest release links" | ||
git push |