blob: 8f428b7d11d6d94d43ffffad3f77f6a501bc0343 [file]
# 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:
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@v6
- 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@v6
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@v6
- name: Setup dotnet toolchain
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"
- name: Download native artifacts
uses: actions/download-artifact@v7
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: |
case "${{ inputs.release_type }}" in
rc)
SUFFIX="rc"
;;
*)
SUFFIX="preview.${GITHUB_RUN_NUMBER}"
;;
esac
echo "VERSION_SUFFIX=${SUFFIX}" >> "$GITHUB_OUTPUT"
- name: Pack OpenDAL
run: dotnet pack OpenDAL/OpenDAL.csproj -c Release -o artifacts/package --version-suffix "${{ steps.version.outputs.VERSION_SUFFIX }}"
- name: Upload NuGet package
uses: actions/upload-artifact@v6
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' }}
runs-on: ubuntu-latest
needs:
- package
permissions:
contents: read
id-token: write
environment: production
steps:
- name: Setup dotnet toolchain
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"
- name: Download NuGet package
uses: actions/download-artifact@v7
with:
name: dotnet-package
path: bindings/dotnet/artifacts/package
- name: NuGet login
id: login
shell: bash
env:
NUGET_USERNAME: Apache.OpenDAL
run: |
oidc_token="$(curl -fsSL \
-H "Authorization: Bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=https%3A%2F%2Fwww.nuget.org" \
| python3 -c 'import json, sys; print(json.load(sys.stdin)["value"])')"
echo "::add-mask::${oidc_token}"
request_body="$(python3 -c 'import json, os; print(json.dumps({"username": os.environ["NUGET_USERNAME"], "tokenType": "ApiKey"}))')"
api_key="$(curl -fsSL \
-X POST https://www.nuget.org/api/v2/token \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${oidc_token}" \
-H "User-Agent: apache-opendal-release" \
--data "${request_body}" \
| python3 -c 'import json, sys; print(json.load(sys.stdin)["apiKey"])')"
echo "::add-mask::${api_key}"
echo "NUGET_API_KEY=${api_key}" >> "${GITHUB_OUTPUT}"
- 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 --skip-duplicate