Skip to content

Commit 9b1d4ac

Browse files
authored
Update release info (#2)
1 parent a9ff780 commit 9b1d4ac

File tree

9 files changed

+251
-2
lines changed

9 files changed

+251
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Update latest release info
2+
on:
3+
workflow_dispatch:
4+
repository_dispatch:
5+
types: [release]
6+
7+
push:
8+
branches:
9+
- main
10+
11+
pull_request:
12+
branches:
13+
- main
14+
15+
permissions:
16+
contents: write
17+
18+
jobs:
19+
update:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: 3.12
28+
29+
- name: Install uv
30+
uses: astral-sh/[email protected]
31+
with:
32+
version: "latest"
33+
34+
- name: Run update script
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
run: |
38+
cd _scripts/get_release_info
39+
uv run main.py
40+
41+
- name: Commit changes
42+
if: ${{ !contains(fromJSON('["push", "pull_request"]'), github.event_name) }}
43+
uses: EndBug/[email protected]
44+
with:
45+
author_name: github-actions[bot]
46+
author_email: 41898282+github-actions[bot]@users.noreply.github.com
47+
message: "Update release info"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.venv/
2+
.env
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
query getLatestReleaseAssets(
2+
$owner: String!
3+
$name: String!
4+
$first: Int!
5+
) {
6+
repository(owner: $owner, name: $name) {
7+
latestRelease {
8+
releaseAssets(first: $first) {
9+
nodes {
10+
name
11+
downloadUrl
12+
}
13+
}
14+
}
15+
}
16+
}

_scripts/get_release_info/main.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import json
2+
import os
3+
from pathlib import Path
4+
5+
from dotenv import load_dotenv
6+
import httpx
7+
8+
load_dotenv()
9+
10+
current_dir = Path(__file__).parent
11+
query_get_last_release_assets = (current_dir / "getLatestReleaseAssets.graphql").read_text()
12+
url = "https://api.github.com/graphql"
13+
14+
repo_root_dir = current_dir.parent.parent
15+
assert (repo_root_dir / ".git").exists()
16+
output_file = repo_root_dir / "_data/release_assets.json"
17+
18+
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
19+
20+
21+
def main():
22+
response = httpx.post(
23+
url,
24+
json={
25+
"query": query_get_last_release_assets,
26+
"variables": {
27+
"owner": "dfint",
28+
"name": "installer",
29+
"first": 2,
30+
}
31+
},
32+
headers={"Authorization": f"Bearer {GITHUB_TOKEN}"},
33+
timeout=httpx.Timeout(60)
34+
)
35+
response.raise_for_status()
36+
37+
response_json = response.json()
38+
assets = response_json["data"]["repository"]["latestRelease"]["releaseAssets"]["nodes"]
39+
40+
map_os_names = {
41+
"win": "windows",
42+
"lin": "linux",
43+
}
44+
45+
result = {}
46+
for asset in assets:
47+
os_part = asset["name"].split("-")[2]
48+
os_name = map_os_names[os_part]
49+
print(f"{os_name}: {asset['downloadUrl']}")
50+
51+
result[os_name] = {
52+
"name": asset["name"],
53+
"url": asset["downloadUrl"],
54+
}
55+
56+
output_file.write_text(json.dumps(result, indent=4, ensure_ascii=False))
57+
58+
59+
if __name__ == "__main__":
60+
main()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "get-release-info"
3+
version = "0.1.0"
4+
readme = "README.md"
5+
requires-python = ">=3.12"
6+
dependencies = [
7+
"httpx>=0.28.1",
8+
"python-dotenv>=1.1.1",
9+
]

_scripts/get_release_info/uv.lock

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_test.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Test direct download links
22

33
Download Windows version of the Installer:
4-
[{{ site.data.release_files.windows.name }}]({{ site.data.release_files.windows.url }})
4+
[{{ site.data.release_assets.windows.name }}]({{ site.data.release_assets.windows.url }})
55

66
Download Linux version of the Installer:
7-
[{{ site.data.release_files.linux.name }}]({{ site.data.release_files.linux.url }})
7+
[{{ site.data.release_assets.linux.name }}]({{ site.data.release_assets.linux.url }})

0 commit comments

Comments
 (0)