From 2a73919ccb6e28a798eea376d06bf00d7ec65d75 Mon Sep 17 00:00:00 2001 From: cxfksword <718792+cxfksword@users.noreply.github.com> Date: Sat, 25 Nov 2023 10:04:51 +0800 Subject: [PATCH] tweak: replace ghproxy --- .github/workflows/beta.yaml | 4 ++ .github/workflows/build.yaml | 6 +- .github/workflows/issue_close_inactive.yml | 15 ++--- .github/workflows/publish.yaml | 52 ++++++++------- .gitignore | 1 + README.md | 6 +- build.meta.json | 13 ---- build.sh | 43 ------------- generate_manifest.py | 74 ++++++++++++++++++++++ 9 files changed, 120 insertions(+), 94 deletions(-) delete mode 100644 build.meta.json delete mode 100755 build.sh create mode 100755 generate_manifest.py diff --git a/.github/workflows/beta.yaml b/.github/workflows/beta.yaml index 23953b3..05574e6 100644 --- a/.github/workflows/beta.yaml +++ b/.github/workflows/beta.yaml @@ -20,8 +20,12 @@ jobs: run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - name: Setup dotnet uses: actions/setup-dotnet@v3 + id: dotnet with: dotnet-version: ${{ env.dotnet-version }} + - name: Change default dotnet version + run: | + echo '{"sdk":{"version": "${{ steps.dotnet.outputs.dotnet-version }}"}}' > ./global.json - name: Initialize workflow variables id: vars run: | diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c9c4c7f..889a178 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -12,11 +12,15 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-dotnet@v3 + id: dotnet with: dotnet-version: 6.0.x + - name: Change default dotnet version + run: | + echo '{"sdk":{"version": "${{ steps.dotnet.outputs.dotnet-version }}"}}' > ./global.json - name: Install dependencies run: dotnet restore - name: Build - run: dotnet build --configuration Release --no-restore + run: dotnet build --no-restore # - name: Test # run: dotnet test --no-restore --verbosity normal diff --git a/.github/workflows/issue_close_inactive.yml b/.github/workflows/issue_close_inactive.yml index 039ce62..9d3434d 100644 --- a/.github/workflows/issue_close_inactive.yml +++ b/.github/workflows/issue_close_inactive.yml @@ -10,12 +10,11 @@ jobs: runs-on: ubuntu-latest steps: - name: close-issues - uses: actions-cool/issues-helper@v3 + uses: actions/stale@v7 with: - actions: "close-issues" - token: ${{ secrets.GITHUB_TOKEN }} - inactive-day: 30 - exclude-labels: "enhancement,bug" - close-reason: "not_planned" - body: | - This issue was closed due to inactive more than 30 days. You can reopen it if you think it should continue. + stale-issue-message: "This issue was closed due to inactive more than 30 days. You can reopen it if you think it should continue." + exempt-issue-labels: "FAQ,question,bug,enhancement" + days-before-stale: 30 + days-before-close: 0 + days-before-pr-stale: -1 + days-before-pr-close: -1 diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index dfbdd50..df294b1 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -21,8 +21,16 @@ jobs: run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - name: Setup dotnet uses: actions/setup-dotnet@v3 + id: dotnet with: dotnet-version: ${{ env.dotnet-version }} + - name: Change default dotnet version + run: | + echo '{"sdk":{"version": "${{ steps.dotnet.outputs.dotnet-version }}"}}' > ./global.json + - name: Setup python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.python-version }} - name: Initialize workflow variables id: vars run: | @@ -35,34 +43,30 @@ jobs: dotnet restore ${{ env.project }} --no-cache dotnet publish --nologo --no-restore --configuration=Release --framework=net6.0 -p:Version=${{steps.vars.outputs.VERSION}} ${{ env.project }} mkdir -p artifacts - cp ./Jellyfin.Plugin.Danmu/bin/Release/net6.0/Jellyfin.Plugin.Danmu.dll ./artifacts/ - - name: Compress build files - uses: thedoctor0/zip-release@main + zip -j ./artifacts/${{ env.artifact }}_${{steps.vars.outputs.VERSION}}.zip ./Jellyfin.Plugin.Danmu/bin/Release/net6.0/Jellyfin.Plugin.Danmu.dll + cp ./doc/logo.png ./artifacts/logo.png + - name: Generate manifest + run: cd artifacts && python3 ../generate_manifest.py ${{ env.artifact }}_${{steps.vars.outputs.VERSION}}.zip ${GITHUB_REF#refs/*/} + - name: Deploy to jellyfin release repo + uses: peaceiris/actions-gh-pages@v3 with: - type: "zip" - directory: "artifacts" - filename: "artifacts.zip" - exclusions: "*.json *.pdb" - - name: Setup python - uses: actions/setup-python@v2 - with: - python-version: ${{ env.python-version }} - - name: Install JPRM - run: python -m pip install jprm - - name: Run JPRM - run: chmod +x ./build.sh && ./build.sh ${{ env.artifact }} ${{steps.vars.outputs.VERSION}} ${GITHUB_REF#refs/*/} + personal_token: ${{ secrets.PAT }} + external_repository: cxfksword/jellyfin-release + destination_dir: ${{ env.artifact }} + publish_branch: master + publish_dir: ./artifacts - name: Publish release uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: ./${{ env.artifact }}/${{ env.artifact }}_*.zip + file: ./artifacts/${{ env.artifact }}_*.zip tag: ${{ github.ref }} file_glob: true - - name: Publish manifest - uses: svenstaro/upload-release-action@v2 - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - file: ./manifest*.json - tag: "manifest" - overwrite: true - file_glob: true + # - name: Publish manifest + # uses: svenstaro/upload-release-action@v2 + # with: + # repo_token: ${{ secrets.GITHUB_TOKEN }} + # file: ./artifacts/manifest*.json + # tag: "manifest" + # overwrite: true + # file_glob: true diff --git a/.gitignore b/.gitignore index 5001f37..8ddde23 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ obj/ .idea/ artifacts **/.DS_Store +*.json \ No newline at end of file diff --git a/README.md b/README.md index 676f6db..cab3d71 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,7 @@ jellyfin弹幕自动下载插件,已支持的弹幕来源:b站,弹弹play 只支持最新的`jellyfin 10.8.x`版本 -添加插件存储库: - -国内加速:https://gh-proxy.com/https://github.com/cxfksword/jellyfin-plugin-danmu/releases/download/manifest/manifest_cn.json - -国外访问:https://github.com/cxfksword/jellyfin-plugin-danmu/releases/download/manifest/manifest.json +添加插件存储库:https://jellyfin-plugin-release.pages.dev/danmu/manifest.json ## 如何使用 diff --git a/build.meta.json b/build.meta.json deleted file mode 100644 index eee1607..0000000 --- a/build.meta.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "category": "Metadata", - "changelog": "NA", - "description": "jellyfin的b站弹幕自动下载插件,会匹配b站番剧/电影视频,自动下载对应弹幕,并定时更新。", - "guid": "5B39DA44-5314-4940-8E26-54C821C17F86", - "imageUrl": "https://github.com/cxfksword/jellyfin-plugin-danmu/raw/main/doc/logo.png", - "name": "Danmu", - "overview": "jellyfin弹幕下载插件", - "owner": "cxfksword", - "targetAbi": "10.8.0.0", - "timestamp": "1970-01-01T00:00:00Z", - "version": "1.0.0.0" -} diff --git a/build.sh b/build.sh deleted file mode 100755 index c42aeb7..0000000 --- a/build.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -# $1 from github action -ARTIFACT=$1 -VERSION=$2 -TAG=$3 - -CURRENT_DATE=$(date +'%Y-%m-%dT%H:%M:%S') -WORK_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P) -ARTIFACT_ZIP_FILE="${WORK_DIR}/artifacts/artifacts.zip" -ARTIFACT_META="${WORK_DIR}/build.meta.json" - -JELLYFIN_REPO_URL="https://github.com/cxfksword/jellyfin-plugin-danmu/releases/download" -JELLYFIN_MANIFEST="${WORK_DIR}/manifest.json" -JELLYFIN_MANIFEST_CN="${WORK_DIR}/manifest_cn.json" -JELLYFIN_MANIFEST_OLD="https://github.com/cxfksword/jellyfin-plugin-danmu/releases/download/manifest/manifest.json" - -# download old manifest -wget -q -O "$JELLYFIN_MANIFEST" "$JELLYFIN_MANIFEST_OLD" -if [ $? -ne 0 ]; then - rm -rf $JELLYFIN_MANIFEST - jprm repo init $WORK_DIR -fi - -# update meta json message -cp -f "${ARTIFACT_META}" "${ARTIFACT_ZIP_FILE}.meta.json" -CHANGELOG=$(git tag -l --format='%(contents)' ${TAG}) -sed -i "s@NA@$CHANGELOG@" "${ARTIFACT_ZIP_FILE}.meta.json" -sed -i "s@1.0.0.0@$VERSION@" "${ARTIFACT_ZIP_FILE}.meta.json" -sed -i "s@1970-01-01T00:00:00Z@$CURRENT_DATE@" "${ARTIFACT_ZIP_FILE}.meta.json" - - -# generate new manifest -jprm --verbosity=debug repo add --url=${JELLYFIN_REPO_URL} "${JELLYFIN_MANIFEST}" "${ARTIFACT_ZIP_FILE}" - -# fix menifest download url -sed -i "s@/${ARTIFACT}/@/$TAG/@" "$JELLYFIN_MANIFEST" - -# 国内加速 -cp -f "$JELLYFIN_MANIFEST" "$JELLYFIN_MANIFEST_CN" -sed -i "s@github.com@gh-proxy.com/https://github.com@g" "$JELLYFIN_MANIFEST_CN" - -exit $? \ No newline at end of file diff --git a/generate_manifest.py b/generate_manifest.py new file mode 100755 index 0000000..99abc88 --- /dev/null +++ b/generate_manifest.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +import hashlib +import json +import sys +import re +import os +import subprocess +from datetime import datetime +from urllib.request import urlopen +from urllib.error import HTTPError + + +def generate_manifest(): + return [{ + "guid": "5B39DA44-5314-4940-8E26-54C821C17F86", + "name": "Danmu", + "description": "jellyfin的b站弹幕自动下载插件,会匹配b站番剧/电影视频,自动下载对应弹幕,并定时更新。", + "overview": "jellyfin弹幕下载插件", + "owner": "cxfksword", + "category": "Metadata", + "imageUrl": "https://jellyfin-plugin-release.pages.dev/danmu/logo.png", + "versions": [] + }] + +def generate_version(filepath, version, changelog): + return { + 'version': f"{version}.0", + 'changelog': changelog, + 'targetAbi': '10.8.0.0', + 'sourceUrl': f'https://jellyfin-plugin-release.pages.dev/danmu/danmu_{version}.0.zip', + 'checksum': md5sum(filepath), + 'timestamp': datetime.now().strftime('%Y-%m-%dT%H:%M:%S') + } + +def md5sum(filename): + with open(filename, 'rb') as f: + return hashlib.md5(f.read()).hexdigest() + + +def main(): + filename = sys.argv[1] + tag = sys.argv[2] + version = tag.lstrip('v') + filepath = os.path.join(os.getcwd(), filename) + result = subprocess.run(['git', 'tag','-l','--format=%(contents)', tag, '-l'], stdout=subprocess.PIPE) + changelog = result.stdout.decode('utf-8').strip() + + # 解析旧 manifest + try: + with urlopen('https://raw.githubusercontent.com/cxfksword/jellyfin-release/master/danmu/manifest.json') as f: + manifest = json.load(f) + except HTTPError as err: + if err.code == 404: + manifest = generate_manifest() + else: + raise + + # 追加新版本/覆盖旧版本 + manifest[0]['versions'] = list(filter(lambda x: x['version'] == version, manifest[0]['versions'])) + manifest[0]['versions'].insert(0, generate_version(filepath, version, changelog)) + + with open('manifest.json', 'w') as f: + json.dump(manifest, f, indent=2) + + # # 国内加速 + # with open('manifest_cn.json', 'w') as f: + # manifest_cn = json.dumps(manifest, indent=2) + # manifest_cn = re.sub('https://github.com/cxfksword/jellyfin-plugin-danmu/raw/main/doc/logo.png', "https://jellyfin-plugin-release.pages.dev/danmu/logo.png", manifest_cn) + # manifest_cn = re.sub('https://github.com/cxfksword/jellyfin-plugin-danmu/releases/download/v[0-9.]+', "https://jellyfin-plugin-release.pages.dev/danmu", manifest_cn) + # f.write(manifest_cn) + + +if __name__ == '__main__': + main() \ No newline at end of file