A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
1name: CD For SiYuan
2
3on:
4 push:
5 tags:
6 - '*-dev*'
7 workflow_dispatch:
8
9# ref https://docs.github.com/zh/actions/learn-github-actions/variables
10env:
11 repo_name_android: "siyuan-android"
12 repo_name: "siyuan"
13 repo_owner: "siyuan-note"
14 package_json: "app/package.json"
15
16jobs:
17 create_release:
18 name: Create Release
19 runs-on: ubuntu-latest
20 outputs:
21 upload_url: ${{ steps.create_release.outputs.upload_url }}
22 release_version: ${{ steps.release_info.outputs.release_version }}
23 version: ${{ steps.version.outputs.value }}
24 packageManager: ${{ steps.packageManager.outputs.value }}
25 steps:
26 - name: Checkout code
27 uses: actions/checkout@v4
28
29 - name: Setup Python
30 uses: actions/setup-python@v5
31 with:
32 python-version: "3.11"
33 - run: pip install PyGithub
34
35 - id: thisLatestRelease
36 uses: pozetroninc/github-action-get-latest-release@master
37 with:
38 # owner: siyuan-note
39 # repo: siyuan
40 repository: ${{ github.repository }}
41 token: ${{ secrets.GITHUB_TOKEN }}
42 excludes: prerelease, draft
43
44 - name: Extract version from package.json
45 uses: sergeysova/jq-action@v2
46 id: version
47 with:
48 cmd: 'jq .version ${{ env.package_json }} -r'
49
50 - name: Extract electronVersion from package.json
51 uses: sergeysova/jq-action@v2
52 id: electronVersion
53 with:
54 cmd: "jq .devDependencies.electron ${{ env.package_json }} -r"
55
56 - name: Extract packageManager from package.json
57 uses: sergeysova/jq-action@v2
58 id: packageManager
59 with:
60 cmd: "jq .packageManager ${{ env.package_json }} -r"
61
62 - name: Gather Release Information
63 id: release_info
64 run: |
65 echo "release_title=$(git show --format=%s --no-patch | head -1)" >> $GITHUB_OUTPUT
66 echo "release_version=$(TZ=Asia/Shanghai date +'v%Y%m%d%H%M')" >> $GITHUB_OUTPUT
67 changelog_header=$(python scripts/parse-changelog-HEAD.py -t ${{ github.ref }} -b ${{ steps.thisLatestRelease.outputs.release }} -e ${{ steps.electronVersion.outputs.value }} ${{ env.repo_owner }}/${{ env.repo_name }})
68 changelog=$(python scripts/parse-changelog.py -t ${{ github.ref }} ${{ env.repo_owner }}/${{ env.repo_name }})
69 EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
70 echo "release_body<<$EOF" >> $GITHUB_ENV
71 echo "$changelog_header" >> $GITHUB_ENV
72 echo "$changelog" >> $GITHUB_ENV
73 echo "$EOF" >> $GITHUB_ENV
74 env:
75 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76
77 - name: Create Release
78 id: create_release
79 uses: ncipollo/release-action@v1
80 with:
81 name: ${{ steps.release_info.outputs.release_version }}
82 tag: ${{ github.ref }}
83 body: ${{ env.release_body }}
84 draft: false
85 prerelease: true
86 token: ${{ secrets.GITHUB_TOKEN }}
87
88 build:
89 runs-on: ${{ matrix.config.os }}
90 name: ${{ matrix.config.name }}
91 needs: create_release
92 strategy:
93 matrix:
94 config:
95 - os: ubuntu-22.04
96 name: ubuntu build linux.AppImage
97 kernel_path: "../app/kernel-linux/SiYuan-Kernel"
98 build_args_prefix: "-s -w -X"
99 build_args_suffix: "Mode=prod"
100 electron_args: "dist-linux"
101 goos: "linux"
102 goarch: "amd64"
103 suffix: "linux.AppImage"
104 - os: ubuntu-22.04
105 name: ubuntu build linux.tar.gz
106 kernel_path: "../app/kernel-linux/SiYuan-Kernel"
107 build_args_prefix: "-s -w -X"
108 build_args_suffix: "Mode=prod"
109 electron_args: "dist-linux"
110 goos: "linux"
111 goarch: "amd64"
112 suffix: "linux.tar.gz"
113 - os: macos-latest
114 name: macos build mac.dmg
115 kernel_path: "../app/kernel-darwin/SiYuan-Kernel"
116 build_args_prefix: "-s -w -X"
117 build_args_suffix: "Mode=prod"
118 electron_args: "dist-darwin"
119 goos: "darwin"
120 goarch: "amd64"
121 suffix: "mac.dmg"
122 - os: macos-latest
123 name: macos build mac-arm64.dmg
124 kernel_path: "../app/kernel-darwin-arm64/SiYuan-Kernel"
125 build_args_prefix: "-s -w -X"
126 build_args_suffix: "Mode=prod"
127 electron_args: "dist-darwin-arm64"
128 goos: "darwin"
129 goarch: "arm64"
130 suffix: "mac-arm64.dmg"
131 - os: windows-latest
132 name: windows build win.exe
133 kernel_path: "../app/kernel/SiYuan-Kernel.exe"
134 build_args_prefix: "-s -w -H=windowsgui -X"
135 build_args_suffix: "Mode=prod"
136 electron_args: "dist"
137 goos: "windows"
138 gobin: "bin"
139 mingwsys: "MINGW64"
140 goarch: "amd64"
141 suffix: "win.exe"
142
143 steps:
144 - uses: actions/checkout@v4
145 with:
146 path: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}
147
148 - name: Set up MingGW
149 uses: msys2/setup-msys2@v2
150 if: "contains( matrix.config.goos, 'windows')"
151 with:
152 install: p7zip mingw-w64-x86_64-lua
153
154 - name: Set up Go
155 uses: actions/setup-go@v5
156 with:
157 go-version-file: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/kernel/go.mod
158 - run: go version
159
160 - name: Set up goversioninfo
161 run: go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo && go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo
162 if: "contains( matrix.config.goos, 'windows')"
163 working-directory: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/kernel
164 env:
165 GO111MODULE: on
166 CGO_ENABLED: 1
167 GOOS: ${{ matrix.config.goos }}
168 GOPATH: ${{ github.workspace }}/go
169 GOARCH: ${{ matrix.config.goarch }}
170
171 - name: Set up Node
172 uses: actions/setup-node@v4
173 with:
174 node-version: 20
175
176 - name: Install Node pnpm
177 run: npm install -g ${{ needs.create_release.outputs.packageManager }}
178 working-directory: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/app
179
180 - name: Install Node Dependencies
181 run: pnpm install --no-frozen-lockfile
182 working-directory: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/app
183
184 - name: Building UI
185 run: pnpm run build
186 working-directory: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/app
187
188 - name: Remove Build Directory
189 uses: JesseTG/rm@v1.0.2
190 with:
191 path: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/app/build
192
193 - name: Remove Kernel Directory for Linux
194 uses: JesseTG/rm@v1.0.2
195 with:
196 path: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/app/kernel-linux
197
198 - name: Remove Kernel Directory for Windows
199 uses: JesseTG/rm@v1.0.2
200 with:
201 path: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/app/kernel
202
203 - name: Remove Kernel Directory for macOS
204 uses: JesseTG/rm@v1.0.2
205 with:
206 path: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/app/kernel-darwin
207
208 - name: Remove Kernel Directory for macOS ARM64
209 uses: JesseTG/rm@v1.0.2
210 with:
211 path: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/app/kernel-darwin-arm64
212
213 - name: Generate Icon Resource and Properties/Version Info For Windows
214 run: ${{ github.workspace }}\go\${{ matrix.config.gobin }}\goversioninfo -platform-specific=true -icon="resource\icon.ico" -manifest="resource\goversioninfo.exe.manifest"
215 if: "contains( matrix.config.goos, 'windows')"
216 working-directory: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/kernel
217
218 - name: Building Kernel
219 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 }}"
220 working-directory: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/kernel
221 env:
222 GO111MODULE: on
223 CGO_ENABLED: 1
224 GOOS: ${{ matrix.config.goos }}
225 GOPATH: ${{ github.workspace }}/go
226 GOARCH: ${{ matrix.config.goarch }}
227
228 - name: Building Electron App
229 run: pnpm run ${{ matrix.config.electron_args }}
230 working-directory: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/app
231
232 - name: Upload Release
233 uses: actions/upload-release-asset@v1
234 env:
235 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
236 with:
237 upload_url: ${{ needs.create_release.outputs.upload_url }}
238 asset_name: siyuan-${{ needs.create_release.outputs.release_version }}-${{ matrix.config.suffix }}
239 asset_path: ${{ github.workspace }}/go/src/github.com/${{ env.repo_owner }}/${{ env.repo_name }}/app/build/siyuan-${{ needs.create_release.outputs.version }}-${{ matrix.config.suffix }}
240 asset_content_type: application/octet-stream