:octocat: 添加最基本的CI/CD支持 #5033

This commit is contained in:
ssfdust 2022-05-30 11:28:02 +08:00
parent 8dbc19c1fe
commit de566fe61e
5 changed files with 291 additions and 2 deletions

216
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,216 @@
name: CI/CD For SiYuan
on:
schedule:
- cron: '30 4 * * *'
workflow_dispatch:
jobs:
create_release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.version.outputs.value }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Gather Release Information
id: release_info
run: |
echo "::set-output name=release_title::$(git show --format=%s --no-patch | head -1)"
changelog=$(python scripts/parse-changelog.py CHANGE_LOGS.md)
changelog="${changelog//'%'/'%25'}"
changelog="${changelog//$'\n'/'%0A'}"
changelog="${changelog//$'\r'/'%0D'}"
echo "::set-output name=release_body::$changelog"
- name: Extract version from package.json
uses: sergeysova/jq-action@v2
id: version
with:
cmd: 'jq .version app/package.json -r'
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_name: v${{ steps.version.outputs.value }}-${{ steps.release_info.outputs.release_title }}
tag_name: ${{ github.ref }}
body: ${{ steps.release_info.outputs.release_body }}
draft: true
prerelease: true
build:
runs-on: ${{ matrix.config.os }}
needs: create_release
strategy:
matrix:
config:
- os: ubuntu-20.04
kernel_path: "../app/kernel-linux/SiYuan-Kernel"
build_args: "-s -w"
electron_args: "dist-linux"
goos: "linux"
goarch: "amd64"
suffix: "linux.AppImage"
- os: ubuntu-20.04
kernel_path: "../app/kernel-linux/SiYuan-Kernel"
build_args: "-s -w"
electron_args: "dist-linux"
goos: "linux"
goarch: "amd64"
suffix: "linux.tar.gz"
- os: macos-latest
kernel_path: "../app/kernel-darwin/SiYuan-Kernel"
build_args: "-s -w"
electron_args: "dist-darwin"
goos: "darwin"
goarch: "amd64"
suffix: "mac.dmg"
- os: macos-latest
kernel_path: "../app/kernel-darwin-arm64/SiYuan-Kernel"
build_args: "-s -w"
electron_args: "dist-darwin-arm64"
goos: "darwin"
goarch: "arm64"
suffix: "mac-arm64.dmg"
- os: windows-2019
kernel_path: "../app/kernel/SiYuan-Kernel.exe"
build_args: "-s -w -H=windowsgui"
electron_args: "dist"
goos: "windows"
gobin: "bin"
mingwsys: "MINGW64"
goarch: "amd64"
suffix: "win.exe"
- os: windows-2019
kernel_path: "../app/kernel32/SiYuan-Kernel.exe"
build_args: "-s -w -H=windowsgui"
electron_args: "dist-win32"
goos: "windows"
mingwsys: "MINGW32"
goarch: "386"
gobin: "bin\\windows_386"
suffix: "win32.exe"
steps:
- uses: actions/checkout@v3
with:
path: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan
- 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 TDM-GCC
run: msys2 -c "bash go/src/github.com/siyuan-note/siyuan/scripts/get-tdm-gcc.sh tdm https://github.com/jmeubank/tdm-gcc/releases/download/v10.3.0-tdm-1/tdm-gcc-10.3.0.exe" && echo "CC=${{ github.workspace }}/tdm/bin/gcc.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
if: "contains( matrix.config.goarch, '386')"
working-directory: ${{ github.workspace }}
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
- 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/siyuan-note/siyuan/kernel
env:
GO111MODULE: on
GOPROXY: https://goproxy.io
CGO_ENABLED: 1
GOOS: ${{ matrix.config.goos }}
GOPATH: ${{ github.workspace }}/go
GOARCH: ${{ matrix.config.goarch }}
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install Node Dependencies
run: npm install
working-directory: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan/app
- name: Building UI
run: npm run build
working-directory: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan/app
- name: Remove Build Directory
uses: JesseTG/rm@v1.0.2
with:
path: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan/app/build
- name: Remove Kernel Directory for Linux
uses: JesseTG/rm@v1.0.2
with:
path: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan/app/kernel-linux
- name: Remove Kernel Directory for Windows 32bit
uses: JesseTG/rm@v1.0.2
with:
path: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan/app/kernel32
- name: Remove Kernel Directory for Windows
uses: JesseTG/rm@v1.0.2
with:
path: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan/app/kernel
- name: Remove Kernel Directory for Mac
uses: JesseTG/rm@v1.0.2
with:
path: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan/app/kernel-darwin
- name: Remove Kernel Directory for Mac M1
uses: JesseTG/rm@v1.0.2
with:
path: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan/app/kernel-darwin-arm64
- 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/siyuan-note/siyuan/kernel
- name: Building Kernel
run: go build --tags fts5 -o "${{ matrix.config.kernel_path }}" -v -ldflags "${{ matrix.config.build_args }}"
working-directory: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan/kernel
env:
GO111MODULE: on
GOPROXY: https://goproxy.io
CGO_ENABLED: 1
GOOS: ${{ matrix.config.goos }}
GOPATH: ${{ github.workspace }}/go
GOARCH: ${{ matrix.config.goarch }}
- name: Building Electron
run: npm run ${{ matrix.config.electron_args }}
working-directory: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan/app
# - name: Build Appx
# run: npm install -g electron-windows-store && electron-windows-store --input-directory app\build\win-unpacked --output-directory app\build\ --package-version 1.0.0.0 --package-name SiYuan --manifest app\appx\AppxManifest.xml --assets app\appx\assets\ --make-pri true
# if: "contains( matrix.config.goos, 'windows')"
# working-directory: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan
- name: Upload Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_name: siyuan-${{ needs.create_release.outputs.version }}-${{ matrix.config.suffix }}
asset_path: ${{ github.workspace }}/go/src/github.com/siyuan-note/siyuan/app/build/siyuan-${{ needs.create_release.outputs.version }}-${{ matrix.config.suffix }}
asset_content_type: application/octet-stream

View file

@ -19,7 +19,7 @@ win:
- from: "kernel32"
to: "kernel"
requestedExecutionLevel: "asInvoker"
certificateSubjectName: "Yunnan Liandi Technology Co., Ltd."
# certificateSubjectName: "Yunnan Liandi Technology Co., Ltd."
signingHashAlgorithms: [ 'sha256' ]
#rfc3161TimeStampServer: "http://sha256timestamp.ws.symantec.com/sha256/timestamp"
#rfc3161TimeStampServer: "http://time.certum.pl"

View file

@ -19,7 +19,7 @@ win:
- from: "kernel"
to: "kernel"
requestedExecutionLevel: "asInvoker"
certificateSubjectName: "Yunnan Liandi Technology Co., Ltd."
# certificateSubjectName: "Yunnan Liandi Technology Co., Ltd."
signingHashAlgorithms: [ 'sha256' ]
#rfc3161TimeStampServer: "http://sha256timestamp.ws.symantec.com/sha256/timestamp"
#rfc3161TimeStampServer: "http://time.certum.pl"

41
scripts/get-tdm-gcc.sh Normal file
View file

@ -0,0 +1,41 @@
#!/bin/sh
# This script is to set up tdm-gcc environment for windows ci.
# BE CAREFUL! THIS SCRIPT WILL DESTROY THE ROOT OF TDM-DCC AT FIRST.
# Usage:
# bash /path/to/the/script /path/to/tdm-gcc/sysroot <URL>
BASEDIR=$(rm -rf $1 && mkdir $1 && cd $1 && pwd)
TDM_URL=$2
function DecompressTDM () {
echo "Downloading From ${TDM_URL}..."
wget ${TDM_URL} -O "${BASEDIR}/tdm.exe" > /dev/null
echo "Decompress the archive..."
7z e -y "${BASEDIR}/tdm.exe" -o"${BASEDIR}" > /dev/null
for tarbar in "${BASEDIR}/"*.tar.xz
do
# We can't use tar -Jxvf here, it will cause pipeline hanging.
xz -d "${tarbar}" -c > "${tarbar%.xz}"
tar -xf "${tarbar%.xz}" -C ${BASEDIR}
done
}
function CreateFeaturesHeader() {
echo "Creating features.h..."
cat > "${BASEDIR}/include/features.h" <<EOF
#ifndef __MINGW_FEATURES__
#pragma GCC system_header
#define __MINGW_FEATURES__ (__MINGW_FEATURES_BEGIN__) \\
__MINGW_FEATURE_IGNORE__ (__MINGW_ANSI_STDIO__) \\
__MINGW_FEATURE_IGNORE__ (__MINGW_LC_MESSAGES__) \\
__MINGW_FEATURE_IGNORE__ (__MINGW_LC_ENVVARS__) \\
__MINGW_FEATURES_END__
#endif
EOF
}
DecompressTDM
CreateFeaturesHeader

View file

@ -0,0 +1,32 @@
#!/usr/bin/env python3
from pathlib import Path
from argparse import ArgumentParser
def parse_latest_changelog(text: str) -> str:
"""Read the contents between the first `##` and the second `##`"""
recording = False
contents: list[str] = []
for line in text.splitlines():
if line.strip().startswith("## ") and recording is False:
recording = True
elif line.strip().startswith("## ") and recording is True:
break
if recording:
contents.append(line)
return "\n".join(contents[1:])
def get_changelog() -> str:
parser = ArgumentParser(description="Get the latest change log from CHANG_LOGS.md")
parser.add_argument("changelog_file", help="The path of CHANGE_LOGS.md")
args = parser.parse_args()
with Path(args.changelog_file).open() as f:
return f.read()
if __name__ == '__main__':
changelog = get_changelog()
latest_changelog = parse_latest_changelog(changelog)
print(latest_changelog)