Skip to content

Commit 7b92a81

Browse files
committed
build: update build script
1 parent 3513da7 commit 7b92a81

File tree

4 files changed

+95
-74
lines changed

4 files changed

+95
-74
lines changed

.github/workflows/publish.yaml

+24-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
env:
88
dotnet-version: 6.0.x
9-
python-version: 3.8
9+
python-version: 3.10
1010
project: Jellyfin.Plugin.MetaShark/Jellyfin.Plugin.MetaShark.csproj
1111
artifact: metashark
1212

@@ -23,6 +23,10 @@ jobs:
2323
uses: actions/setup-dotnet@v3
2424
with:
2525
dotnet-version: ${{ env.dotnet-version }}
26+
- name: Setup python
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: ${{ env.python-version }}
2630
- name: Initialize workflow variables
2731
id: vars
2832
run: |
@@ -41,28 +45,30 @@ jobs:
4145
with:
4246
type: "zip"
4347
directory: "artifacts"
44-
filename: "artifacts.zip"
48+
filename: "${{ env.artifact }}_${{steps.vars.outputs.VERSION}}.zip"
4549
exclusions: "*.json *.pdb"
46-
- name: Setup python
47-
uses: actions/setup-python@v2
50+
- name: Generate manifest
51+
run: cd artifacts && python3 ../generate_manifest.py ${{ env.artifact }}_${{steps.vars.outputs.VERSION}}.zip ${GITHUB_REF#refs/*/}
52+
- name: Deploy to jellyfin release repo
53+
uses: peaceiris/actions-gh-pages@v3
4854
with:
49-
python-version: ${{ env.python-version }}
50-
- name: Install JPRM
51-
run: python -m pip install jprm
52-
- name: Run JPRM
53-
run: chmod +x ./build.sh && ./build.sh ${{ env.artifact }} ${{steps.vars.outputs.VERSION}} ${GITHUB_REF#refs/*/}
55+
deploy_key: ${{ secrets.PAT }}
56+
external_repository: cxfksword/jellyfin-release
57+
destination_dir: ${{ env.artifact }}
58+
publish_branch: master
59+
publish_dir: ./artifacts
5460
- name: Publish release
5561
uses: svenstaro/upload-release-action@v2
5662
with:
5763
repo_token: ${{ secrets.GITHUB_TOKEN }}
58-
file: ./${{ env.artifact }}/${{ env.artifact }}_*.zip
64+
file: ./artifacts/${{ env.artifact }}_*.zip
5965
tag: ${{ github.ref }}
6066
file_glob: true
61-
- name: Publish manifest
62-
uses: svenstaro/upload-release-action@v2
63-
with:
64-
repo_token: ${{ secrets.GITHUB_TOKEN }}
65-
file: ./manifest*.json
66-
tag: "manifest"
67-
overwrite: true
68-
file_glob: true
67+
# - name: Publish manifest
68+
# uses: svenstaro/upload-release-action@v2
69+
# with:
70+
# repo_token: ${{ secrets.GITHUB_TOKEN }}
71+
# file: ./artifacts/manifest*.json
72+
# tag: "manifest"
73+
# overwrite: true
74+
# file_glob: true

build.meta.json

-13
This file was deleted.

build.sh

-43
This file was deleted.

generate_manifest.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python3
2+
import hashlib
3+
import json
4+
import sys
5+
import re
6+
import os
7+
import subprocess
8+
from datetime import datetime
9+
from urllib.request import urlopen
10+
from urllib.error import HTTPError
11+
12+
def generate_manifest():
13+
return [{
14+
"guid": "9a19103f-16f7-4668-be54-9a1e7a4f7556",
15+
"name": "MetaShark",
16+
"description": "jellyfin电影元数据插件,影片信息只要从豆瓣获取,并由TMDB补充缺失的剧集数据。",
17+
"overview": "jellyfin电影元数据插件",
18+
"owner": "cxfksword",
19+
"category": "Metadata",
20+
"imageUrl": "https://github.com/cxfksword/jellyfin-plugin-metashark/raw/main/doc/logo.png",
21+
"versions": []
22+
}]
23+
24+
def generate_version(filepath, version, changelog):
25+
return {
26+
'version': f"{version}.0",
27+
'changelog': changelog,
28+
'targetAbi': '10.8.0.0',
29+
'sourceUrl': f'https://github.com/cxfksword/jellyfin-plugin-metashark/releases/download/v{version}/metashark_{version}.0.zip',
30+
'checksum': md5sum(filepath),
31+
'timestamp': datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
32+
}
33+
34+
def md5sum(filename):
35+
with open(filename, 'rb') as f:
36+
return hashlib.md5(f.read()).hexdigest()
37+
38+
39+
def main():
40+
filename = sys.argv[1]
41+
tag = sys.argv[2]
42+
version = tag.removeprefix('v')
43+
filepath = os.path.join(os.getcwd(), filename)
44+
result = subprocess.run(['git', 'tag','-l','--format=%(contents)', tag, '-l'], stdout=subprocess.PIPE)
45+
changelog = result.stdout.decode('utf-8').strip()
46+
47+
# 解析旧 manifest
48+
try:
49+
with urlopen('https://github.com/cxfksword/jellyfin-plugin-metashark/releases/download/manifest/maniest.json') as f:
50+
manifest = json.load(f)
51+
except HTTPError as err:
52+
if err.code == 404:
53+
manifest = generate_manifest()
54+
else:
55+
raise
56+
57+
# 追加新版本
58+
manifest[0]['versions'].insert(0, generate_version(filepath, version, changelog))
59+
60+
with open('manifest.json', 'w') as f:
61+
json.dump(manifest, f, indent=2)
62+
63+
# 国内加速
64+
with open('manifest_cn.json', 'w') as f:
65+
manifest_cn = json.dumps(manifest, indent=2)
66+
manifest_cn = re.sub("github.com", "gh-proxy.com/https://github.com", manifest_cn)
67+
f.write(manifest_cn)
68+
69+
70+
if __name__ == '__main__':
71+
main()

0 commit comments

Comments
 (0)