name: CD For SiYuan on: push: tags: - '*-dev*' workflow_dispatch: # ref https://docs.github.com/zh/actions/learn-github-actions/variables env: package_json: "app/package.json" jobs: create_release: name: Create Release runs-on: ubuntu-latest outputs: release_version: ${{ steps.release_info.outputs.release_version }} version: ${{ steps.version.outputs.value }} packageManager: ${{ steps.packageManager.outputs.value }} steps: - name: Checkout code uses: actions/checkout@v6 - name: Setup Python uses: actions/setup-python@v6 with: python-version: "3.11" - run: pip install PyGithub - id: thisLatestRelease run: | LATEST=$(gh api "repos/${{ github.repository }}/releases/latest" --jq '.tag_name' 2>/dev/null || echo "") echo "release=$LATEST" >> $GITHUB_OUTPUT env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Extract version from package.json id: version run: | echo "value=$(jq .version ${{ env.package_json }} -r)" >> $GITHUB_OUTPUT - name: Extract electronVersion from package.json id: electronVersion run: | echo "value=$(jq .devDependencies.electron ${{ env.package_json }} -r)" >> $GITHUB_OUTPUT - name: Extract packageManager from package.json id: packageManager run: | echo "value=$(jq .packageManager ${{ env.package_json }} -r)" >> $GITHUB_OUTPUT - name: Gather Release Information id: release_info run: | echo "release_title=$(git show --format=%s --no-patch | head -1)" >> $GITHUB_OUTPUT echo "release_version=$(TZ=Asia/Shanghai date +'v%Y%m%d%H%M')" >> $GITHUB_OUTPUT changelog_header=$(python scripts/parse-changelog-HEAD.py -t ${{ github.ref }} -b ${{ steps.thisLatestRelease.outputs.release }} -e ${{ steps.electronVersion.outputs.value }} ${{ github.repository }}) changelog=$(python scripts/parse-changelog.py -t ${{ github.ref }} ${{ github.repository }}) EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) echo "release_body<<$EOF" >> $GITHUB_ENV echo "$changelog_header" >> $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 }} draft: false prerelease: true token: ${{ secrets.GITHUB_TOKEN }} build: runs-on: ${{ matrix.config.os }} name: ${{ matrix.config.name }} needs: create_release strategy: matrix: config: - os: ubuntu-24.04 name: ubuntu build linux kernel_path: "../app/kernel-linux/SiYuan-Kernel" build_args_prefix: "-s -w -X" build_args_suffix: "Mode=prod" electron_args: "dist-linux" goos: "linux" goarch: "amd64" suffix: "linux" - os: macos-latest name: macos build mac.dmg kernel_path: "../app/kernel-darwin/SiYuan-Kernel" build_args_prefix: "-s -w -X" build_args_suffix: "Mode=prod" electron_args: "dist-darwin" goos: "darwin" goarch: "amd64" suffix: "mac.dmg" - os: macos-latest name: macos build mac-arm64.dmg kernel_path: "../app/kernel-darwin-arm64/SiYuan-Kernel" build_args_prefix: "-s -w -X" build_args_suffix: "Mode=prod" electron_args: "dist-darwin-arm64" goos: "darwin" goarch: "arm64" suffix: "mac-arm64.dmg" - os: windows-latest name: windows build win.exe kernel_path: "../app/kernel/SiYuan-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.exe" steps: - uses: actions/checkout@v6 with: path: ${{ github.workspace }}/go/src/github.com/${{ github.repository }} - 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@v6 with: go-version-file: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel/go.mod cache-dependency-path: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel/go.sum - 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 }}/go/src/github.com/${{ github.repository }}/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@v6 with: node-version: 24 - name: Install Node pnpm run: npm install -g ${{ needs.create_release.outputs.packageManager }} working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app - name: Install Node Dependencies run: pnpm install --no-frozen-lockfile working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app - name: Building UI run: pnpm run build working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app - name: Remove Build Directory run: rm -rf "${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build" shell: bash - name: Remove Kernel Directory for Linux run: rm -rf "${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/kernel-linux" shell: bash - name: Remove Kernel Directory for Windows run: rm -rf "${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/kernel" shell: bash - name: Remove Kernel Directory for macOS run: rm -rf "${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/kernel-darwin" shell: bash - name: Remove Kernel Directory for macOS ARM64 run: rm -rf "${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/kernel-darwin-arm64" shell: bash - 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')" working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel - name: Building Kernel run: go build -tags fts5 -o "${{ matrix.config.kernel_path }}" -ldflags "${{ matrix.config.build_args_prefix }} github.com/${{ github.repository }}/kernel/util.${{ matrix.config.build_args_suffix }}" working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/kernel env: GO111MODULE: on CGO_ENABLED: 1 GOOS: ${{ matrix.config.goos }} GOPATH: ${{ github.workspace }}/go GOARCH: ${{ matrix.config.goarch }} - name: Install RPM build tools if: matrix.config.goos == 'linux' run: sudo apt-get install -y rpm - name: Building Electron App run: pnpm run ${{ matrix.config.electron_args }} working-directory: ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app - name: Upload Release if: matrix.config.goos != 'linux' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} run: | gh release upload ${{ github.ref_name }} "${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build/siyuan-${{ needs.create_release.outputs.version }}-${{ matrix.config.suffix }}#siyuan-${{ needs.create_release.outputs.release_version }}-${{ matrix.config.suffix }}" - name: Upload Linux Release Assets if: matrix.config.goos == 'linux' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} run: | BUILD_DIR="${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app/build" gh release upload ${{ github.ref_name }} \ "$BUILD_DIR/siyuan-${{ needs.create_release.outputs.version }}-linux.AppImage#siyuan-${{ needs.create_release.outputs.release_version }}-linux.AppImage" \ "$BUILD_DIR/siyuan-${{ needs.create_release.outputs.version }}-linux.tar.gz#siyuan-${{ needs.create_release.outputs.release_version }}-linux.tar.gz" \ "$BUILD_DIR/siyuan-${{ needs.create_release.outputs.version }}-linux.deb#siyuan-${{ needs.create_release.outputs.release_version }}-linux.deb" \ "$BUILD_DIR/siyuan-${{ needs.create_release.outputs.version }}-linux.rpm#siyuan-${{ needs.create_release.outputs.release_version }}-linux.rpm"