|
| 1 | +# Copyright AGNTCY Contributors (https://github.com/agntcy) |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +--- |
| 5 | +name: Reusable .NET Bindings Release |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_call: |
| 9 | + inputs: |
| 10 | + library-name: |
| 11 | + description: Name of the library |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + default: slim_bindings |
| 15 | + dotnet-version: |
| 16 | + description: .NET SDK version |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + default: "8.0.x" |
| 20 | + dotnet-bindings-working-directory: |
| 21 | + description: Working directory for .NET bindings |
| 22 | + required: false |
| 23 | + type: string |
| 24 | + default: ./data-plane/bindings/dotnet |
| 25 | + nuget-package-name: |
| 26 | + description: NuGet package name |
| 27 | + required: false |
| 28 | + type: string |
| 29 | + default: Agntcy.Slim |
| 30 | + secrets: |
| 31 | + nuget-api-key: |
| 32 | + description: NuGet API key for publishing |
| 33 | + required: true |
| 34 | + |
| 35 | +env: |
| 36 | + LIBRARY_NAME: ${{ inputs.library-name }} |
| 37 | + NUGET_PACKAGE_NAME: ${{ inputs.nuget-package-name }} |
| 38 | + |
| 39 | +jobs: |
| 40 | + # ========================================================================== |
| 41 | + # Job 1: Publish NuGet package |
| 42 | + # ========================================================================== |
| 43 | + release-dotnet-bindings: |
| 44 | + name: Release .NET Bindings |
| 45 | + runs-on: ubuntu-latest |
| 46 | + defaults: |
| 47 | + run: |
| 48 | + shell: bash |
| 49 | + working-directory: ${{ inputs.dotnet-bindings-working-directory }} |
| 50 | + steps: |
| 51 | + - name: Checkout source repo |
| 52 | + uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - name: Setup .NET |
| 55 | + uses: actions/setup-dotnet@v4 |
| 56 | + with: |
| 57 | + dotnet-version: ${{ inputs.dotnet-version }} |
| 58 | + |
| 59 | + # Download NuGet package artifact |
| 60 | + - name: Download NuGet Package Artifact |
| 61 | + uses: actions/download-artifact@v4 |
| 62 | + with: |
| 63 | + name: dotnet-bindings-nuget |
| 64 | + path: ${{ inputs.dotnet-bindings-working-directory }}/nupkg |
| 65 | + |
| 66 | + - name: List downloaded artifacts |
| 67 | + run: | |
| 68 | + echo "Downloaded NuGet package:" |
| 69 | + ls -lah ./nupkg/ |
| 70 | +
|
| 71 | + - name: Extract version from tag |
| 72 | + id: extract-version |
| 73 | + run: | |
| 74 | + # Extract version from tag name (remove 'slim-bindings-' prefix) |
| 75 | + VERSION="${{ github.ref_name }}" |
| 76 | + VERSION="${VERSION#slim-bindings-}" |
| 77 | + echo "Extracted version: $VERSION" |
| 78 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 79 | +
|
| 80 | + - name: Determine if pre-release |
| 81 | + id: prerelease |
| 82 | + run: | |
| 83 | + VERSION="${{ steps.extract-version.outputs.version }}" |
| 84 | + if [[ "$VERSION" =~ (alpha|beta|rc) ]]; then |
| 85 | + echo "is_prerelease=true" >> $GITHUB_OUTPUT |
| 86 | + echo "This is a pre-release version" |
| 87 | + else |
| 88 | + echo "is_prerelease=false" >> $GITHUB_OUTPUT |
| 89 | + echo "This is a stable release" |
| 90 | + fi |
| 91 | +
|
| 92 | + - name: Publish to NuGet.org |
| 93 | + run: | |
| 94 | + PACKAGE=$(ls ./nupkg/*.nupkg | head -1) |
| 95 | + echo "Publishing package: $PACKAGE" |
| 96 | + |
| 97 | + dotnet nuget push "$PACKAGE" \ |
| 98 | + --api-key "${{ secrets.nuget-api-key }}" \ |
| 99 | + --source https://api.nuget.org/v3/index.json \ |
| 100 | + --skip-duplicate |
| 101 | + |
| 102 | + echo "Successfully published to NuGet.org" |
| 103 | +
|
| 104 | + # ========================================================================== |
| 105 | + # Job 2: Test the published .NET bindings work as expected |
| 106 | + # ========================================================================== |
| 107 | + test-dotnet-bindings: |
| 108 | + name: Test .NET Bindings (${{ matrix.platform.target }}) |
| 109 | + runs-on: ${{ matrix.platform.runner }} |
| 110 | + needs: release-dotnet-bindings |
| 111 | + if: startsWith(github.ref, 'refs/tags/slim-bindings-') |
| 112 | + strategy: |
| 113 | + fail-fast: false |
| 114 | + matrix: |
| 115 | + platform: |
| 116 | + # Linux x86_64 variants |
| 117 | + - runner: ubuntu-24.04 |
| 118 | + os: linux |
| 119 | + target: x86_64-unknown-linux-gnu |
| 120 | + - runner: ubuntu-24.04 |
| 121 | + os: linux |
| 122 | + target: x86_64-unknown-linux-musl |
| 123 | + # Windows variant |
| 124 | + - runner: windows-latest |
| 125 | + os: windows |
| 126 | + target: x86_64-pc-windows-msvc |
| 127 | + # macOS variants |
| 128 | + - runner: macos-15-intel |
| 129 | + os: macos |
| 130 | + target: x86_64-apple-darwin |
| 131 | + - runner: macos-15 |
| 132 | + os: macos |
| 133 | + target: aarch64-apple-darwin |
| 134 | + defaults: |
| 135 | + run: |
| 136 | + shell: bash |
| 137 | + steps: |
| 138 | + - name: Checkout code |
| 139 | + uses: actions/checkout@v4 |
| 140 | + |
| 141 | + - name: Setup .NET |
| 142 | + uses: actions/setup-dotnet@v4 |
| 143 | + with: |
| 144 | + dotnet-version: ${{ inputs.dotnet-version }} |
| 145 | + |
| 146 | + - name: Wait for NuGet package propagation |
| 147 | + run: | |
| 148 | + echo "Waiting 60 seconds for NuGet.org package index to update..." |
| 149 | + sleep 60 |
| 150 | +
|
| 151 | + - name: Test bindings installation and usage |
| 152 | + run: | |
| 153 | + # Extract version from tag name |
| 154 | + VERSION="${{ github.ref_name }}" |
| 155 | + VERSION="${VERSION#slim-bindings-}" |
| 156 | + echo "Testing version: $VERSION" |
| 157 | + echo "Platform: ${{ matrix.platform.target }}" |
| 158 | + echo "Runner: ${{ matrix.platform.runner }}" |
| 159 | +
|
| 160 | + # Create a temporary test directory |
| 161 | + if [ "$RUNNER_OS" = "Windows" ]; then |
| 162 | + TEST_DIR=$(mktemp -d -p "$RUNNER_TEMP") |
| 163 | + else |
| 164 | + TEST_DIR=$(mktemp -d) |
| 165 | + fi |
| 166 | + cd "$TEST_DIR" |
| 167 | + echo "Testing in: $TEST_DIR" |
| 168 | +
|
| 169 | + # Create a test console application |
| 170 | + dotnet new console -n SlimBindingsTest |
| 171 | + cd SlimBindingsTest |
| 172 | +
|
| 173 | + # Install the package from NuGet.org |
| 174 | + echo "Installing package ${{ env.NUGET_PACKAGE_NAME }} version $VERSION" |
| 175 | + dotnet add package ${{ env.NUGET_PACKAGE_NAME }} --version $VERSION |
| 176 | + echo "Package installed successfully" |
| 177 | +
|
| 178 | + # Copy and run test program |
| 179 | + cp $GITHUB_WORKSPACE/.github/tests/dotnet/test_installation.cs ./Program.cs |
| 180 | +
|
| 181 | + # Build and run |
| 182 | + dotnet build |
| 183 | + dotnet run |
| 184 | +
|
| 185 | + echo "" |
| 186 | + echo "All tests passed on ${{ matrix.platform.target }}!" |
| 187 | +
|
| 188 | + - name: Test result summary |
| 189 | + if: success() |
| 190 | + run: | |
| 191 | + echo ".NET bindings verification completed successfully on ${{ matrix.platform.target }}" |
| 192 | + echo "The published package is working correctly." |
| 193 | +
|
| 194 | + # ========================================================================== |
| 195 | + # Job 3: Finalize release - create summary |
| 196 | + # ========================================================================== |
| 197 | + finalize-dotnet-release: |
| 198 | + name: Finalize Release |
| 199 | + runs-on: ubuntu-latest |
| 200 | + needs: test-dotnet-bindings |
| 201 | + if: startsWith(github.ref, 'refs/tags/slim-bindings-') |
| 202 | + steps: |
| 203 | + - name: Extract version |
| 204 | + id: extract-version |
| 205 | + run: | |
| 206 | + VERSION="${{ github.ref_name }}" |
| 207 | + VERSION="${VERSION#slim-bindings-}" |
| 208 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 209 | +
|
| 210 | + - name: Verify package availability |
| 211 | + run: | |
| 212 | + VERSION="${{ steps.extract-version.outputs.version }}" |
| 213 | + echo "Verifying package is discoverable on NuGet.org..." |
| 214 | + |
| 215 | + # Query NuGet API to verify package availability |
| 216 | + RESPONSE=$(curl -s "https://api.nuget.org/v3/registration5-semver1/${{ env.NUGET_PACKAGE_NAME }}/index.json") |
| 217 | + |
| 218 | + if echo "$RESPONSE" | grep -q "$VERSION"; then |
| 219 | + echo "Package version $VERSION is discoverable on NuGet.org" |
| 220 | + else |
| 221 | + echo "Package might still be indexing on NuGet.org" |
| 222 | + fi |
| 223 | +
|
| 224 | + - name: Release complete |
| 225 | + run: | |
| 226 | + VERSION="${{ steps.extract-version.outputs.version }}" |
| 227 | + echo "" |
| 228 | + echo "Release $VERSION complete!" |
| 229 | + echo ".NET bindings published to https://www.nuget.org/packages/${{ env.NUGET_PACKAGE_NAME }}" |
| 230 | + echo "Version: $VERSION" |
| 231 | + echo "All tests passed on 5 platforms" |
| 232 | + echo "" |
| 233 | + echo "Install with:" |
| 234 | + echo " dotnet add package ${{ env.NUGET_PACKAGE_NAME }} --version $VERSION" |
0 commit comments