| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| |
| name: Release Dotnet Binding |
| |
| on: |
| push: |
| tags: |
| - "v[0-9]+.[0-9]+.[0-9]+" |
| - "v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+" |
| pull_request: |
| branches: |
| - main |
| paths: |
| - ".github/workflows/release_dotnet.yml" |
| - "bindings/dotnet/build.py" |
| - "bindings/dotnet/OpenDAL/OpenDAL.csproj" |
| workflow_dispatch: |
| inputs: |
| release_type: |
| description: "Release type" |
| required: true |
| type: choice |
| default: none |
| options: |
| - none |
| - preview |
| - rc |
| |
| concurrency: |
| group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} |
| cancel-in-progress: true |
| |
| permissions: |
| contents: read |
| |
| jobs: |
| build-native: |
| name: Build Native - ${{ matrix.classifier }} |
| runs-on: ${{ matrix.os }} |
| defaults: |
| run: |
| working-directory: "bindings/dotnet" |
| strategy: |
| fail-fast: false |
| matrix: |
| include: |
| - os: ubuntu-latest |
| classifier: linux-x86_64 |
| artifact: libopendal_dotnet.so |
| - os: windows-latest |
| classifier: windows-x86_64 |
| artifact: opendal_dotnet.dll |
| - os: macos-latest |
| classifier: osx-aarch_64 |
| artifact: libopendal_dotnet.dylib |
| |
| steps: |
| - uses: actions/checkout@v7 |
| - name: Setup Python |
| uses: actions/setup-python@v6 |
| with: |
| python-version: "3.11" |
| - name: Setup Rust toolchain |
| uses: ./.github/actions/setup |
| with: |
| need-protoc: true |
| need-rocksdb: true |
| github-token: ${{ secrets.GITHUB_TOKEN }} |
| |
| - name: Build native library |
| run: python build.py --classifier ${{ matrix.classifier }} |
| |
| - name: Upload native artifact |
| uses: actions/upload-artifact@v7 |
| with: |
| name: native-${{ matrix.classifier }} |
| path: bindings/dotnet/target/native/${{ matrix.classifier }}/${{ matrix.artifact }} |
| if-no-files-found: error |
| |
| package: |
| name: Pack NuGet package |
| runs-on: ubuntu-latest |
| needs: |
| - build-native |
| defaults: |
| run: |
| working-directory: "bindings/dotnet" |
| |
| steps: |
| - uses: actions/checkout@v7 |
| - name: Setup dotnet toolchain |
| uses: actions/setup-dotnet@v5 |
| with: |
| dotnet-version: "10.0.x" |
| |
| - name: Download native artifacts |
| uses: actions/download-artifact@v8 |
| with: |
| pattern: native-* |
| merge-multiple: true |
| path: bindings/dotnet/target/release-assets |
| |
| - name: Prepare runtime assets |
| shell: bash |
| run: | |
| mkdir -p OpenDAL/runtimes/win-x64/native |
| mkdir -p OpenDAL/runtimes/linux-x64/native |
| mkdir -p OpenDAL/runtimes/osx-arm64/native |
| |
| cp target/release-assets/opendal_dotnet.dll OpenDAL/runtimes/win-x64/native/ |
| cp target/release-assets/libopendal_dotnet.so OpenDAL/runtimes/linux-x64/native/ |
| cp target/release-assets/libopendal_dotnet.dylib OpenDAL/runtimes/osx-arm64/native/ |
| |
| - name: Determine version suffix |
| id: version |
| shell: bash |
| run: | |
| set -euo pipefail |
| |
| suffix="" |
| if [[ "${GITHUB_EVENT_NAME}" == "push" && "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-rc\.([0-9]+)$ ]]; then |
| suffix="rc.${BASH_REMATCH[1]}" |
| elif [[ "${GITHUB_EVENT_NAME}" == "push" && "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| suffix="" |
| else |
| case "${{ inputs.release_type }}" in |
| rc) |
| suffix="rc" |
| ;; |
| *) |
| suffix="preview.${GITHUB_RUN_NUMBER}" |
| ;; |
| esac |
| fi |
| |
| echo "version_suffix=${suffix}" >> "$GITHUB_OUTPUT" |
| |
| - name: Pack OpenDAL |
| shell: bash |
| run: | |
| set -euo pipefail |
| |
| pack_args=( |
| OpenDAL/OpenDAL.csproj |
| -c Release |
| -o artifacts/package |
| ) |
| if [[ -n "${{ steps.version.outputs.version_suffix }}" ]]; then |
| pack_args+=(--version-suffix "${{ steps.version.outputs.version_suffix }}") |
| fi |
| |
| dotnet pack "${pack_args[@]}" |
| |
| - name: Upload NuGet package |
| uses: actions/upload-artifact@v7 |
| with: |
| name: dotnet-package |
| path: bindings/dotnet/artifacts/package/*.nupkg |
| if-no-files-found: error |
| |
| publish: |
| name: Publish |
| if: ${{ (github.event_name == 'workflow_dispatch' && inputs.release_type != 'none') || (startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-')) }} |
| runs-on: ubuntu-latest |
| needs: |
| - package |
| permissions: |
| contents: read |
| id-token: write |
| |
| steps: |
| - name: Setup dotnet toolchain |
| uses: actions/setup-dotnet@v5 |
| with: |
| dotnet-version: "10.0.x" |
| |
| - name: Download NuGet package |
| uses: actions/download-artifact@v8 |
| with: |
| name: dotnet-package |
| path: bindings/dotnet/artifacts/package |
| |
| - name: NuGet login |
| id: login |
| uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0 |
| with: |
| # The nuget.org account that created the trusted publishing policy, |
| # not the package owner (Apache.OpenDAL organization). |
| user: Fatorin |
| |
| - name: Publish package |
| run: dotnet nuget push bindings/dotnet/artifacts/package/*.nupkg --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json |