From 7726ed42459c177fcb273cd4c29108a8c8888dff Mon Sep 17 00:00:00 2001 From: guanzi008 <245205080@qq.com> Date: Sat, 13 May 2023 22:52:50 +0800 Subject: [PATCH] feat: add build-artifacts.yml (#1583) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create main.yml 构建的单文件运行版本几个平台的Windows amd64 ,Linux amd64,Linux arm64 * Rename main.yml to build-artifacts.yml --------- Co-authored-by: boojack --- .github/workflows/build-artifacts.yml | 86 +++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/build-artifacts.yml diff --git a/.github/workflows/build-artifacts.yml b/.github/workflows/build-artifacts.yml new file mode 100644 index 00000000..c6753e62 --- /dev/null +++ b/.github/workflows/build-artifacts.yml @@ -0,0 +1,86 @@ +name: Memos Build + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + goarch: [amd64, arm64] + include: + - os: windows-latest + goos: windows + goarch: amd64 + cgo_env: CC=x86_64-w64-mingw32-gcc + + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + CGO_ENABLED: 1 + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Clone Memos + run: git clone https://github.com/usememos/memos.git + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '18.12.1' + + - name: Build frontend (Windows) + if: matrix.os == 'windows-latest' + shell: pwsh + run: | + cd memos/web + npm install -g pnpm + pnpm i --frozen-lockfile + pnpm build + Remove-Item -Path ../server/dist -Recurse -Force + mv dist ../server/ + + - name: Build frontend (non-Windows) + if: matrix.os != 'windows-latest' + run: | + cd memos/web + npm install -g pnpm + pnpm i --frozen-lockfile + pnpm build + rm -rf ../server/dist + mv dist ../server/ + + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '1.19.3' + + - name: Install mingw-w64 (Windows) + if: matrix.os == 'windows-latest' + run: | + choco install mingw + echo ${{ matrix.cgo_env }} >> $GITHUB_ENV + + - name: Install gcc-aarch64-linux-gnu (Ubuntu ARM64) + if: matrix.os == 'ubuntu-latest' && matrix.goarch == 'arm64' + run: | + sudo apt-get update + sudo apt-get install -y gcc-aarch64-linux-gnu + echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV + + - name: Build backend + run: | + cd memos + go build -o memos-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.os == 'windows-latest' && '.exe' || '' }} ./main.go + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: memos-binary-${{ matrix.os }}-${{ matrix.goarch }} + path: memos/memos-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.os == 'windows-latest' && '.exe' || '' }}