From e56fca05fc8b8bfdcd9a244c90d609009c6f6954 Mon Sep 17 00:00:00 2001 From: Bonjour LI <33248848+bonjour-py@users.noreply.github.com> Date: Tue, 14 Apr 2026 09:41:07 +0800 Subject: [PATCH] Refactor and Optimize CI Workflow (#9083) * Refactor and Optimize CI Workflow * Refactor and Optimize CI Workflow (Added input option value annotations for clarity.) --- .github/workflows/build-all.yml | 18 ++-- .github/workflows/build-linux.yml | 105 ++++---------------- .github/workflows/build-osx.yml | 96 ++++++++---------- .github/workflows/build-windows-desktop.yml | 67 +++---------- .github/workflows/build-windows.yml | 63 +++--------- .github/workflows/build.yml | 71 +++++++++++++ .github/workflows/package-zip.yml | 64 ++++++++++++ package-release-zip.sh | 15 --- 8 files changed, 230 insertions(+), 269 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/package-zip.yml delete mode 100644 package-release-zip.sh diff --git a/.github/workflows/build-all.yml b/.github/workflows/build-all.yml index 03b7d834..09e84f1d 100644 --- a/.github/workflows/build-all.yml +++ b/.github/workflows/build-all.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Trigger build windows - if: github.event.inputs.release_tag != '' + if: inputs.release_tag != '' run: | curl -X POST \ -H "Accept: application/vnd.github.v3+json" \ @@ -22,12 +22,12 @@ jobs: -d "{ \"ref\": \"master\", \"inputs\": { - \"release_tag\": \"${{ github.event.inputs.release_tag }}\" + \"release_tag\": \"${{ inputs.release_tag }}\" } }" - name: Trigger build linux - if: github.event.inputs.release_tag != '' + if: inputs.release_tag != '' run: | curl -X POST \ -H "Accept: application/vnd.github.v3+json" \ @@ -36,12 +36,12 @@ jobs: -d "{ \"ref\": \"master\", \"inputs\": { - \"release_tag\": \"${{ github.event.inputs.release_tag }}\" + \"release_tag\": \"${{ inputs.release_tag }}\" } }" - name: Trigger build osx - if: github.event.inputs.release_tag != '' + if: inputs.release_tag != '' run: | curl -X POST \ -H "Accept: application/vnd.github.v3+json" \ @@ -50,12 +50,12 @@ jobs: -d "{ \"ref\": \"master\", \"inputs\": { - \"release_tag\": \"${{ github.event.inputs.release_tag }}\" + \"release_tag\": \"${{ inputs.release_tag }}\" } }" - name: Trigger build windows desktop - if: github.event.inputs.release_tag != '' + if: inputs.release_tag != '' run: | curl -X POST \ -H "Accept: application/vnd.github.v3+json" \ @@ -64,6 +64,6 @@ jobs: -d "{ \"ref\": \"master\", \"inputs\": { - \"release_tag\": \"${{ github.event.inputs.release_tag }}\" + \"release_tag\": \"${{ inputs.release_tag }}\" } - }" \ No newline at end of file + }" diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 4b212697..5d2d6ac2 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -13,73 +13,29 @@ on: permissions: contents: write -env: - OutputArch: "linux-64" - OutputArchArm: "linux-arm64" - OutputPath64: "${{ github.workspace }}/v2rayN/Release/linux-64" - OutputPathArm64: "${{ github.workspace }}/v2rayN/Release/linux-arm64" - jobs: build: - strategy: - matrix: - configuration: [Release] - runs-on: ubuntu-24.04 + uses: ./.github/workflows/build.yml + with: + target: linux - steps: - - name: Checkout - uses: actions/checkout@v6.0.2 - with: - submodules: 'recursive' - fetch-depth: '0' - - - name: Setup .NET - uses: actions/setup-dotnet@v5.2.0 - with: - dotnet-version: '8.0.x' - - - name: Build - run: | - cd v2rayN - dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r linux-x64 -p:SelfContained=true -o "$OutputPath64" - dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r linux-arm64 -p:SelfContained=true -o "$OutputPathArm64" - dotnet publish ./AmazTool/AmazTool.csproj -c Release -r linux-x64 -p:SelfContained=true -p:PublishTrimmed=true -o "$OutputPath64" - dotnet publish ./AmazTool/AmazTool.csproj -c Release -r linux-arm64 -p:SelfContained=true -p:PublishTrimmed=true -o "$OutputPathArm64" - - - name: Upload build artifacts - uses: actions/upload-artifact@v7.0.1 - with: - name: v2rayN-linux - path: | - ${{ github.workspace }}/v2rayN/Release/linux* - - # release zip archive - - name: Package release zip archive - if: github.event.inputs.release_tag != '' - run: | - chmod 755 package-release-zip.sh - ./package-release-zip.sh "$OutputArch" "$OutputPath64" - ./package-release-zip.sh "$OutputArchArm" "$OutputPathArm64" - - - name: Upload zip archive to release - uses: svenstaro/upload-release-action@v2 - if: github.event.inputs.release_tag != '' - with: - file: ${{ github.workspace }}/v2rayN*.zip - tag: ${{ github.event.inputs.release_tag }} - file_glob: true - prerelease: true + release-zip: + if: inputs.release_tag != '' + needs: build + uses: ./.github/workflows/package-zip.yml + with: + target: linux + release_tag: ${{ inputs.release_tag }} deb: - needs: build + name: build and release deb if: | - (github.event_name == 'workflow_dispatch' && github.event.inputs.release_tag != '') || + (github.event_name == 'workflow_dispatch' && inputs.release_tag != '') || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) - runs-on: ubuntu-24.04 - container: - image: debian:13 + runs-on: ubuntu-latest + container: debian:13 env: - RELEASE_TAG: ${{ github.event.inputs.release_tag != '' && github.event.inputs.release_tag || github.ref_name }} + RELEASE_TAG: ${{ case(inputs.release_tag != '', inputs.release_tag, github.ref_name) }} steps: - name: Prepare tools (Debian) @@ -115,12 +71,6 @@ jobs: echo "==== Dist tree ====" ls -R "$GITHUB_WORKSPACE/dist/deb" || true - - name: Upload DEB artifacts - uses: actions/upload-artifact@v7.0.1 - with: - name: v2rayN-deb - path: dist/deb/**/*.deb - - name: Upload DEBs to release uses: svenstaro/upload-release-action@v2 with: @@ -130,15 +80,14 @@ jobs: prerelease: true rpm: - needs: build + name: build and release rpm if: | - (github.event_name == 'workflow_dispatch' && github.event.inputs.release_tag != '') || + (github.event_name == 'workflow_dispatch' && inputs.release_tag != '') || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) - runs-on: ubuntu-24.04 - container: - image: registry.access.redhat.com/ubi10/ubi + runs-on: ubuntu-latest + container: registry.access.redhat.com/ubi10/ubi env: - RELEASE_TAG: ${{ github.event.inputs.release_tag != '' && github.event.inputs.release_tag || github.ref_name }} + RELEASE_TAG: ${{ case(inputs.release_tag != '', inputs.release_tag, github.ref_name) }} steps: - name: Prepare tools (Red Hat) @@ -207,12 +156,6 @@ jobs: submodules: 'recursive' fetch-depth: '0' - - name: Restore build artifacts - uses: actions/download-artifact@v8 - with: - name: v2rayN-linux - path: ${{ github.workspace }}/v2rayN/Release - - name: Ensure script permissions run: chmod 755 package-rhel.sh @@ -227,13 +170,7 @@ jobs: find "$GITHUB_WORKSPACE/dist/rpm" -name "v2rayN-*-1*.aarch64.rpm" -exec mv {} "$GITHUB_WORKSPACE/dist/rpm/v2rayN-linux-rhel-arm64.rpm" \; || true echo "==== Dist tree ====" ls -R "$GITHUB_WORKSPACE/dist/rpm" || true - - - name: Upload RPM artifacts - uses: actions/upload-artifact@v7.0.1 - with: - name: v2rayN-rpm - path: dist/rpm/**/*.rpm - + - name: Upload RPMs to release uses: svenstaro/upload-release-action@v2 with: diff --git a/.github/workflows/build-osx.yml b/.github/workflows/build-osx.yml index 942b0e99..ab5be89f 100644 --- a/.github/workflows/build-osx.yml +++ b/.github/workflows/build-osx.yml @@ -10,78 +10,62 @@ on: branches: - master -env: - OutputArch: "macos-64" - OutputArchArm: "macos-arm64" - OutputPath64: "${{ github.workspace }}/v2rayN/Release/macos-64" - OutputPathArm64: "${{ github.workspace }}/v2rayN/Release/macos-arm64" +permissions: + contents: write jobs: build: + uses: ./.github/workflows/build.yml + with: + target: macos + + release-zip: + if: inputs.release_tag != '' + needs: build + uses: ./.github/workflows/package-zip.yml + with: + target: macos + release_tag: ${{ inputs.release_tag }} + + dmg: + name: package and release macOS dmg + if: inputs.release_tag != '' + needs: build strategy: matrix: - configuration: [Release] - + arch: [ x64, arm64 ] runs-on: macos-latest - + env: + Arch: |- + ${{ + case( + matrix.arch == 'x64', '64', + matrix.arch + ) + }} steps: - name: Checkout uses: actions/checkout@v6.0.2 - with: - submodules: 'recursive' - fetch-depth: '0' - - name: Setup - uses: actions/setup-dotnet@v5.2.0 + - name: Restore build artifacts + uses: actions/download-artifact@v8 with: - dotnet-version: '8.0.x' - - - name: Build - run: | - cd v2rayN - dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r osx-x64 -p:SelfContained=true -o $OutputPath64 - dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r osx-arm64 -p:SelfContained=true -o $OutputPathArm64 - dotnet publish ./AmazTool/AmazTool.csproj -c Release -r osx-x64 -p:SelfContained=true -p:PublishTrimmed=true -o $OutputPath64 - dotnet publish ./AmazTool/AmazTool.csproj -c Release -r osx-arm64 -p:SelfContained=true -p:PublishTrimmed=true -o $OutputPathArm64 - - - name: Upload build artifacts - uses: actions/upload-artifact@v7.0.1 - with: - name: v2rayN-macos - path: | - ${{ github.workspace }}/v2rayN/Release/macos* + name: ${{ matrix.arch }} + path: v2rayN-macos-${{ env.Arch }} - # release osx package - - name: Package osx - if: github.event.inputs.release_tag != '' - run: | - brew install create-dmg - chmod 755 package-osx.sh - ./package-osx.sh $OutputArch $OutputPath64 ${{ github.event.inputs.release_tag }} - ./package-osx.sh $OutputArchArm $OutputPathArm64 ${{ github.event.inputs.release_tag }} + - name: Setup create-dmg + run: brew install create-dmg + + - name: Ensure script permissions + run: chmod 755 package-osx.sh + + - name: Package dmg + run: ./package-osx.sh macos-$Arch v2rayN-macos-$Arch ${{ inputs.release_tag }} - name: Upload dmg to release uses: svenstaro/upload-release-action@v2 - if: github.event.inputs.release_tag != '' with: file: ${{ github.workspace }}/v2rayN*.dmg - tag: ${{ github.event.inputs.release_tag }} + tag: ${{ inputs.release_tag }} file_glob: true prerelease: true - - # release zip archive - - name: Package release zip archive - if: github.event.inputs.release_tag != '' - run: | - chmod 755 package-release-zip.sh - ./package-release-zip.sh $OutputArch $OutputPath64 - ./package-release-zip.sh $OutputArchArm $OutputPathArm64 - - - name: Upload zip archive to release - uses: svenstaro/upload-release-action@v2 - if: github.event.inputs.release_tag != '' - with: - file: ${{ github.workspace }}/v2rayN*.zip - tag: ${{ github.event.inputs.release_tag }} - file_glob: true - prerelease: true \ No newline at end of file diff --git a/.github/workflows/build-windows-desktop.yml b/.github/workflows/build-windows-desktop.yml index 8c986de3..9a9579a4 100644 --- a/.github/workflows/build-windows-desktop.yml +++ b/.github/workflows/build-windows-desktop.yml @@ -10,62 +10,19 @@ on: branches: - master -env: - OutputArch: "windows-64" - OutputArchArm: "windows-arm64" - OutputPath64: "${{ github.workspace }}/v2rayN/Release/windows-64" - OutputPathArm64: "${{ github.workspace }}/v2rayN/Release/windows-arm64" +permissions: + contents: write jobs: build: - strategy: - matrix: - configuration: [Release] + uses: ./.github/workflows/build.yml + with: + target: windows - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v6.0.2 - with: - submodules: 'recursive' - fetch-depth: '0' - - - name: Setup - uses: actions/setup-dotnet@v5.2.0 - with: - dotnet-version: '8.0.x' - - - name: Build - run: | - cd v2rayN - dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r win-x64 -p:SelfContained=true -p:EnableWindowsTargeting=true -o $OutputPath64 - dotnet publish ./v2rayN.Desktop/v2rayN.Desktop.csproj -c Release -r win-arm64 -p:SelfContained=true -p:EnableWindowsTargeting=true -o $OutputPathArm64 - dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-x64 -p:SelfContained=true -p:EnableWindowsTargeting=true -p:PublishTrimmed=true -o $OutputPath64 - dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-arm64 -p:SelfContained=true -p:EnableWindowsTargeting=true -p:PublishTrimmed=true -o $OutputPathArm64 - - - name: Upload build artifacts - uses: actions/upload-artifact@v7.0.1 - with: - name: v2rayN-windows-desktop - path: | - ${{ github.workspace }}/v2rayN/Release/windows* - - # release zip archive - - name: Package release zip archive - if: github.event.inputs.release_tag != '' - run: | - chmod 755 package-release-zip.sh - ./package-release-zip.sh $OutputArch $OutputPath64 - mv "v2rayN-${OutputArch}.zip" "v2rayN-${OutputArch}-desktop.zip" - ./package-release-zip.sh $OutputArchArm $OutputPathArm64 - mv "v2rayN-${OutputArchArm}.zip" "v2rayN-${OutputArchArm}-desktop.zip" - - - name: Upload zip archive to release - uses: svenstaro/upload-release-action@v2 - if: github.event.inputs.release_tag != '' - with: - file: ${{ github.workspace }}/v2rayN*.zip - tag: ${{ github.event.inputs.release_tag }} - file_glob: true - prerelease: true + release-zip: + if: inputs.release_tag != '' + needs: build + uses: ./.github/workflows/package-zip.yml + with: + target: windows-desktop + release_tag: ${{ inputs.release_tag }} diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index f7b5cd63..4bcba3d6 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -10,57 +10,20 @@ on: branches: - master -env: - OutputArch: "windows-64" - OutputArchArm: "windows-arm64" - OutputPath64: "${{ github.workspace }}/v2rayN/Release/windows-64" - OutputPathArm64: "${{ github.workspace }}/v2rayN/Release/windows-arm64" +permissions: + contents: write jobs: build: - strategy: - matrix: - configuration: [Release] + uses: ./.github/workflows/build.yml + with: + target: windows + project: ./v2rayN/v2rayN.csproj - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v6.0.2 - - - name: Setup - uses: actions/setup-dotnet@v5.2.0 - with: - dotnet-version: '8.0.x' - - - name: Build - run: | - cd v2rayN - dotnet publish ./v2rayN/v2rayN.csproj -c Release -r win-x64 -p:SelfContained=true -p:EnableWindowsTargeting=true -o $OutputPath64 - dotnet publish ./v2rayN/v2rayN.csproj -c Release -r win-arm64 -p:SelfContained=true -p:EnableWindowsTargeting=true -o $OutputPathArm64 - dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-x64 -p:SelfContained=true -p:EnableWindowsTargeting=true -p:PublishTrimmed=true -o $OutputPath64 - dotnet publish ./AmazTool/AmazTool.csproj -c Release -r win-arm64 -p:SelfContained=true -p:EnableWindowsTargeting=true -p:PublishTrimmed=true -o $OutputPathArm64 - - - name: Upload build artifacts - uses: actions/upload-artifact@v7.0.1 - with: - name: v2rayN-windows - path: | - ${{ github.workspace }}/v2rayN/Release/windows* - - # release zip archive - - name: Package release zip archive - if: github.event.inputs.release_tag != '' - run: | - chmod 755 package-release-zip.sh - ./package-release-zip.sh $OutputArch $OutputPath64 - ./package-release-zip.sh $OutputArchArm $OutputPathArm64 - - - name: Upload zip archive to release - uses: svenstaro/upload-release-action@v2 - if: github.event.inputs.release_tag != '' - with: - file: ${{ github.workspace }}/v2rayN*.zip - tag: ${{ github.event.inputs.release_tag }} - file_glob: true - prerelease: true + release-zip: + if: inputs.release_tag != '' + needs: build + uses: ./.github/workflows/package-zip.yml + with: + target: windows + release_tag: ${{ inputs.release_tag }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..838a99ec --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,71 @@ +name: build + +on: + workflow_call: + inputs: + target: # windows linux macos + required: true + type: string + project: + required: false + type: string + default: './v2rayN.Desktop/v2rayN.Desktop.csproj' + +jobs: + build: + name: build x64 arm64 + strategy: + matrix: + arch: [ x64, arm64 ] + runs-on: |- + ${{ + case( + inputs.target == 'macos', 'macos-latest', + inputs.target == 'linux', 'ubuntu-24.04', + 'ubuntu-latest' + ) + }} + env: + Output: "${{ github.workspace }}/${{ matrix.arch }}" + RID: |- + ${{ + case( + inputs.target == 'macos', format('osx-{0}', matrix.arch), + inputs.target == 'windows', format('win-{0}', matrix.arch), + format('{0}-{1}', inputs.target, matrix.arch) + ) + }} + Project: ${{ inputs.project }} + ExtOpt: |- + ${{ + case( + inputs.target == 'windows', '-p:EnableWindowsTargeting=true', + '' + ) + }} + + steps: + - name: Checkout + uses: actions/checkout@v6.0.2 + with: + submodules: 'recursive' + fetch-depth: '0' + + - name: Setup .NET + uses: actions/setup-dotnet@v5.2.0 + with: + dotnet-version: '8.0.x' + + - name: Build v2rayN + working-directory: ./v2rayN + run: dotnet publish $Project -c Release -r $RID -p:SelfContained=true $ExtOpt -o $Output + + - name: Build AmazTool + working-directory: ./v2rayN + run: dotnet publish ./AmazTool/AmazTool.csproj -c Release -r $RID -p:SelfContained=true -p:PublishTrimmed=true $ExtOpt -o $Output + + - name: Upload build artifacts + uses: actions/upload-artifact@v7.0.1 + with: + name: ${{ matrix.arch }} + path: ${{ matrix.arch }} diff --git a/.github/workflows/package-zip.yml b/.github/workflows/package-zip.yml new file mode 100644 index 00000000..de89a5ce --- /dev/null +++ b/.github/workflows/package-zip.yml @@ -0,0 +1,64 @@ +name: package and release Zip + +on: + workflow_call: + inputs: + release_tag: + required: true + type: string + target: # windows linux macos windows-desktop + required: true + type: string + +permissions: + contents: write + +jobs: + package: + name: package x64 arm64 + strategy: + matrix: + arch: [ x64, arm64 ] + runs-on: ubuntu-latest + env: + Target: |- + ${{ + case( + inputs.target == 'windows-desktop', 'windows', + inputs.target + ) + }} + Arch: |- + ${{ + case( + matrix.arch == 'x64', '64', + matrix.arch + ) + }} + steps: + - name: Checkout + uses: actions/checkout@v6.0.2 + + - name: Restore build artifacts + uses: actions/download-artifact@v8 + with: + name: ${{ matrix.arch }} + path: v2rayN-${{ env.Target }}-${{ env.Arch }} + + - name: Get v2rayN-core-bin + run: wget -nv -O v2rayN-$Target-$Arch.zip "https://github.com/2dust/v2rayN-core-bin/raw/refs/heads/master/v2rayN-$Target-$Arch.zip" + + - name: Package zip archive + run: 7z a -tZip v2rayN-$Target-$Arch.zip v2rayN-$Target-$Arch -mx1 + + - name: Rename windows-desktop + if: inputs.target == 'windows-desktop' + run: mv "v2rayN-$Target-$Arch.zip" "v2rayN-$Target-$Arch-desktop.zip" + + - name: Upload zip archive to release + uses: svenstaro/upload-release-action@v2 + with: + file: ${{ github.workspace }}/v2rayN*.zip + tag: ${{ inputs.release_tag }} + file_glob: true + prerelease: true diff --git a/package-release-zip.sh b/package-release-zip.sh deleted file mode 100644 index 60804e69..00000000 --- a/package-release-zip.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -Arch="$1" -OutputPath="$2" - -OutputArch="v2rayN-${Arch}" -FileName="v2rayN-${Arch}.zip" - -wget -nv -O $FileName "https://github.com/2dust/v2rayN-core-bin/raw/refs/heads/master/$FileName" - -ZipPath64="./$OutputArch" -mkdir $ZipPath64 - -cp -rf $OutputPath "$ZipPath64/$OutputArch" -7z a -tZip $FileName "$ZipPath64/$OutputArch" -mx1 \ No newline at end of file