Skip to content

Commit

Permalink
misc: update build config
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed May 17, 2024
1 parent d6eecae commit ab02a51
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
- name: Run JPRM
env:
CHANGELOG: ${{ needs.current_info.outputs.changelog }}
run: python build_plugin.py --version=${{ needs.current_info.outputs.version }} --prerelease=True
run: python build_plugin.py --repo ${{ github.repository }} --version=${{ needs.current_info.outputs.version }} --prerelease=True

- name: Create Pre-Release
uses: softprops/action-gh-release@v1
Expand Down
22 changes: 13 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ on:
branches: master

jobs:
build:
build_plugin:
runs-on: ubuntu-latest
name: Build & Release
name: Build Release

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@master
with:
ref: ${{ github.ref }}
fetch-depth: 0
fetch-depth: 0 # This is set to download the full git history for the repo

- name: Get release version
id: currenttag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
- name: Get Current Version
id: release_info
uses: revam/gh-action-get-tag-and-version@v1
with:
fallback: 1.0.0
branch: true
prefix: v
prefixRegex: "[vV]?"

- name: Setup .Net
uses: actions/setup-dotnet@v1
Expand All @@ -41,7 +43,9 @@ jobs:
run: python -m pip install jprm

- name: Run JPRM
run: python build_plugin.py --version=${{ steps.currenttag.outputs.tag }}
env:
CHANGELOG: "" # Add the release's change-log here maybe.
run: python build_plugin.py --repo ${{ github.repository }} --version=${{ steps.current_info.outputs.version }}

- name: Update Release
uses: svenstaro/upload-release-action@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ Thumbs.db
Desktop.ini
.DS_Store
/.idea/
/.venv
artifacts
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"imdbid",
"interrobang",
"jellyfin",
"jprm",
"koma",
"linkbutton",
"manhua",
Expand Down
61 changes: 40 additions & 21 deletions build_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,72 @@
import json
import yaml
import argparse
import re

def extract_target_framework(csproj_path):
with open(csproj_path, "r") as file:
content = file.read()
target_framework_match = re.compile(r"<TargetFramework>(.*?)<\/TargetFramework>", re.IGNORECASE).search(content)
target_frameworks_match = re.compile(r"<TargetFrameworks>(.*?)<\/TargetFrameworks>", re.IGNORECASE).search(content)
if target_framework_match:
return target_framework_match.group(1)
elif target_frameworks_match:
return target_frameworks_match.group(1).split(";")[0] # Return the first framework
else:
return None

parser = argparse.ArgumentParser()
parser.add_argument('--version', required=True)
parser.add_argument('--prerelease')
parser.add_argument("--repo", required=True)
parser.add_argument("--version", required=True)
parser.add_argument("--prerelease", default=True)
opts = parser.parse_args()

framework = extract_target_framework("./Shokofin/Shokofin.csproj")
version = opts.version
prerelease = bool(opts.prerelease)

artifact_dir = os.path.join(os.getcwd(), 'artifacts')
os.mkdir(artifact_dir)
artifact_dir = os.path.join(os.getcwd(), "artifacts")
if not os.path.exists(artifact_dir):
os.mkdir(artifact_dir)

if prerelease:
jellyfin_repo_file="./manifest-unstable.json"
jellyfin_repo_file="./manifest-unstable.json"
else:
jellyfin_repo_file="./manifest.json"
jellyfin_repo_file="./manifest.json"

jellyfin_repo_url="https://github.com/ShokoAnime/Shokofin/releases/download"
jellyfin_repo_url=f"https://github.com/{opts.repo}/releases/download"

# Add changelog to the build yaml before we generate the release.
build_file = './build.yaml'
build_file = "./build.yaml"

with open(build_file, 'r') as file:
with open(build_file, "r") as file:
data = yaml.safe_load(file)

if "changelog" in data:
data["changelog"] = os.environ["CHANGELOG"].strip()
if "CHANGELOG" in os.environ:
data["changelog"] = os.environ["CHANGELOG"].strip()
else:
data["changelog"] = ""

with open(build_file, 'w') as file:
with open(build_file, "w") as file:
yaml.dump(data, file, sort_keys=False)

zipfile=os.popen('jprm --verbosity=debug plugin build "." --output="%s" --version="%s" --dotnet-framework="net6.0"' % (artifact_dir, version)).read().strip()
zipfile=os.popen("jprm --verbosity=debug plugin build \".\" --output=\"%s\" --version=\"%s\" --dotnet-framework=\"%s\"" % (artifact_dir, version, framework)).read().strip()

jellyfin_plugin_release_url=f'{jellyfin_repo_url}/{version}/shoko_{version}.zip'
jellyfin_plugin_release_url=f"{jellyfin_repo_url}/{version}/shoko_{version}.zip"

os.system('jprm repo add --plugin-url=%s %s %s' % (jellyfin_plugin_release_url, jellyfin_repo_file, zipfile))
os.system("jprm repo add --plugin-url=%s %s %s" % (jellyfin_plugin_release_url, jellyfin_repo_file, zipfile))

# Compact the unstable manifest after building, so it only contains the last 5 versions.
if prerelease:
with open(jellyfin_repo_file, 'r') as file:
data = json.load(file)
with open(jellyfin_repo_file, "r") as file:
data = json.load(file)

for item in data:
if 'versions' in item and len(item['versions']) > 5:
item['versions'] = item['versions'][:5]
for item in data:
if "versions" in item and len(item["versions"]) > 5:
item["versions"] = item["versions"][:5]

with open(jellyfin_repo_file, 'w') as file:
json.dump(data, file, indent=4)
with open(jellyfin_repo_file, "w") as file:
json.dump(data, file, indent=4)

print(version)

0 comments on commit ab02a51

Please sign in to comment.