Skip to content

feat(bilibili-analyzer): replace yt-dlp with native Bilibili API inte… #51

feat(bilibili-analyzer): replace yt-dlp with native Bilibili API inte…

feat(bilibili-analyzer): replace yt-dlp with native Bilibili API inte… #51

Workflow file for this run

name: CI
permissions:
contents: write
on:
push:
branches: ["**"]
tags: ["v*"]
pull_request:
workflow_dispatch:
inputs:
version:
description: "Release version (e.g., 1.2.3)"
required: true
type: string
release_notes:
description: "Release notes / changelog"
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Compute version
id: version
shell: bash
run: |
set -euo pipefail
BASE_VERSION="1.0"
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
VERSION="${{ inputs.version }}"
elif [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF_NAME#v}"
else
VERSION="${BASE_VERSION}.${GITHUB_RUN_NUMBER}"
fi
VERSION="${VERSION#v}"
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
echo "Version: ${VERSION}"
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "10.0.x"
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: web/package-lock.json
- name: Install frontend dependencies
working-directory: web
run: npm ci
- name: Build frontend
working-directory: web
run: npm run build
- name: Sync frontend into backend wwwroot
shell: bash
run: |
set -euo pipefail
mkdir -p src/MyYuCode/wwwroot
rsync -a --delete web/dist/ src/MyYuCode/wwwroot/
- name: Build backend
if: github.event_name != 'workflow_dispatch'
run: dotnet build src/MyYuCode/MyYuCode.csproj -c Release -p:Version=${{ steps.version.outputs.version }} -p:InformationalVersion=${{ steps.version.outputs.version }}
- name: Publish backend
if: github.event_name == 'workflow_dispatch'
shell: bash
run: |
set -euo pipefail
for RID in linux-x64 osx-x64; do
dotnet publish src/MyYuCode/MyYuCode.csproj -c Release -r "${RID}" --self-contained false -o "artifacts/publish/${RID}" -p:Version=${{ steps.version.outputs.version }} -p:InformationalVersion=${{ steps.version.outputs.version }}
done
WIN_PUBLISH_ROOT="artifacts/publish/win-x64"
rm -rf "${WIN_PUBLISH_ROOT}"
mkdir -p "${WIN_PUBLISH_ROOT}"
dotnet publish src/MyYuCode.Win/MyYuCode.Win.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -p:Version=${{ steps.version.outputs.version }} -p:InformationalVersion=${{ steps.version.outputs.version }} -p:DebugType=None -p:DebugSymbols=false -o "${WIN_PUBLISH_ROOT}"
if [[ ! -f "${WIN_PUBLISH_ROOT}/MyYuCode.Win.exe" ]]; then
echo "MyYuCode.Win.exe not found in win-x64 publish output."
exit 1
fi
- name: Add platform scripts
if: github.event_name == 'workflow_dispatch'
shell: bash
run: |
set -euo pipefail
cat > "artifacts/publish/linux-x64/run.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
export DOTNET_ENVIRONMENT=Production
export ASPNETCORE_URLS="http://0.0.0.0:9110"
echo "MyYuCode is running at $ASPNETCORE_URLS"
echo "Open: http://localhost:9110"
if [[ -f "./MyYuCode" ]]; then
chmod +x "./MyYuCode"
./MyYuCode
else
dotnet "./MyYuCode.dll"
fi
EOF
chmod +x "artifacts/publish/linux-x64/run.sh"
cat > "artifacts/publish/linux-x64/install-service.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
SERVICE_NAME="${SERVICE_NAME:-myyucode}"
URLS="${URLS:-http://0.0.0.0:9110}"
INSTALL_DIR="$(cd "$(dirname "$0")" && pwd)"
if [[ $EUID -ne 0 ]]; then
echo "Run this script with sudo." >&2
exit 1
fi
if [[ -x "$INSTALL_DIR/MyYuCode" ]]; then
EXECUTABLE="$INSTALL_DIR/MyYuCode"
elif [[ -f "$INSTALL_DIR/MyYuCode.dll" ]]; then
DOTNET_PATH="$(command -v dotnet || true)"
if [[ -z "$DOTNET_PATH" ]]; then
echo "dotnet not found in PATH." >&2
exit 1
fi
EXECUTABLE="$DOTNET_PATH $INSTALL_DIR/MyYuCode.dll"
else
echo "MyYuCode executable not found in $INSTALL_DIR" >&2
exit 1
fi
SERVICE_PATH="/etc/systemd/system/${SERVICE_NAME}.service"
cat > "$SERVICE_PATH" <<SERVICE_EOF
[Unit]
Description=MyYuCode service
After=network.target
[Service]
WorkingDirectory=$INSTALL_DIR
ExecStart=$EXECUTABLE --urls $URLS
Restart=always
RestartSec=5
Environment=DOTNET_ENVIRONMENT=Production
Environment=ASPNETCORE_URLS=$URLS
[Install]
WantedBy=multi-user.target
SERVICE_EOF
systemctl daemon-reload
systemctl enable --now "$SERVICE_NAME"
systemctl status "$SERVICE_NAME" --no-pager
echo "URL: $URLS"
echo "Open: http://localhost:9110"
EOF
chmod +x "artifacts/publish/linux-x64/install-service.sh"
cat > "artifacts/publish/osx-x64/run.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
export DOTNET_ENVIRONMENT=Production
export ASPNETCORE_URLS="http://0.0.0.0:9110"
echo "MyYuCode is running at $ASPNETCORE_URLS"
echo "Open: http://localhost:9110"
if [[ -f "./MyYuCode" ]]; then
chmod +x "./MyYuCode"
./MyYuCode
else
dotnet "./MyYuCode.dll"
fi
EOF
chmod +x "artifacts/publish/osx-x64/run.sh"
cat > "artifacts/publish/osx-x64/install-service.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
SERVICE_NAME="${SERVICE_NAME:-com.myyucode.service}"
URLS="${URLS:-http://0.0.0.0:9110}"
INSTALL_DIR="$(cd "$(dirname "$0")" && pwd)"
if [[ $EUID -ne 0 ]]; then
echo "Run this script with sudo." >&2
exit 1
fi
if [[ -x "$INSTALL_DIR/MyYuCode" ]]; then
program_args=("$INSTALL_DIR/MyYuCode" "--urls" "$URLS")
else
dll="$INSTALL_DIR/MyYuCode.dll"
if [[ ! -f "$dll" ]]; then
echo "MyYuCode executable not found in $INSTALL_DIR" >&2
exit 1
fi
dotnet_path="$(command -v dotnet || true)"
if [[ -z "$dotnet_path" ]]; then
for candidate in /usr/local/share/dotnet/dotnet /opt/homebrew/bin/dotnet; do
if [[ -x "$candidate" ]]; then
dotnet_path="$candidate"
break
fi
done
fi
if [[ -z "$dotnet_path" ]]; then
echo "dotnet not found in PATH." >&2
exit 1
fi
program_args=("$dotnet_path" "$dll" "--urls" "$URLS")
fi
plist_path="/Library/LaunchDaemons/${SERVICE_NAME}.plist"
{
echo '<?xml version="1.0" encoding="UTF-8"?>'
echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
echo '<plist version="1.0">'
echo '<dict>'
echo ' <key>Label</key>'
echo " <string>${SERVICE_NAME}</string>"
echo ' <key>ProgramArguments</key>'
echo ' <array>'
for arg in "${program_args[@]}"; do
printf ' <string>%s</string>\n' "$arg"
done
echo ' </array>'
echo ' <key>WorkingDirectory</key>'
echo " <string>${INSTALL_DIR}</string>"
echo ' <key>EnvironmentVariables</key>'
echo ' <dict>'
echo ' <key>DOTNET_ENVIRONMENT</key>'
echo ' <string>Production</string>'
echo ' <key>ASPNETCORE_URLS</key>'
echo " <string>${URLS}</string>"
echo ' </dict>'
echo ' <key>RunAtLoad</key>'
echo ' <true/>'
echo ' <key>KeepAlive</key>'
echo ' <true/>'
echo ' <key>StandardOutPath</key>'
echo " <string>${INSTALL_DIR}/myyucode.out.log</string>"
echo ' <key>StandardErrorPath</key>'
echo " <string>${INSTALL_DIR}/myyucode.err.log</string>"
echo '</dict>'
echo '</plist>'
} > "$plist_path"
launchctl bootout system "$plist_path" >/dev/null 2>&1 || true
launchctl bootstrap system "$plist_path"
launchctl enable system/"${SERVICE_NAME}"
launchctl kickstart -k system/"${SERVICE_NAME}"
echo "URL: $URLS"
echo "Open: http://localhost:9110"
EOF
chmod +x "artifacts/publish/osx-x64/install-service.sh"
- name: Package release assets
if: github.event_name == 'workflow_dispatch'
shell: bash
run: |
set -euo pipefail
mkdir -p artifacts
tar -czf "artifacts/MyYuCode-${{ steps.version.outputs.version }}-linux-x64.tar.gz" -C artifacts/publish/linux-x64 .
tar -czf "artifacts/MyYuCode-${{ steps.version.outputs.version }}-osx-x64.tar.gz" -C artifacts/publish/osx-x64 .
(cd artifacts/publish/win-x64 && zip -r "../../MyYuCode-${{ steps.version.outputs.version }}-win-x64.zip" .)
- name: Create release
if: github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ github.token }}
RELEASE_NOTES: ${{ inputs.release_notes }}
shell: bash
run: |
set -euo pipefail
TAG="v${{ steps.version.outputs.version }}"
ASSETS=(
"artifacts/MyYuCode-${{ steps.version.outputs.version }}-linux-x64.tar.gz"
"artifacts/MyYuCode-${{ steps.version.outputs.version }}-osx-x64.tar.gz"
"artifacts/MyYuCode-${{ steps.version.outputs.version }}-win-x64.zip"
)
gh release create "${TAG}" "${ASSETS[@]}" --title "${TAG}" --notes "${RELEASE_NOTES}" --target "${GITHUB_SHA}"