Skip to content

Commit 508ef8c

Browse files
committed
ci(fix): Multi Platform
1 parent 6f8f3ae commit 508ef8c

File tree

6 files changed

+98
-65
lines changed

6 files changed

+98
-65
lines changed

.github/get_version.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import re
2+
def get_version():
3+
with open("./src/main.html", "r", encoding="utf-8") as f:
4+
content = f.read()
5+
pattern = re.compile(r'const VERSION = "([0-9.]+)";')
6+
version = pattern.search(content).group(1)
7+
print(f"Version: {version}")
8+
return version

.github/release.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from get_version import get_version
2+
from os import getenv
3+
version = get_version()
4+
5+
DOWNLOAD_URL = "https://github.com/xuanzhi33/smcl/releases/download/"
6+
MIRROR = "https://mirror.ghproxy.com/"
7+
os_list = ["Windows", "Linux", "macOS"]
8+
9+
download_md = ""
10+
for os_name in os_list:
11+
filename = f"SMCL-{version}-{os_name}.zip"
12+
url = f"{MIRROR}{DOWNLOAD_URL}{version}/{filename}"
13+
download_md += f"- {os_name}: [{filename}]({url})\n"
14+
15+
release_notes = f"""
16+
## Download / 下载
17+
{download_md}
18+
## Notes / 说明
19+
- Zip Password / 解压密码: `smcl`
20+
- Please extract and run smcl.exe / 下载后请解压并运行 smcl.exe
21+
"""
22+
23+
with open("release_notes.md", "w", encoding="utf-8") as f:
24+
f.write(release_notes)
25+
26+
27+
gh_env = getenv("GITHUB_ENV")
28+
29+
if gh_env is not None:
30+
print(f"Writing: {gh_env}")
31+
with open(gh_env, "a") as f:
32+
f.write(f"smcl_version={version}\n")

.github/release_util.py

-55
This file was deleted.

.github/setup_env.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from get_version import get_version
2+
from platform import system
3+
from os import getenv
4+
version = get_version()
5+
os_name = system()
6+
7+
if os_name == "Darwin":
8+
os_name = "macOS"
9+
10+
envs = {
11+
"smcl_version": version,
12+
"smcl_filename": f"SMCL-{version}-{os_name}.zip"
13+
}
14+
15+
gh_env = getenv("GITHUB_ENV")
16+
17+
if gh_env is not None:
18+
print(f"Writing: {gh_env}")
19+
with open(gh_env, "a") as f:
20+
for key, value in envs.items():
21+
f.write(f"{key}={value}\n")

.github/workflows/build.yml

+35-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
name: publish
1+
name: Release
22

33
on:
44
push:
55
branches: [ "main" ]
66

77
jobs:
8-
build-and-publish:
8+
build:
99
strategy:
1010
matrix:
11-
os: [windows-latest, ubuntu-latest, macos-latest]
11+
os: [ windows-latest, ubuntu-latest, macos-latest ]
1212
runs-on: ${{ matrix.os }}
13-
permissions:
14-
contents: write
1513
steps:
16-
- uses: actions/checkout@v4
14+
- name: Checkout
15+
uses: actions/checkout@v4
1716
- name: Set up Python
1817
uses: actions/setup-python@v5
1918
with:
@@ -24,17 +23,44 @@ jobs:
2423
- name: Build
2524
run: |
2625
python build.py
27-
- name: Run release script
26+
- name: Setup env
2827
run: |
29-
python .github/release_util.py
28+
python .github/setup_env.py
3029
- name: Zip
3130
run: |
3231
7z a ${{ env.smcl_filename }} ./dist/smcl/* -p"smcl"
32+
- name: Upload
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: ${{ matrix.os }}
36+
path: ${{ env.smcl_filename }}
37+
38+
release:
39+
needs: build
40+
runs-on: ubuntu-latest
41+
permissions:
42+
contents: write
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v4
46+
- name: Set up Python
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: '3.11'
50+
- name: Run release.py
51+
run: |
52+
python .github/release.py
53+
- name: Download artifact
54+
uses: actions/download-artifact@v4
55+
with:
56+
merge-multiple: true
3357
- name: Release
3458
uses: softprops/action-gh-release@v2
3559
with:
3660
files: |
37-
${{ env.smcl_filename }}
61+
smcl-${{ env.smcl_version }}-Windows.zip
62+
smcl-${{ env.smcl_version }}-Linux.zip
63+
smcl-${{ env.smcl_version }}-macOS.zip
3864
tag_name: ${{ env.smcl_version }}
3965
generate_release_notes: true
4066
body_path: release_notes.md

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ test
66
test.py
77
.minecraft
88
src/cmcl.json
9-
__pycache__
9+
__pycache__
10+
release_notes.md

0 commit comments

Comments
 (0)