Merge branch 'feature' of https://github.com/Blessing-Studio/WonderLa… #723
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI-Build | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ "feature" ] | |
env: | |
ACTIONS_ALLOW_UNSECURE_COMMANDS: true | |
dotnet-version: "8.0" | |
target-version: "net8.0" | |
compile-flags: "--self-contained=true -c Release -p:UseAppHost=true -p:IncludeNativeLibrariesForSelfExtract=true -p:EnableCompressionInSingleFile=true -p:DebugType=None -p:DebugSymbols=false -p:PublishSingleFile=true" | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
submodules: recursive | |
- name: "Setup Dotnet" | |
uses: "actions/setup-dotnet@v3" | |
with: | |
dotnet-version: "${{env.dotnet-version}}" | |
- name: Test | |
run: dotnet test WonderLab.Desktop/WonderLab.Desktop.csproj | |
test_build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
submodules: recursive | |
- name: "Setup Dotnet" | |
uses: "actions/setup-dotnet@v3" | |
with: | |
dotnet-version: "${{env.dotnet-version}}" | |
- name: Test | |
run: dotnet build WonderLab.Desktop/WonderLab.Desktop.csproj | |
build_Windows: | |
runs-on: windows-latest | |
needs: [test, test_build] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: "${{env.dotnet-version}}" | |
- name: Update code | |
shell: cmd | |
working-directory: ./ | |
run: ./.build/update_code.bat | |
- name: Build | |
shell: powershell | |
working-directory: ./ | |
run: | | |
./.build/build_windows.ps1 | |
- name: Upload x64 build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: Windows_x64 | |
path: 'WonderLab.Desktop/bin/Release/${{ env.target-version }}/publish/win-x64/*.zip' | |
- name: Upload arm64 build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: Windows_arm64 | |
path: 'WonderLab.Desktop/bin/Release/${{ env.target-version }}/publish/win-arm64/*.zip' | |
build_Linux: | |
strategy: | |
matrix: | |
arch: ["x64", "arm", "arm64"] | |
runs-on: ubuntu-latest | |
needs: [test, test_build] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
submodules: recursive | |
- name: "Setup Dotnet" | |
uses: "actions/setup-dotnet@v3" | |
with: | |
dotnet-version: "${{env.dotnet-version}}" | |
- name: Install pupnet | |
run: dotnet tool install -g KuiperZone.PupNet | |
- name: Install Linrary | |
run: | | |
sudo add-apt-repository universe | |
sudo apt install libfuse2 | |
- name: Get version | |
id: package_version | |
uses: Blessing-Studio/get-csproj-version@main | |
with: | |
file: WonderLab/WonderLab.csproj | |
- name: Build | |
run: pupnet --runtime linux-${{ matrix.arch }} --kind appimage -y -o WonderLab.${{ steps.package_version.outputs.version }}.linux-${{ matrix.arch }}.AppImage | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: AppImage | |
path: Deploy/OUT/*.AppImage | |
build_MacOS: | |
runs-on: macos-latest | |
needs: [test, test_build] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: "${{env.dotnet-version}}" | |
- name: Update code | |
shell: bash | |
working-directory: ./ | |
run: | | |
chmod a+x ./.build/update_code.sh | |
./.build/update_code.sh | |
- name: Build | |
shell: bash | |
working-directory: ./ | |
run: | | |
chmod a+x ./.build/build_osx.sh | |
./.build/build_osx.sh | |
- name: Upload x64 build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: OSX_x64 | |
path: 'WonderLab.Desktop/bin/Release/${{ env.target-version }}/publish/osx-x64/*.zip' | |
- name: Upload arm64 build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: OSX_arm64 | |
path: 'WonderLab.Desktop/bin/Release/${{ env.target-version }}/publish/osx-arm64/*.zip' | |
Release: | |
permissions: write-all | |
runs-on: ubuntu-latest | |
needs: [build_Windows, build_MacOS, build_Linux] | |
steps: | |
- uses: nelonoel/branch-name@v1 | |
id: branch_name | |
- name: Download all artifacts | |
uses: actions/download-artifact@v3 | |
- name: Get current time | |
id: time | |
run: echo "::set-output name=current_timestamp::$(date +%s)" | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
if: github.event_name!= 'pull_request' | |
with: | |
token: "${{ secrets.GITHUB_TOKEN }}" | |
prerelease: false | |
tag_name: WonderLab DEV版本 自动编译 ${{ steps.branch_name.outputs.branch }}_${{ steps.package_version.outputs.version }} | |
name: "${{ steps.branch_name.outputs.branch }} - ${{ steps.package_version.outputs.version }} - testing channel" | |
files: | | |
**/*.zip | |
**/*.AppImage | |
- name: Install gh CLI | |
run: | | |
type -p gh || (curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null && sudo apt update && sudo apt install gh -y) | |
- name: Delete old artifacts | |
run: | | |
# 以下是一个简单的 shell 脚本,用于删除除最新的两个以外的旧工件 | |
# 首先列出所有工件并按修改时间排序 | |
artifacts=$(gh api repos/${{ github.repository }}/actions/artifacts --jq '.artifacts | sort_by(.updated_at) |.[] |.name') | |
# 计算要删除的工件数量 | |
count=$(echo "$artifacts" | wc -l) | |
to_delete=$((count - 2)) | |
# 删除旧工件 | |
if [ $to_delete -gt 0 ]; then | |
echo "$artifacts" | head -n $to_delete | while read -r artifact; do | |
gh api repos/${{ github.repository }}/actions/artifacts/$(gh api repos/${{ github.repository }}/actions/artifacts --jq ".artifacts[] | select(.name == \"$artifact\") |.id") -X DELETE | |
done | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |