|
| 1 | +name: Build and Release DLLs |
| 2 | + |
| 3 | +on: |
| 4 | + # 手动触发或在创建新 tag 时自动发布 |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - '**' |
| 8 | + tags: |
| 9 | + - '**' |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-windows: |
| 14 | + name: Build on ${{ matrix.config.name }} |
| 15 | + runs-on: windows-latest |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + config: |
| 20 | + - name: MSVC x86 |
| 21 | + arch: x86 |
| 22 | + compiler: msvc |
| 23 | + artifact-name: getselected-x86.dll |
| 24 | + - name: MSVC x64 |
| 25 | + arch: x64 |
| 26 | + compiler: msvc |
| 27 | + artifact-name: getselected-x64.dll |
| 28 | + - name: MSYS2 UCRT64 |
| 29 | + arch: ucrt64 |
| 30 | + compiler: msys2 |
| 31 | + artifact-name: getselected-ucrt64.dll |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Checkout code |
| 35 | + uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - name: Setup MSVC (for MSVC builds) |
| 38 | + if: matrix.config.compiler == 'msvc' |
| 39 | + uses: ilammy/msvc-dev-cmd@v1 |
| 40 | + with: |
| 41 | + arch: ${{ matrix.config.arch }} |
| 42 | + |
| 43 | + - name: Setup MSYS2 (for MSYS2 builds) |
| 44 | + if: matrix.config.compiler == 'msys2' |
| 45 | + uses: msys2/setup-msys2@v2 |
| 46 | + with: |
| 47 | + msystem: UCRT64 |
| 48 | + install: git mingw-w64-${{ matrix.config.arch }}-toolchain base-devel binutils |
| 49 | + |
| 50 | + - name: Build with MSVC |
| 51 | + if: matrix.config.compiler == 'msvc' |
| 52 | + run: cd src && .\build.bat |
| 53 | + shell: cmd |
| 54 | + |
| 55 | + - name: Build with MSYS2 |
| 56 | + if: matrix.config.compiler == 'msys2' |
| 57 | + run: | |
| 58 | + cd src |
| 59 | + ming32-make |
| 60 | + shell: msys2 {0} |
| 61 | + |
| 62 | + - name: Locate and rename DLL |
| 63 | + id: find-dll |
| 64 | + run: | |
| 65 | + $dll = Get-ChildItem -Path . -Recurse -Include "*.dll" | Select-Object -First 1 |
| 66 | + if (-not $dll) { |
| 67 | + Write-Error "No DLL found after build!" |
| 68 | + exit 1 |
| 69 | + } |
| 70 | + Copy-Item $dll.FullName -Destination "${{ matrix.config.artifact-name }}" |
| 71 | + echo "dll_path=${{ matrix.config.artifact-name }}" >> $env:GITHUB_OUTPUT |
| 72 | + shell: pwsh |
| 73 | + |
| 74 | + - name: Upload artifact |
| 75 | + uses: actions/upload-artifact@v4 |
| 76 | + with: |
| 77 | + name: ${{ matrix.config.artifact-name }} |
| 78 | + path: ${{ steps.find-dll.outputs.dll_path }} |
| 79 | + |
| 80 | + release: |
| 81 | + name: Create Release |
| 82 | + needs: build-windows |
| 83 | + runs-on: ubuntu-latest |
| 84 | + if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v') |
| 85 | + steps: |
| 86 | + - name: Download all artifacts |
| 87 | + uses: actions/download-artifact@v4 |
| 88 | + with: |
| 89 | + path: release-assets |
| 90 | + |
| 91 | + - name: Flatten directory structure |
| 92 | + run: | |
| 93 | + mkdir -p release |
| 94 | + find release-assets -type f -name "*.dll" -exec mv {} release/ \; |
| 95 | +
|
| 96 | + - name: Create Release |
| 97 | + uses: softprops/action-gh-release@v2 |
| 98 | + with: |
| 99 | + files: release/*.dll |
| 100 | + prerelease: false |
| 101 | + draft: false |
| 102 | + fail_on_unmatched_files: true |
0 commit comments