Files
wrong-notebook/.github/workflows/packages.yml
margrop 45988361a2 feat: 群晖与威联通套件内置镜像,安装时无需联网拉取
- 发版时等同一标签的镜像推送后用 skopeo 按架构导出,套件按 x86_64 / arm64 分别出包
- 群晖经 docker-project 的 preload-image 加载;威联通把归档放进架构目录,启动时 docker load
- 威联通启动时本地已有该版本镜像就不再联网拉取,重启和断网时不依赖镜像仓库;升级后清理旧版本镜像
- 不传 --image 时仍生成在线拉取镜像的 noarch 套件,用于本地调试
2026-11-11 17:16:34 +08:00

629 lines
26 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Packages
# 全平台安装包:npm、Windows、macOS、Linux、飞牛OS、群晖、威联通、安卓(单机版、客户端版,各分手机版、平板版)
# Prisma 引擎与构建机平台绑定,因此原生平台在对应架构的 Runner 上分别构建;
# 群晖/威联通为 Docker 套件,发版时内置同版本镜像并按 x86_64 / arm64 分别出包,其余情况生成在线拉取镜像的 noarch 套件
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
windows_signing:
description: 'Windows 签名:auto 按 SIGNPATH_ENABLED 决定生产签名;test 仅限 main,用 SignPath 测试证书签名并单独上传,不替换安装包'
type: choice
options:
- auto
- test
default: auto
permissions:
contents: write
env:
NEXT_TELEMETRY_DISABLED: 1
jobs:
npm:
name: npm
runs-on: ubuntu-24.04
# 只在 GitHub 上运行;Gitea 读取 main 时会回退到本目录,需跳过
if: github.server_url == 'https://github.com'
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '24'
cache: 'npm'
- name: Resolve version
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "PACKAGE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
fi
- name: Cache Next.js build
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ github.workspace }}/.next/cache
key: nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
restore-keys: |
nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-
nextjs-${{ runner.os }}-${{ runner.arch }}-
- run: npm ci --no-audit --no-fund
- name: Build bundle and npm package
run: |
node scripts/package/build.mjs bundle
node scripts/package/build.mjs npm
- name: Smoke test npm package
shell: bash
run: |
set -euo pipefail
prefix="$(mktemp -d)"
data="$(mktemp -d)"
npm install -g --prefix "$prefix" ./dist/wrong-notebook-*.tgz
"$prefix/bin/wrong-notebook" --port 39400 --host 127.0.0.1 --data-dir "$data" > "$data/server.log" 2>&1 &
for _ in $(seq 1 90); do
if curl -sf http://127.0.0.1:39400/api/health; then exit 0; fi
sleep 1
done
cat "$data/server.log"
exit 1
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: package-npm
path: dist/wrong-notebook-*.tgz
if-no-files-found: error
# 发布单独成一个 Job:npm 发布失败不影响安装包上传到 Release
# 使用 npm Trusted Publishing(OIDC),无需 NPM_TOKEN;需在 npmjs.com 包设置中登记本仓库的 packages.yml
npm-publish:
name: Publish to npm
needs: npm
if: github.server_url == 'https://github.com' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-24.04
permissions:
contents: read
id-token: write
steps:
# Trusted Publishing 需要 npm 11.5.1 及以上,Node.js 24 自带
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: package-npm
path: dist
- name: Publish
shell: bash
run: |
npm --version
tag=latest
if [[ "$GITHUB_REF_NAME" == *-* ]]; then tag=next; fi
# OIDC 换取令牌失败时 npm 只在 verbose 日志中说明原因,这里筛出认证相关的行
npm publish ./dist/wrong-notebook-*.tgz --access public --provenance --tag "$tag" --loglevel verbose 2>&1 \
| grep -viE '^npm (notice|verbose) +[0-9.]+[kMB]* ' \
| grep -iE 'oidc|trust|token|auth|provenance|publish|error|^\+ '
desktop:
name: Desktop (${{ matrix.name }})
if: github.server_url == 'https://github.com'
strategy:
fail-fast: false
matrix:
include:
- name: windows-x64
os: windows-latest
args: --win --x64
- name: macos-arm64
os: macos-latest
args: --mac --arm64
- name: macos-x64
os: macos-15-intel
args: --mac --x64
- name: linux-x64
os: ubuntu-24.04
args: --linux --x64
- name: linux-arm64
os: ubuntu-24.04-arm
args: --linux --arm64
runs-on: ${{ matrix.os }}
timeout-minutes: 60
permissions:
contents: read
actions: read
env:
# production:SIGNPATH_ENABLED=true 时对 main 和版本标签签名;test:在 main 手动运行时用测试证书试签。
# 其他情况(含分支试构建)保持原有的未签名流程。
SIGNPATH_MODE: ${{ matrix.name != 'windows-x64' && 'off' || (github.event_name == 'workflow_dispatch' && inputs.windows_signing == 'test' && github.ref == 'refs/heads/main') && 'test' || (vars.SIGNPATH_ENABLED == 'true' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')) && 'production' || 'off' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '24'
cache: 'npm'
- name: Resolve version
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "PACKAGE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
fi
# electron-builder 自带的 fpm 只有 x86_64 版本,arm64 上改用系统 fpm 生成 deb
- name: Install fpm (linux arm64)
if: matrix.name == 'linux-arm64'
run: |
sudo apt-get update
sudo apt-get install -y ruby ruby-dev build-essential
sudo gem install --no-document fpm
echo "USE_SYSTEM_FPM=true" >> "$GITHUB_ENV"
- name: Cache Next.js and Electron binaries
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
${{ github.workspace }}/.next/cache
~/.cache/electron
~/.cache/electron-builder
~/Library/Caches/electron
~/Library/Caches/electron-builder
~/AppData/Local/electron/Cache
~/AppData/Local/electron-builder/Cache
key: desktop-${{ matrix.name }}-${{ hashFiles('package-lock.json', 'packaging/desktop/package.json') }}-${{ github.sha }}
restore-keys: |
desktop-${{ matrix.name }}-${{ hashFiles('package-lock.json', 'packaging/desktop/package.json') }}-
desktop-${{ matrix.name }}-
- run: npm ci --no-audit --no-fund
- name: Build bundle
run: node scripts/package/build.mjs bundle
- name: Build desktop installers (unsigned)
shell: bash
env:
# GitHub release-assets CDN 偶发 504,改用国内 Electron 镜像下载运行时
ELECTRON_MIRROR: https://npmmirror.com/mirrors/electron/
ELECTRON_BUILDER_BINARIES_MIRROR: https://npmmirror.com/mirrors/electron-builder-binaries/
CSC_IDENTITY_AUTO_DISCOVERY: 'false'
run: |
# GitHub release-assets CDN 偶发 504;重试可利用 electron-builder 缓存继续下载
for attempt in 1 2 3; do
if node scripts/package/build.mjs desktop ${{ matrix.args }}; then exit 0; fi
if [[ "$attempt" -eq 3 ]]; then exit 1; fi
echo "桌面安装包构建失败,30 秒后第 $((attempt + 1)) 次重试"
sleep 30
done
- name: 检查 Windows 签名配置与安装包元数据
if: env.SIGNPATH_MODE != 'off'
id: windows-signing
shell: pwsh
env:
SIGNPATH_API_TOKEN: ${{ secrets.SIGNPATH_API_TOKEN }}
SIGNPATH_ORGANIZATION_ID: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
SIGNPATH_PROJECT_SLUG: ${{ vars.SIGNPATH_PROJECT_SLUG }}
SIGNPATH_SIGNING_POLICY_SLUG: ${{ env.SIGNPATH_MODE == 'test' && (vars.SIGNPATH_TEST_SIGNING_POLICY_SLUG || 'test-signing') || vars.SIGNPATH_SIGNING_POLICY_SLUG }}
SIGNPATH_ARTIFACT_CONFIGURATION_SLUG: ${{ vars.SIGNPATH_ARTIFACT_CONFIGURATION_SLUG }}
run: |
foreach ($name in @('SIGNPATH_API_TOKEN', 'SIGNPATH_ORGANIZATION_ID', 'SIGNPATH_PROJECT_SLUG', 'SIGNPATH_SIGNING_POLICY_SLUG', 'SIGNPATH_ARTIFACT_CONFIGURATION_SLUG')) {
if ([string]::IsNullOrWhiteSpace([Environment]::GetEnvironmentVariable($name))) {
throw "启用 Windows 签名后必须配置 $name"
}
}
$files = @(Get-ChildItem dist/desktop/release/WrongNotebook-Win-*.exe -File)
if ($files.Count -ne 2 -or @($files | Where-Object Name -Match '^WrongNotebook-Win-Setup-.+-x64\.exe$').Count -ne 1 -or @($files | Where-Object Name -Match '^WrongNotebook-Win-Portable-.+-x64\.exe$').Count -ne 1) {
throw '必须同时生成一个 Windows 安装版和一个免安装版'
}
$versions = @($files.VersionInfo.ProductVersion | Select-Object -Unique)
if ($versions.Count -ne 1 -or [string]::IsNullOrWhiteSpace($versions[0]) -or @($files | Where-Object { $_.VersionInfo.ProductName -ne 'WrongNotebook' }).Count -ne 0) {
throw 'Windows 安装包必须使用 WrongNotebook 产品名和一致的产品版本'
}
"product-version=$($versions[0])" >> $env:GITHUB_OUTPUT
"signing-policy-slug=$env:SIGNPATH_SIGNING_POLICY_SLUG" >> $env:GITHUB_OUTPUT
# SignPath 验证 GitHub 构建来源;此中间产物不匹配 Release 的 package-* 下载规则。
- name: 上传 Windows 未签名产物供 SignPath 验证
if: env.SIGNPATH_MODE != 'off'
id: unsigned-windows
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: unsigned-windows-x64
path: dist/desktop/release/WrongNotebook-Win-*.exe
if-no-files-found: error
retention-days: 1
- name: 提交 SignPath 请求并等待维护者批准
if: env.SIGNPATH_MODE != 'off'
uses: signpath/github-action-submit-signing-request@f6d04783b4569d051e0c80105fe66e82819d0092 # v3.0
with:
api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
organization-id: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
project-slug: ${{ vars.SIGNPATH_PROJECT_SLUG }}
signing-policy-slug: ${{ steps.windows-signing.outputs.signing-policy-slug }}
artifact-configuration-slug: ${{ vars.SIGNPATH_ARTIFACT_CONFIGURATION_SLUG }}
github-artifact-id: ${{ steps.unsigned-windows.outputs.artifact-id }}
wait-for-completion: true
wait-for-completion-timeout-in-seconds: 1800
output-artifact-directory: ${{ runner.temp }}/signed-windows
parameters: |
version: ${{ toJSON(steps.windows-signing.outputs.product-version) }}
- name: 验证 Windows 签名并替换发布文件
if: env.SIGNPATH_MODE == 'production'
shell: pwsh
run: ./scripts/package/verify-windows-signatures.ps1 -UnsignedDirectory dist/desktop/release -SignedDirectory '${{ runner.temp }}/signed-windows'
- name: 验证测试证书签名(不替换发布文件)
if: env.SIGNPATH_MODE == 'test'
shell: pwsh
run: ./scripts/package/verify-windows-signatures.ps1 -UnsignedDirectory dist/desktop/release -SignedDirectory '${{ runner.temp }}/signed-windows' -TestCertificate
# 测试证书签名的文件仅供下载核对,名称不匹配 Release 的 package-* 规则。
- name: 上传测试证书签名的 Windows 产物
if: env.SIGNPATH_MODE == 'test'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: test-signed-windows-x64
path: ${{ runner.temp }}/signed-windows
if-no-files-found: error
retention-days: 7
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: package-desktop-${{ matrix.name }}
path: |
dist/desktop/release/WrongNotebook-*.exe
dist/desktop/release/WrongNotebook-*.dmg
dist/desktop/release/WrongNotebook-*.zip
dist/desktop/release/WrongNotebook-*.AppImage
dist/desktop/release/WrongNotebook-*.deb
if-no-files-found: error
fnos:
name: fnOS (${{ matrix.arch }})
if: github.server_url == 'https://github.com'
strategy:
fail-fast: false
matrix:
include:
- arch: x86
os: ubuntu-24.04
fnpack: fnpack-1.2.1-linux-amd64
sha256: 72d2a4095da676b64510b023731a227b369d80f8079bc45ff8a2f802ec0480c1
- arch: arm
os: ubuntu-24.04-arm
fnpack: fnpack-1.2.1-linux-arm64
sha256: aad9e16b101267d30017f39ab969e3c085fbce209716f8bd3b1e167eaf15e0cf
runs-on: ${{ matrix.os }}
timeout-minutes: 60
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '24'
cache: 'npm'
- name: Resolve version
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "PACKAGE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
fi
- name: Install fnpack
run: |
curl -fsSL -o /usr/local/bin/fnpack "https://static2.fnnas.com/fnpack/${{ matrix.fnpack }}"
echo "${{ matrix.sha256 }} /usr/local/bin/fnpack" | sha256sum -c -
chmod +x /usr/local/bin/fnpack
- name: Cache Next.js build
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ github.workspace }}/.next/cache
key: nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
restore-keys: |
nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-
nextjs-${{ runner.os }}-${{ runner.arch }}-
- run: npm ci --no-audit --no-fund
- name: Build fpk
run: |
node scripts/package/build.mjs bundle
node scripts/package/build.mjs fnos --arch ${{ matrix.arch }}
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: package-fnos-${{ matrix.arch }}
path: dist/WrongNotebook-FnOS-*.fpk
if-no-files-found: error
synology:
name: Synology SPK (${{ matrix.arch }})
if: github.server_url == 'https://github.com'
runs-on: ubuntu-24.04
# 发版时要等 CI 工作流推送镜像
timeout-minutes: 100
strategy:
fail-fast: false
matrix:
include:
- arch: x86_64
docker_arch: amd64
- arch: arm64
docker_arch: arm64
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '24'
cache: 'npm'
- name: Resolve version
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "PACKAGE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
fi
- run: npm ci --no-audit --no-fund
# 镜像由 CI 工作流在同一标签上构建,测试通过后才推送;等它出现后导出为 docker save 格式,
# 与用户从 ghcr.io 拉到的是同一份镜像
- name: Export Docker image
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: |
image="ghcr.io/margrop/wrong-notebook:${PACKAGE_VERSION}"
platform=(--override-os linux --override-arch "${{ matrix.docker_arch }}")
for attempt in $(seq 1 150); do
if skopeo inspect "${platform[@]}" "docker://${image}" > /dev/null 2>&1; then
break
fi
if [ "$attempt" = 150 ]; then
echo "等待镜像 ${image} 超时" >&2
exit 1
fi
sleep 30
done
skopeo copy "${platform[@]}" "docker://${image}" "docker-archive:${RUNNER_TEMP}/image.tar:${image}"
gzip "${RUNNER_TEMP}/image.tar"
echo "IMAGE_ARGS=--arch ${{ matrix.arch }} --image ${RUNNER_TEMP}/image.tar.gz" >> "$GITHUB_ENV"
- name: Build SPK
run: node scripts/package/build.mjs synology $IMAGE_ARGS
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: package-synology-${{ matrix.arch }}
path: dist/WrongNotebook-Synology-*.spk
if-no-files-found: error
qnap:
name: QNAP QPKG (${{ matrix.arch }})
if: github.server_url == 'https://github.com'
runs-on: ubuntu-24.04
# 发版时要等 CI 工作流推送镜像
timeout-minutes: 100
strategy:
fail-fast: false
matrix:
include:
- arch: x86_64
docker_arch: amd64
- arch: arm64
docker_arch: arm64
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '24'
cache: 'npm'
- name: Resolve version
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "PACKAGE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
fi
- name: Install QDK
shell: bash
run: |
curl -fsSL -o /tmp/qdk.deb "https://github.com/qnap-dev/QDK/releases/download/v2.5.3/qdk_2.5.3_amd64.deb"
echo "17b3841b7d4590a4ee025844ba583304b5e3c497d9fa8934d5175131d3908022 /tmp/qdk.deb" | sha256sum -c -
sudo apt-get install -y /tmp/qdk.deb
export PATH="$PATH:/usr/share/QDK/bin"
qbuild --version || true
- run: npm ci --no-audit --no-fund
# 镜像由 CI 工作流在同一标签上构建,测试通过后才推送;等它出现后导出为 docker save 格式,
# 与用户从 ghcr.io 拉到的是同一份镜像
- name: Export Docker image
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: |
image="ghcr.io/margrop/wrong-notebook:${PACKAGE_VERSION}"
platform=(--override-os linux --override-arch "${{ matrix.docker_arch }}")
for attempt in $(seq 1 150); do
if skopeo inspect "${platform[@]}" "docker://${image}" > /dev/null 2>&1; then
break
fi
if [ "$attempt" = 150 ]; then
echo "等待镜像 ${image} 超时" >&2
exit 1
fi
sleep 30
done
skopeo copy "${platform[@]}" "docker://${image}" "docker-archive:${RUNNER_TEMP}/image.tar:${image}"
gzip "${RUNNER_TEMP}/image.tar"
echo "IMAGE_ARGS=--arch ${{ matrix.arch }} --image ${RUNNER_TEMP}/image.tar.gz" >> "$GITHUB_ENV"
- name: Build QPKG
run: |
export PATH="$PATH:/usr/share/QDK/bin"
node scripts/package/build.mjs qnap $IMAGE_ARGS
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: package-qnap-${{ matrix.arch }}
path: dist/WrongNotebook-QNAP-*.qpkg
if-no-files-found: error
android:
name: Android
if: github.server_url == 'https://github.com'
runs-on: ubuntu-24.04
# 未命中缓存时需要交叉编译 Prisma 引擎
timeout-minutes: 90
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '24'
cache: 'npm'
# Runner 镜像自带 Android SDK(ANDROID_HOME),缺少的平台和构建工具由 Android Gradle 插件自动下载
- uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
with:
distribution: 'temurin'
java-version: '17'
- uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2
with:
gradle-version: '8.11.1'
- name: Resolve version
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "PACKAGE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
fi
- name: Cache Next.js build
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ github.workspace }}/.next/cache
key: nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
restore-keys: |
nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-
nextjs-${{ runner.os }}-${{ runner.arch }}-
- run: npm ci --no-audit --no-fund
# 单机版内置的服务端与其他安装包相同
- name: Build bundle
run: node scripts/package/build.mjs bundle
# Prisma 不提供安卓引擎,按引擎提交交叉编译并缓存(Runner 自带 rustup 和 Android NDK)
- name: Resolve Prisma engines version
shell: bash
run: |
echo "PRISMA_ENGINES_COMMIT=$(node -p "require('./node_modules/@prisma/engines-version/package.json').prisma.enginesVersion")" >> "$GITHUB_ENV"
echo "ANDROID_PRISMA_ENGINES_DIR=$RUNNER_TEMP/android-prisma-engines" >> "$GITHUB_ENV"
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
id: engines-cache
with:
path: ${{ runner.temp }}/android-prisma-engines
key: android-prisma-engines-${{ env.PRISMA_ENGINES_COMMIT }}-${{ hashFiles('scripts/package/build-android-prisma-engines.sh') }}
- name: Build Prisma engines for Android
if: steps.engines-cache.outputs.cache-hit != 'true'
run: bash scripts/package/build-android-prisma-engines.sh "$ANDROID_PRISMA_ENGINES_DIR"
# 组装单机版运行时时用 patchelf 改写 Node.js 依赖库的名称
- name: Install patchelf
run: sudo apt-get update && sudo apt-get install -y patchelf
# 发布版必须使用固定的签名密钥,否则用户无法覆盖安装升级
- name: Prepare signing key
shell: bash
env:
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
run: |
if [ -n "$ANDROID_KEYSTORE_BASE64" ]; then
echo "$ANDROID_KEYSTORE_BASE64" | base64 -d > "$RUNNER_TEMP/release.jks"
echo "ANDROID_KEYSTORE_FILE=$RUNNER_TEMP/release.jks" >> "$GITHUB_ENV"
elif [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "::error::未配置 ANDROID_KEYSTORE_BASE64,发布版 APK 必须使用固定签名,见 doc/INSTALL_PACKAGES.md"
exit 1
else
echo "::warning::未配置签名密钥,APK 使用调试签名,仅供测试"
fi
- name: Build APKs
env:
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
run: node scripts/package/build.mjs android
- name: Verify signatures
shell: bash
run: |
rm -f "$RUNNER_TEMP/release.jks"
# 与 app/build.gradle 的 buildToolsVersion 一致,构建时已由 Android Gradle 插件安装
apksigner="$ANDROID_HOME/build-tools/35.0.0/apksigner"
for apk in dist/WrongNotebook-Android-*.apk; do
echo "== $apk"
certs="$("$apksigner" verify --print-certs "$apk")"
echo "$certs"
if [[ "$GITHUB_REF" == refs/tags/v* ]] && grep -q 'CN=Android Debug' <<< "$certs"; then
echo "::error::$apk 使用了调试签名"
exit 1
fi
done
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: package-android
path: dist/WrongNotebook-Android-*.apk
if-no-files-found: error
release:
name: Upload to Release
needs: [npm, desktop, fnos, synology, qnap, android]
if: github.server_url == 'https://github.com' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: assets
pattern: package-*
merge-multiple: true
- name: Generate checksums
run: |
cd assets
sha256sum * > SHA256SUMS.txt
cat SHA256SUMS.txt
- name: Upload assets
env:
GH_TOKEN: ${{ github.token }}
run: |
# Release 通常已由 release.yml 创建;不存在时先创建
gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1 || \
gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --title "$GITHUB_REF_NAME" --notes ""
gh release upload "$GITHUB_REF_NAME" assets/* --clobber --repo "$GITHUB_REPOSITORY"