[ci] update Github actions script

This commit is contained in:
dijunkun
2025-10-27 11:03:24 +08:00
parent 4e6f52a578
commit cd87492833
2 changed files with 57 additions and 76 deletions

57
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,57 @@
name: Build CrossDesk Server
on:
push:
branches: ["**"]
tags: ["*"]
workflow_dispatch:
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache xmake packages
uses: actions/cache@v4
with:
path: $HOME/.xmake/packages
key: ${{ runner.os }}-xmake-${{ hashFiles('**/xmake.lua') }}
restore-keys: |
${{ runner.os }}-xmake-
- name: Install xmake & deps
run: |
sudo apt update
sudo apt-get install -y software-properties-common git curl unzip build-essential
sudo add-apt-repository -y ppa:xmake-io/xmake
sudo apt update
sudo apt install -y xmake
xmake --version
- name: Build
run: xmake b -vy crossdesk_server
- name: Prepare dist
run: |
mkdir -p dist
cp build/linux/x86_64/release/crossdesk_server dist/
chmod +x dist/crossdesk_server
- name: Upload build artifact (for non-tag pushes too)
uses: actions/upload-artifact@v4
with:
name: crossdesk_server
path: dist/crossdesk_server
- name: Publish GitHub Release (on tag)
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v2
with:
files: dist/crossdesk_server
generate_release_notes: true

View File

@@ -1,76 +0,0 @@
name: Build and Deploy CrossDesk Server
on:
push:
branches:
- "**"
tags:
- "*"
jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache xmake dependencies
uses: actions/cache@v4
with:
path: /home/runner/.xmake/packages
key: ${{ runner.os }}-xmake-deps-linux-${{ hashFiles('**/xmake.lua') }}
restore-keys: |
${{ runner.os }}-xmake-deps-linux-
- name: Install dependencies
run: |
sudo apt update
sudo apt-get install -y software-properties-common git curl unzip build-essential
sudo add-apt-repository ppa:xmake-io/xmake
sudo apt update && sudo apt install -y xmake
- name: Build
run: xmake b -vy crossdesk_server
- name: Archive build artifact
run: |
tar czf crossdesk-server.tar.gz -C build/linux/x86_64/release crossdesk_server
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: crossdesk-server
path: crossdesk-server.tar.gz
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: crossdesk-server
path: .
- name: Deploy to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_KEY }} #
source: "crossdesk-server.tar.gz"
target: "/home/ubuntu/deploy"
- name: Restart service
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_KEY }}
script: |
cd /home/ubuntu/deploy
tar xzf crossdesk-server.tar.gz
sudo mv crossdesk_server /usr/local/bin/crossdesk_server
sudo systemctl restart crossdesk-server