|
| 1 | +name: C# CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: "The release version of GLIDE, formatted as *.*.* or *.*.*-rc*" |
| 11 | + required: true |
| 12 | + nuget_publish: |
| 13 | + description: "Publish to NuGet" |
| 14 | + required: true |
| 15 | + type: boolean |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + id-token: write |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: C#-CD-${{ github.head_ref || github.ref }}-${{ toJson(inputs) }} |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +run-name: |
| 26 | + # Set custom name if job is started manually and name is given |
| 27 | + ${{ github.event_name == 'workflow_dispatch' && (inputs.name == '' && format('{0} @ {1} {2}', github.ref_name, github.sha, toJson(inputs)) || inputs.name) || '' }} |
| 28 | + |
| 29 | +env: |
| 30 | + CARGO_TERM_COLOR: always |
| 31 | + |
| 32 | +jobs: |
| 33 | + load-platform-matrix: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + outputs: |
| 36 | + PLATFORM_MATRIX: ${{ steps.load-platform-matrix.outputs.PLATFORM_MATRIX }} |
| 37 | + steps: |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: load-platform-matrix |
| 42 | + id: load-platform-matrix |
| 43 | + working-directory: .github/json_matrices |
| 44 | + run: | |
| 45 | + jq -c "[.[] | select(any(.tags[] == \"cd\"; .))]" < os-matrix.json | awk '{ printf "PLATFORM_MATRIX=%s\n", $0 }' | tee -a $GITHUB_OUTPUT |
| 46 | +
|
| 47 | + set-release-version: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + outputs: |
| 50 | + RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }} |
| 51 | + steps: |
| 52 | + - name: Set the release version |
| 53 | + id: release-version |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + if ${{ github.event_name == 'workflow_dispatch' }}; then |
| 57 | + R_VERSION="${{ env.INPUT_VERSION }}" |
| 58 | + else |
| 59 | + R_VERSION=${{ github.ref_name }} |
| 60 | + fi |
| 61 | + echo "RELEASE_VERSION=${R_VERSION}" >> $GITHUB_ENV |
| 62 | + echo "Release version detected: $R_VERSION" |
| 63 | + echo "RELEASE_VERSION=$R_VERSION" >> $GITHUB_OUTPUT |
| 64 | + env: |
| 65 | + INPUT_VERSION: ${{ github.event.inputs.version }} |
| 66 | + |
| 67 | + create-binaries: |
| 68 | + needs: [load-platform-matrix] |
| 69 | + timeout-minutes: 35 |
| 70 | + strategy: |
| 71 | + # Run all jobs |
| 72 | + fail-fast: false |
| 73 | + matrix: |
| 74 | + host: ${{ fromJson(needs.load-platform-matrix.outputs.PLATFORM_MATRIX) }} |
| 75 | + runs-on: ${{ matrix.host.RUNNER }} |
| 76 | + |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v4 |
| 79 | + with: |
| 80 | + submodules: true |
| 81 | + |
| 82 | + - name: Output Matrix Parameters for this job |
| 83 | + shell: bash |
| 84 | + run: | |
| 85 | + echo "Job running with the following matrix configuration:" |
| 86 | + echo "${{ toJson(matrix) }}" |
| 87 | +
|
| 88 | + - name: Install shared software dependencies |
| 89 | + uses: ./.github/workflows/install-shared-dependencies |
| 90 | + with: |
| 91 | + os: ${{ matrix.host.OS }} |
| 92 | + target: ${{ matrix.host.TARGET }} |
| 93 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + engine-version: ${{ matrix.engine.version }} |
| 95 | + |
| 96 | + - uses: actions/cache@v4 |
| 97 | + with: |
| 98 | + path: rust/target |
| 99 | + key: rust-${{ matrix.host.TARGET }} |
| 100 | + |
| 101 | + - name: Build native libs (linux gnu) |
| 102 | + if: ${{ contains(matrix.host.TARGET, 'linux-gnu') }} |
| 103 | + working-directory: rust |
| 104 | + run: | |
| 105 | + cargo zigbuild -r --target ${{ matrix.host.TARGET }}.2.17 |
| 106 | + mkdir -p target/release |
| 107 | + cp target/*/release/libglide_rs.so target/release/ |
| 108 | +
|
| 109 | + - name: Build native libs |
| 110 | + if: ${{ !contains(matrix.host.TARGET, 'linux-gnu') }} |
| 111 | + working-directory: rust |
| 112 | + run: cargo build --release --target ${{ matrix.host.TARGET }} |
| 113 | + |
| 114 | + - name: Upload artifacts to publish |
| 115 | + continue-on-error: true |
| 116 | + uses: actions/upload-artifact@v4 |
| 117 | + with: |
| 118 | + name: ${{ matrix.host.TARGET }} |
| 119 | + path: | |
| 120 | + rust/target/release/*.so |
| 121 | + rust/target/release/*.dylib |
| 122 | + rust/target/release/*.dll |
| 123 | +
|
| 124 | + build-package-to-publish: |
| 125 | + needs: [set-release-version, create-binaries] |
| 126 | + runs-on: ubuntu-latest |
| 127 | + env: |
| 128 | + RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }} |
| 129 | + steps: |
| 130 | + - uses: actions/checkout@v4 |
| 131 | + |
| 132 | + - name: Download published artifacts |
| 133 | + uses: actions/download-artifact@v4 |
| 134 | + with: |
| 135 | + path: bin |
| 136 | + |
| 137 | + - name: Rename lib for windows |
| 138 | + working-directory: bin |
| 139 | + run: | |
| 140 | + find . -name glide_rs.dll -execdir mv {} libglide_rs.dll \; |
| 141 | + tree -h |
| 142 | +
|
| 143 | + - name: Set up dotnet |
| 144 | + uses: actions/setup-dotnet@v4 |
| 145 | + with: |
| 146 | + # install all supported versions + latest dotnet too to use language features |
| 147 | + dotnet-version: | |
| 148 | + 6 |
| 149 | + 8 |
| 150 | + 9 |
| 151 | + env: |
| 152 | + DOTNET_INSTALL_DIR: ~/.dotnet |
| 153 | + |
| 154 | + - name: Pack the client |
| 155 | + working-directory: sources/Valkey.Glide |
| 156 | + run: | |
| 157 | + dotnet build Valkey.Glide.csproj --configuration Release /property:Version=${{ env.RELEASE_VERSION }} |
| 158 | + dotnet pack Valkey.Glide.csproj --configuration Release -p:NuspecProperties=version=${{ env.RELEASE_VERSION }} |
| 159 | + tree -h bin/Release |
| 160 | + unzip -l bin/Release/Valkey.Glide.${{ env.RELEASE_VERSION }}.nupkg |
| 161 | + unzip -l bin/Release/Valkey.Glide.${{ env.RELEASE_VERSION }}.symbols.nupkg |
| 162 | + env: |
| 163 | + SkipCargo: true |
| 164 | + |
| 165 | + - name: Upload artifacts to publish |
| 166 | + uses: actions/upload-artifact@v4 |
| 167 | + with: |
| 168 | + name: package |
| 169 | + path: sources/Valkey.Glide/bin/Release/Valkey.Glide.*.nupkg |
| 170 | + |
| 171 | + publish: |
| 172 | + environment: Release |
| 173 | + if: ${{ (inputs.nuget_publish == true || github.event_name == 'push') && github.repository_owner == 'valkey-io' }} |
| 174 | + needs: [build-package-to-publish] |
| 175 | + runs-on: ubuntu-latest |
| 176 | + steps: |
| 177 | + - name: Download package |
| 178 | + uses: actions/download-artifact@v4 |
| 179 | + with: |
| 180 | + name: package |
| 181 | + |
| 182 | + - name: Publish |
| 183 | + run: | |
| 184 | + ls -lh |
| 185 | + dotnet nuget push Valkey.Glide.*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json |
| 186 | +
|
| 187 | + test: |
| 188 | + needs: [publish, set-release-version, load-platform-matrix] |
| 189 | + if: ${{ !cancelled() }} |
| 190 | + timeout-minutes: 35 |
| 191 | + strategy: |
| 192 | + # Run all jobs |
| 193 | + fail-fast: false |
| 194 | + matrix: |
| 195 | + host: ${{ fromJson(needs.load-platform-matrix.outputs.PLATFORM_MATRIX) }} |
| 196 | + runs-on: ${{ matrix.host.RUNNER }} |
| 197 | + env: |
| 198 | + RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }} |
| 199 | + steps: |
| 200 | + - uses: actions/checkout@v4 |
| 201 | + |
| 202 | + - name: Download package |
| 203 | + if: ${{ needs.publish.result == 'skipped' }} |
| 204 | + uses: actions/download-artifact@v4 |
| 205 | + with: |
| 206 | + name: package |
| 207 | + path: nuget.local |
| 208 | + |
| 209 | + - name: Set up dotnet |
| 210 | + uses: actions/setup-dotnet@v4 |
| 211 | + with: |
| 212 | + # install latest dotnet too to use language features |
| 213 | + dotnet-version: | |
| 214 | + 8 |
| 215 | + 9 |
| 216 | +
|
| 217 | + - name: Set up a local nuget |
| 218 | + if: ${{ needs.publish.result == 'skipped' }} |
| 219 | + shell: bash |
| 220 | + run: | |
| 221 | + ls -l $GITHUB_WORKSPACE/nuget.local |
| 222 | + dotnet nuget add source $GITHUB_WORKSPACE/nuget.local |
| 223 | + dotnet nuget config paths |
| 224 | + if [[ "$OS" != "Windows_NT" ]]; then |
| 225 | + dotnet nuget config paths | xargs cat |
| 226 | + else |
| 227 | + cat "C:\\Users\\runneradmin\\AppData\\Roaming\\NuGet\\NuGet.Config" |
| 228 | + fi |
| 229 | +
|
| 230 | + - name: Patch IT suite to run tests using freshly published version |
| 231 | + working-directory: tests/Valkey.Glide.IntegrationTests |
| 232 | + shell: bash |
| 233 | + run: | |
| 234 | + dotnet remove reference $(dotnet list reference | tail -n +3) |
| 235 | + dotnet add package Valkey.Glide --version ${{ env.RELEASE_VERSION }} |
| 236 | + git diff |
| 237 | +
|
| 238 | + - name: Install engine |
| 239 | + # TODO activate this on windows once fixed, see https://github.com/valkey-io/valkey-glide-csharp/issues/6 |
| 240 | + if: ${{ matrix.host.OS != 'windows' }} |
| 241 | + uses: ./.github/workflows/install-engine |
| 242 | + with: |
| 243 | + engine-version: 8.1 |
| 244 | + target: ${{ matrix.host.TARGET }} |
| 245 | + |
| 246 | + - name: Run tests |
| 247 | + # TODO activate this on windows once fixed, see https://github.com/valkey-io/valkey-glide-csharp/issues/6 |
| 248 | + if: ${{ matrix.host.OS != 'windows' }} |
| 249 | + working-directory: tests/Valkey.Glide.IntegrationTests |
| 250 | + run: | |
| 251 | + dotnet test --framework net8.0 --logger "console;verbosity=detailed" --logger "html;LogFileName=TestReport.html" --results-directory . --filter "FullyQualifiedName~CommandTests" |
| 252 | +
|
| 253 | + - name: Upload test reports |
| 254 | + if: always() |
| 255 | + continue-on-error: true |
| 256 | + uses: actions/upload-artifact@v4 |
| 257 | + with: |
| 258 | + name: test-reports-${{ matrix.host.TARGET }} |
| 259 | + path: | |
| 260 | + TestReport.html |
| 261 | + valkey-glide/utils/clusters/** |
| 262 | +
|
| 263 | + remove-package-if-validation-fails: |
| 264 | + needs: [publish, test, set-release-version] |
| 265 | + if: ${{ !cancelled() }} |
| 266 | + runs-on: ubuntu-latest |
| 267 | + env: |
| 268 | + RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }} |
| 269 | + steps: |
| 270 | + - name: Remove package from NuGet due to test failures |
| 271 | + if: ${{ needs.test.result == 'failure' && needs.publish.result == 'success' }} |
| 272 | + run: dotnet nuget delete Valkey.Glide ${{ env.RELEASE_VERSION }} --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --non-interactive |
0 commit comments