更新文档 #747 #246
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sillot CI/CD | |
# https://github.com/actions/runner-images/blob/main/images/ | |
on: | |
push: | |
tags: | |
- "v*-sillot" | |
# ref https://docs.github.com/zh/actions/learn-github-actions/variables | |
env: | |
repo_name_android: "Sillot-android" | |
repo_name: "Sillot" | |
repo_owner: "Hi-Windom" | |
package_json: "package.json" | |
pnpm_ws: "pnpm-workspace.yaml" | |
android_gradle_build_output: "build/outputs/apk/action" | |
android_gradle_build_params: "assembleAction -profile --quiet --stacktrace" | |
# android_gradle_build_params: "assembleOfficialAction -profile --quiet --stacktrace" # 多渠道时 | |
# android_gradle_build_output: "build/outputs/apk/official/action" # 多渠道时 | |
jobs: | |
create_release: | |
name: Create Release | |
runs-on: ubuntu-latest | |
outputs: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
release_version: ${{ steps.release_info.outputs.release_version }} | |
version: ${{ steps.version.outputs.value }} | |
packageManager: ${{ steps.packageManager.outputs.value }} | |
actionInstallCommand: ${{ steps.actionInstallCommand.outputs.value }} | |
steps: | |
- name: ☄️ Checkout repository | |
uses: actions/checkout@v4 | |
- name: 🔨 Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: 🚀 Install PyGithub | |
run: pip install PyGithub | |
- name: 💫 Extract version from package.json | |
uses: sergeysova/jq-action@v2 | |
id: version | |
with: | |
cmd: "jq .version ${{ env.package_json }} -r" | |
- name: 💫 Extract syv from package.json | |
uses: sergeysova/jq-action@v2 | |
id: syv | |
with: | |
cmd: "jq .syv ${{ env.package_json }} -r" | |
- name: 💫 Extract sypv from package.json | |
uses: sergeysova/jq-action@v2 | |
id: sypv | |
with: | |
cmd: "jq .sypv ${{ env.package_json }} -r" | |
- name: 💫 Extract electronVersion from pnpm-workspace.yaml | |
uses: mikefarah/yq@v4 | |
id: electronVersion | |
with: | |
cmd: "yq .catalog.electron ${{ env.pnpm_ws }}" | |
- name: 💫 Extract packageManager from package.json | |
uses: sergeysova/jq-action@v2 | |
id: packageManager | |
with: | |
cmd: "jq .packageManager ${{ env.package_json }} -r" | |
- name: 💫 Extract actionInstallCommand from package.json | |
uses: sergeysova/jq-action@v2 | |
id: actionInstallCommand | |
with: | |
cmd: "jq .actionInstallCommand ${{ env.package_json }} -r" | |
- name: 💫 Set thisLatestRelease | |
id: thisLatestRelease | |
uses: K-Sillot/github-action-get-latest-release@master | |
with: | |
# owner: Hi-Windom | |
# repo: Sillot | |
repository: ${{ github.repository }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
excludes: prerelease, draft | |
- name: 📃 Gather Sillot Release Information | |
id: release_info | |
# https://github.com/Hi-Windom/Sillot/issues/373 | |
# 注意:创建或更新环境变量的步骤无权访问新值;$GITHUB_OUTPUT 需要定义步骤 id 才能稍后检索输出值,$GITHUB_ENV 则不需要 | |
# 以下转换不再需要: | |
# changelog="${changelog//'%'/'%25'}" | |
# changelog="${changelog//$'\n'/'%0A'}" | |
# changelog="${changelog//$'\r'/'%0D'}" | |
run: | | |
echo "release_title=$(git show --format=%s --no-patch | head -1)" >> $GITHUB_OUTPUT | |
echo "release_version=v${{ steps.version.outputs.value }}_$(TZ=Asia/Shanghai date +'%Y%m%d')_syv${{ steps.syv.outputs.value }}" >> $GITHUB_OUTPUT | |
changelog1=$(python scripts/parse-changelog-HEAD.py -t ${{ github.ref }} -b ${{ steps.thisLatestRelease.outputs.release }} -e ${{ steps.electronVersion.outputs.result }} ${{ env.repo_owner }}/${{ env.repo_name }}) | |
changelog2=$(python scripts/parse-changelog-sillot.py -t ${{ github.ref }} ${{ env.repo_owner }}/${{ env.repo_name }}) | |
changelog3=$(python scripts/parse-changelog-sillot.py -t ${{ github.ref }} ${{ env.repo_owner }}/${{ env.repo_name_android }}) | |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | |
echo "release_body_sillot<<$EOF" >> $GITHUB_ENV | |
echo "$changelog1" >> $GITHUB_ENV | |
echo "$changelog2" >> $GITHUB_ENV | |
echo "$changelog3" >> $GITHUB_ENV | |
echo "$EOF" >> $GITHUB_ENV | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: 📃 Gather SiYuan Release Information | |
id: release_info_siyuan | |
run: | | |
changelog=$(python scripts/parse-changelog.py -t v${{ steps.syv.outputs.value }} -a "${{ steps.sypv.outputs.value }}" siyuan-note/siyuan) | |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | |
echo "release_body_siyuan<<$EOF" >> $GITHUB_ENV | |
echo "$changelog" >> $GITHUB_ENV | |
echo "$EOF" >> $GITHUB_ENV | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: 🚩 Create Release | |
id: create_release | |
uses: ncipollo/release-action@v1 | |
with: | |
name: ${{ steps.release_info.outputs.release_version }} | |
tag: ${{ github.ref }} | |
body: "${{ env.release_body_sillot }}\n\n---\n\n${{ env.release_body_siyuan }}\n\n---\n\n\n" | |
generateReleaseNotes: true | |
draft: false | |
prerelease: true | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: 📤 Upload artifact siyuan_desc_mapping.json | |
uses: actions/upload-artifact@v4 | |
with: | |
name: siyuan_desc_mapping.json | |
path: siyuan_desc_mapping.json | |
build: | |
runs-on: ${{ matrix.config.os }} | |
name: ${{ matrix.config.name }} | |
needs: create_release | |
strategy: | |
matrix: | |
# suffix 需要与 electron builder 配置中的 artifactName 匹配 | |
config: | |
- os: ubuntu-20.04 | |
name: ubuntu build linux-x86_64.AppImage | |
kernel_path_upx: "app/kernel-linux/SiYuan-Sillot-Kernel" | |
kernel_path: "../app/kernel-linux/SiYuan-Sillot-Kernel" | |
build_args_prefix: "-s -w -X" | |
build_args_suffix: "Mode=prod" | |
electron_args: "dist-linux" | |
goos: "linux" | |
goarch: "amd64" | |
suffix: "linux-x86_64.AppImage" | |
- os: ubuntu-20.04 | |
name: ubuntu build linux-x64.tar.gz | |
kernel_path_upx: "app/kernel-linux/SiYuan-Sillot-Kernel" | |
kernel_path: "../app/kernel-linux/SiYuan-Sillot-Kernel" | |
build_args_prefix: "-s -w -X" | |
build_args_suffix: "Mode=prod" | |
electron_args: "dist-linux" | |
goos: "linux" | |
goarch: "amd64" | |
suffix: "linux-x64.tar.gz" | |
- os: windows-latest | |
name: windows build win-x64.exe | |
kernel_path_upx: "app/kernel/SiYuan-Sillot-Kernel.exe" | |
kernel_path: "../app/kernel/SiYuan-Sillot-Kernel.exe" | |
build_args_prefix: "-s -w -H=windowsgui -X" | |
build_args_suffix: "Mode=prod" | |
electron_args: "dist" | |
goos: "windows" | |
gobin: "bin" | |
mingwsys: "MINGW64" | |
goarch: "amd64" | |
suffix: "win-x64.exe" | |
- os: windows-latest | |
name: windows build android.apk | |
kernel_path_upx: "app/kernel/SiYuan-Sillot-Kernel.exe" | |
kernel_path: "../app/kernel/SiYuan-Sillot-Kernel.exe" | |
build_args_prefix: "-s -w -H=windowsgui -X" | |
build_args_suffix: "Mode=prod" | |
electron_args: "dist" | |
goos: "windows" | |
gobin: "bin" | |
mingwsys: "MINGW64" | |
goarch: "amd64" | |
suffix: "apk" | |
steps: | |
# - name: ✅ Enable long paths for windows # 如果路径超过了 260 个字符(对于 .pnpm 几乎不可避免),可能会遇到问题。 | |
# # GitHub Actions 的 windows-latest 默认已经支持长路径。 | |
# if: contains( matrix.config.goos, 'windows') | |
# run: | | |
# Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' | |
# Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 | |
- name: ☄️ Checkout repository and submodules | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
path: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }} | |
- name: 🔨 Set up MingGW | |
uses: msys2/setup-msys2@v2 | |
if: contains( matrix.config.goos, 'windows') | |
with: | |
install: p7zip mingw-w64-x86_64-lua | |
- name: 🔨 Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }}/kernel/go.mod | |
- name: ✅ Go version | |
run: go version | |
- name: 🔨 Set up goversioninfo | |
run: go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo && go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo | |
if: contains( matrix.config.goos, 'windows') | |
working-directory: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }}/kernel | |
env: | |
GO111MODULE: on | |
CGO_ENABLED: 1 | |
GOOS: ${{ matrix.config.goos }} | |
GOPATH: ${{ github.workspace }}/go | |
GOARCH: ${{ matrix.config.goarch }} | |
- name: 🔨 Set up Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: 🔨 Install Node pnpm | |
run: npm install -g ${{ needs.create_release.outputs.packageManager }} | |
working-directory: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }} | |
- name: ✍️ Change NPMRC File | |
run: pnpm config set registry https://registry.npmjs.org/ --location project | |
working-directory: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }} | |
- name: 🚀 Install Node Dependencies | |
run: ${{ needs.create_release.outputs.actionInstallCommand }} | |
working-directory: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }} | |
- name: 🔥 Building UI | |
run: pnpm run app:build | |
working-directory: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }} | |
- name: 🗑️ Remove Build Directory | |
uses: K-Sillot/rm@master | |
if: ${{ !contains( matrix.config.suffix, 'apk') }} | |
with: | |
path: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }}/app/build | |
- name: 🗑️ Remove Kernel Directory for Linux | |
uses: K-Sillot/rm@master | |
if: ${{ !contains( matrix.config.suffix, 'apk') }} | |
with: | |
path: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }}/app/kernel-linux | |
- name: 🗑️ Remove Kernel Directory for Windows | |
uses: K-Sillot/rm@master | |
if: ${{ !contains( matrix.config.suffix, 'apk') }} | |
with: | |
path: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }}/app/kernel | |
- name: 💫 Generate Icon Resource and Properties/Version Info For Windows | |
run: ${{ github.workspace }}\go\${{ matrix.config.gobin }}\goversioninfo -platform-specific=true -icon="resource\icon.ico" -manifest="resource\goversioninfo.exe.manifest" | |
if: ${{ contains( matrix.config.goos, 'windows') && !contains( matrix.config.suffix, 'apk') }} | |
working-directory: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }}/kernel | |
- name: 🔥 Building Kernel | |
if: ${{ !contains( matrix.config.suffix, 'apk') }} | |
run: go build --tags fts5 -o "${{ matrix.config.kernel_path }}" -v -ldflags "${{ matrix.config.build_args_prefix }} github.com/${{ env.repo_owner }}/${{ env.repo_name }}/kernel/util.${{ matrix.config.build_args_suffix }}" | |
working-directory: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }}/kernel | |
env: | |
GO111MODULE: on | |
CGO_ENABLED: 1 | |
GOOS: ${{ matrix.config.goos }} | |
GOPATH: ${{ github.workspace }}/go | |
GOARCH: ${{ matrix.config.goarch }} | |
- name: 🔥 Compress Kernel | |
uses: crazy-max/ghaction-upx@v3 | |
if: ${{ !contains( matrix.config.suffix, 'apk') }} | |
with: | |
version: latest | |
files: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }}/${{ matrix.config.kernel_path_upx }} | |
args: -9 | |
- name: 🔥 Building Electron | |
if: ${{ !contains( matrix.config.suffix, 'apk') }} | |
run: pnpm run ${{ matrix.config.electron_args }} | |
working-directory: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }}/app | |
- name: 📤 Upload Release Asset for Windows & Linux | |
if: ${{ !contains( matrix.config.suffix, 'apk') }} | |
uses: shogo82148/actions-upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.create_release.outputs.upload_url }} | |
asset_name: ${{ env.repo_name }}-${{ needs.create_release.outputs.release_version }}-${{ matrix.config.suffix }} | |
asset_path: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }}/app/build/${{ env.repo_name }}-${{ needs.create_release.outputs.version }}-${{ matrix.config.suffix }} | |
- name: 📦 Packing WinPortable zip | |
uses: thedoctor0/[email protected] | |
if: ${{ contains( matrix.config.goos, 'windows') && !contains( matrix.config.suffix, 'apk') }} | |
with: | |
type: 'zip' | |
filename: ${{ env.repo_name }}-${{ needs.create_release.outputs.release_version }}-win_Portable_.zip | |
path: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }}/app/build/win-unpacked/ | |
exclusions: '*.git*' | |
recursive_exclusions: 'LICENSES.chromium.html' | |
- name: 📤 Upload WinPortable to release asset | |
if: ${{ contains(matrix.config.goos, 'windows') && !contains( matrix.config.suffix, 'apk') }} | |
uses: shogo82148/actions-upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.create_release.outputs.upload_url }} | |
asset_name: ${{ env.repo_name }}-${{ needs.create_release.outputs.release_version }}-win_Portable_.zip | |
asset_path: ${{ env.repo_name }}-${{ needs.create_release.outputs.release_version }}-win_Portable_.zip | |
# Manual setup is required when the built-in version does not work correctly in windows2022 | |
- name: 🔨 Setup JDK | |
uses: actions/setup-java@v3 | |
if: contains( matrix.config.suffix, 'apk') | |
continue-on-error: true | |
with: | |
java-version: '17' | |
distribution: 'zulu' | |
overwrite-settings: true | |
- name: 🔨 Setup Android SDK | |
uses: android-actions/[email protected] | |
if: contains( matrix.config.suffix, 'apk') | |
- name: 🔨 Install Android NDK | |
uses: nttld/setup-ndk@v1 | |
if: contains( matrix.config.suffix, 'apk') | |
with: | |
ndk-version: r25b | |
add-to-path: true | |
- name: 🗑️ Remove android Directory | |
uses: K-Sillot/rm@master | |
if: contains( matrix.config.suffix, 'apk') | |
with: | |
path: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name_android }} | |
- name: ☄️ Checkout android repo | |
uses: actions/checkout@v4 | |
if: contains( matrix.config.suffix, 'apk') | |
with: | |
repository: ${{ env.repo_owner }}/${{ env.repo_name_android }} | |
path: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name_android }} | |
- name: 💥 Prepare android build | |
if: contains( matrix.config.suffix, 'apk') | |
run: | | |
cd ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name }} | |
.\scripts\sillot-android-build-action.bat | |
continue-on-error: false | |
# 暂时不需要额外安装最新版 Gradle | |
# - name: 🔨 Setup Gradle | |
# if: contains( matrix.config.suffix, 'apk') | |
# uses: gradle/actions/setup-gradle@v3 | |
# with: | |
# gradle-version: '8.7' | |
- name: 🔥 Build with Gradle | |
if: contains( matrix.config.suffix, 'apk') | |
working-directory: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name_android }} | |
run: ./gradlew ${{ env.android_gradle_build_params }} | |
continue-on-error: false | |
- name: 📤 Upload Gradle profile reports to artifact | |
if: contains( matrix.config.suffix, 'apk') | |
continue-on-error: true | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Gradle_profile_reports | |
path: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name_android }}/build/reports/profile/ | |
- name: 🌠 Sign APK | |
uses: noriban/sign-android-release@v5 | |
if: contains( matrix.config.suffix, 'apk') | |
id: sign_app | |
with: | |
releaseDirectory: ${{ github.workspace }}/${{ env.repo_owner }}/${{ env.repo_name_android }}/app/${{ env.android_gradle_build_output }} | |
signingKeyBase64: ${{ secrets.APK_SIGN_KEY_JKS_BASE64 }} | |
alias: ${{ secrets.APK_SIGN_KEY_ALIAS }} | |
keyStorePassword: ${{ secrets.APK_SIGN_KEY_JKS_PW }} | |
keyPassword: ${{ secrets.APK_SIGN_KEY_PW }} | |
env: | |
# override default build-tools version -- optional | |
BUILD_TOOLS_VERSION: "34.0.0" | |
- name: 📤 Upload APK to release assets | |
if: contains( matrix.config.suffix, 'apk') | |
uses: shogo82148/actions-upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.create_release.outputs.upload_url }} | |
asset_name: ${{ env.repo_name }}-${{ needs.create_release.outputs.release_version }}-android-arm64_v8a.apk | |
asset_path: ${{ steps.sign_app.outputs.signedReleaseFile }} | |
- name: 📤 Upload logs to artifact if failure | |
if: failure() | |
continue-on-error: true | |
uses: actions/upload-artifact@v4 | |
with: | |
name: logs | |
path: ./**/*.log |