From ded9e7d5b19857005a83092960c8cb56b2b63f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=98=E5=B0=98?= Date: Mon, 30 May 2022 15:29:21 +0800 Subject: [PATCH] =?UTF-8?q?:octocat:=20=E6=B7=BB=E5=8A=A0=E6=9C=80?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E7=9A=84CI/CD=E6=94=AF=E6=8C=81=20#5033=20(#?= =?UTF-8?q?5038)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 216 +++++++++++++++++++++++++++++++++ app/electron-builder-win32.yml | 2 +- app/electron-builder.yml | 2 +- scripts/get-tdm-gcc.sh | 41 +++++++ scripts/parse-changelog.py | 32 +++++ 5 files changed, 291 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 scripts/get-tdm-gcc.sh create mode 100644 scripts/parse-changelog.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..454cae843 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/app/electron-builder-win32.yml b/app/electron-builder-win32.yml index 47670e926..4267fe71c 100644 --- a/app/electron-builder-win32.yml +++ b/app/electron-builder-win32.yml @@ -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" diff --git a/app/electron-builder.yml b/app/electron-builder.yml index 178ac931c..11f50dee8 100644 --- a/app/electron-builder.yml +++ b/app/electron-builder.yml @@ -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" diff --git a/scripts/get-tdm-gcc.sh b/scripts/get-tdm-gcc.sh new file mode 100644 index 000000000..21481a9b2 --- /dev/null +++ b/scripts/get-tdm-gcc.sh @@ -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 + +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" < 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)