|
| 1 | +# .github/workflows/release.yml |
| 2 | +# |
| 3 | +# Triggered by a semver tag (e.g. v1.2.3). |
| 4 | +# |
| 5 | +# Jobs: |
| 6 | +# build-windows — compiles WinToastWrapper.dll for win-x64 / win-x86 / win-arm64 |
| 7 | +# using MSBuild on a Windows runner. |
| 8 | +# build-macos — compiles libMacNotifyWrapper.dylib for osx-arm64 and osx-x64 |
| 9 | +# using clang cross-compilation on a macOS runner. |
| 10 | +# pack — downloads all native artifacts, packs the NuGet package with the |
| 11 | +# tag version, creates a GitHub Release, and optionally pushes to |
| 12 | +# NuGet.org (requires the NUGET_API_KEY repository secret). |
| 13 | + |
| 14 | +name: Release |
| 15 | + |
| 16 | +on: |
| 17 | + push: |
| 18 | + tags: |
| 19 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: write # required to create GitHub Releases |
| 23 | + |
| 24 | +# --------------------------------------------------------------------------- |
| 25 | +# Windows native build — three architectures in parallel |
| 26 | +# --------------------------------------------------------------------------- |
| 27 | +jobs: |
| 28 | + build-windows: |
| 29 | + name: Build WinToastWrapper (${{ matrix.rid }}) |
| 30 | + runs-on: windows-latest |
| 31 | + strategy: |
| 32 | + fail-fast: false |
| 33 | + matrix: |
| 34 | + include: |
| 35 | + - { platform: x64, rid: win-x64 } |
| 36 | + - { platform: Win32, rid: win-x86 } |
| 37 | + - { platform: ARM64, rid: win-arm64 } |
| 38 | + |
| 39 | + steps: |
| 40 | + - name: Checkout |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Add MSBuild to PATH |
| 44 | + uses: microsoft/setup-msbuild@v2 |
| 45 | + |
| 46 | + - name: Build WinToastWrapper (${{ matrix.platform }}) |
| 47 | + run: | |
| 48 | + msbuild native\WinToastWrapper\WinToastWrapper.vcxproj ` |
| 49 | + /p:Configuration=Release ` |
| 50 | + /p:Platform=${{ matrix.platform }} ` |
| 51 | + /m ` |
| 52 | + /nologo |
| 53 | +
|
| 54 | + # The vcxproj OutDir already targets runtimes/<rid>/native/ relative to the |
| 55 | + # repo root, so the DLL lands in the right place after a successful build. |
| 56 | + - name: Upload native artifact |
| 57 | + uses: actions/upload-artifact@v4 |
| 58 | + with: |
| 59 | + name: native-${{ matrix.rid }} |
| 60 | + path: runtimes/${{ matrix.rid }}/native/WinToastWrapper.dll |
| 61 | + if-no-files-found: error |
| 62 | + |
| 63 | +# --------------------------------------------------------------------------- |
| 64 | +# macOS native build — both architectures on one runner via clang cross-compile |
| 65 | +# --------------------------------------------------------------------------- |
| 66 | + build-macos: |
| 67 | + name: Build MacNotifyWrapper (osx-arm64 + osx-x64) |
| 68 | + runs-on: macos-latest |
| 69 | + |
| 70 | + steps: |
| 71 | + - name: Checkout |
| 72 | + uses: actions/checkout@v4 |
| 73 | + |
| 74 | + # The Makefile targets arm64-apple-macos11.0 and x86_64-apple-macos10.14 |
| 75 | + # using -arch flags; cross-compilation works on both Intel and Apple Silicon |
| 76 | + # runners because Xcode ships cross-compilers for both targets. |
| 77 | + - name: Build dylibs and install to runtimes/ |
| 78 | + run: make -C native/MacNotifyWrapper install |
| 79 | + |
| 80 | + - name: Upload osx-arm64 artifact |
| 81 | + uses: actions/upload-artifact@v4 |
| 82 | + with: |
| 83 | + name: native-osx-arm64 |
| 84 | + path: runtimes/osx-arm64/native/libMacNotifyWrapper.dylib |
| 85 | + if-no-files-found: error |
| 86 | + |
| 87 | + - name: Upload osx-x64 artifact |
| 88 | + uses: actions/upload-artifact@v4 |
| 89 | + with: |
| 90 | + name: native-osx-x64 |
| 91 | + path: runtimes/osx-x64/native/libMacNotifyWrapper.dylib |
| 92 | + if-no-files-found: error |
| 93 | + |
| 94 | +# --------------------------------------------------------------------------- |
| 95 | +# NuGet pack and GitHub Release |
| 96 | +# --------------------------------------------------------------------------- |
| 97 | + pack: |
| 98 | + name: Pack NuGet and publish release |
| 99 | + needs: [build-windows, build-macos] |
| 100 | + runs-on: ubuntu-latest |
| 101 | + |
| 102 | + steps: |
| 103 | + - name: Checkout |
| 104 | + uses: actions/checkout@v4 |
| 105 | + |
| 106 | + # Strip the leading 'v' from the tag (v1.2.3 → 1.2.3) for use as the |
| 107 | + # NuGet package version and .NET assembly version. |
| 108 | + - name: Extract version from tag |
| 109 | + run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV" |
| 110 | + |
| 111 | + # Download every native-* artifact into artifact-staging/<artifact-name>/ |
| 112 | + # Each artifact contains a single file at its root (no subdirectory). |
| 113 | + - name: Download native artifacts |
| 114 | + uses: actions/download-artifact@v4 |
| 115 | + with: |
| 116 | + pattern: native-* |
| 117 | + path: artifact-staging/ |
| 118 | + |
| 119 | + # Reconstruct the runtimes/ tree that the .csproj Content items reference. |
| 120 | + # The Condition="Exists(...)" guards in the .csproj will only bundle a file |
| 121 | + # if it is present here, so all five binaries must be staged before packing. |
| 122 | + - name: Stage native binaries into runtimes/ |
| 123 | + run: | |
| 124 | + mkdir -p \ |
| 125 | + runtimes/win-x64/native \ |
| 126 | + runtimes/win-x86/native \ |
| 127 | + runtimes/win-arm64/native \ |
| 128 | + runtimes/osx-x64/native \ |
| 129 | + runtimes/osx-arm64/native |
| 130 | + cp artifact-staging/native-win-x64/WinToastWrapper.dll runtimes/win-x64/native/ |
| 131 | + cp artifact-staging/native-win-x86/WinToastWrapper.dll runtimes/win-x86/native/ |
| 132 | + cp artifact-staging/native-win-arm64/WinToastWrapper.dll runtimes/win-arm64/native/ |
| 133 | + cp artifact-staging/native-osx-x64/libMacNotifyWrapper.dylib runtimes/osx-x64/native/ |
| 134 | + cp artifact-staging/native-osx-arm64/libMacNotifyWrapper.dylib runtimes/osx-arm64/native/ |
| 135 | +
|
| 136 | + - name: Setup .NET |
| 137 | + uses: actions/setup-dotnet@v4 |
| 138 | + with: |
| 139 | + dotnet-version: '8.x' |
| 140 | + |
| 141 | + # -p:Version overrides the hardcoded version in the .csproj for this build. |
| 142 | + # --no-restore is safe here because we only need the managed code compiled; |
| 143 | + # the native binaries are staged directly without a restore step. |
| 144 | + - name: Pack NuGet package |
| 145 | + run: | |
| 146 | + dotnet pack src/Notify.NET/Notify.NET.csproj \ |
| 147 | + --configuration Release \ |
| 148 | + -p:Version=${{ env.VERSION }} \ |
| 149 | + --output ./nupkg |
| 150 | +
|
| 151 | + - name: Create GitHub Release |
| 152 | + uses: softprops/action-gh-release@v2 |
| 153 | + with: |
| 154 | + files: ./nupkg/*.nupkg |
| 155 | + generate_release_notes: true |
| 156 | + fail_on_unmatched_files: true |
| 157 | + |
| 158 | + # Requires the NUGET_API_KEY repository secret to be configured. |
| 159 | + # Skip this step silently if the secret is absent. |
| 160 | + - name: Push to NuGet.org |
| 161 | + if: ${{ secrets.NUGET_API_KEY != '' }} |
| 162 | + run: | |
| 163 | + dotnet nuget push ./nupkg/*.nupkg \ |
| 164 | + --api-key ${{ secrets.NUGET_API_KEY }} \ |
| 165 | + --source https://api.nuget.org/v3/index.json \ |
| 166 | + --skip-duplicate |
0 commit comments