Matrix Build and publish Ziti Native to nuget #178
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Matrix Build and publish Ziti Native to nuget | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: Version of CSDK/Nuget Package | |
default: _CHANGE_ | |
required: true | |
debugOrRelease: | |
description: Debug or Release | |
default: Release | |
required: true | |
env: | |
ZITI_SDK_C_BRANCH: ${{ github.event.inputs.version }} | |
ZITI_DEBUG_OR_RELEASE: ${{ github.event.inputs.debugOrRelease }} | |
NUGET_SOURCE: https://api.nuget.org/v3/index.json | |
BUILD_NUMBER: ${{ github.run_number }} | |
BASEDIR: ${{ github.workspace }}/ZitiNativeApiForDotnetCore | |
TARGETDIR: ${{ github.workspace }}/ZitiNativeApiForDotnetCore/build | |
jobs: | |
set-build-info: | |
runs-on: ubuntu-latest | |
outputs: | |
now: ${{ steps.buildinfo.outputs.now }} | |
repo: ${{ steps.buildinfo.outputs.repo }} | |
branch: ${{ steps.buildinfo.outputs.branch }} | |
qualifier: ${{ steps.qualifierinfo.outputs.qualifier }} | |
steps: | |
- name: Set now, repo, branch, build num | |
id: buildinfo | |
run: | | |
echo "now=$(date '+%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT | |
if [ "${{ github.repository }}" == 'openziti/ziti-sdk-csharp' ]; then | |
echo "repo=" >> $GITHUB_OUTPUT | |
else | |
echo "repo=${{github.repository_owner}}" >> $GITHUB_OUTPUT | |
fi | |
echo "BRANCH_NAME=$(echo $GITHUB_REF | sed 's/refs\/heads\///')" >> $GITHUB_ENV | |
echo "branch=$(echo $GITHUB_REF | sed 's/refs\/heads\///')" >> $GITHUB_OUTPUT | |
- name: Set qualifier | |
id: qualifierinfo | |
run: | | |
if [ "${BRANCH_NAME}" = "main" ]; then | |
echo "qualifier=.${{github.run_number}}" >> $GITHUB_OUTPUT | |
else | |
echo "qualifier=-${BRANCH_NAME}rc${{github.run_number}}" >> $GITHUB_OUTPUT | |
fi | |
native-matrix-build: | |
if: "!contains(github.event.head_commit.message, 'ci skip') && ${{ github.actor != 'dependabot[bot]' }}" | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- ext: so | |
prefix: lib | |
dist: linux | |
os: ubuntu-20.04 | |
arch: x64 | |
preset: linux-x64 | |
- ext: so | |
prefix: lib | |
dist: 'Linux-arm' | |
os: ubuntu-20.04 | |
arch: arm | |
preset: linux-arm | |
- ext: so | |
prefix: lib | |
dist: 'Linux-arm64' | |
os: ubuntu-20.04 | |
arch: arm64 | |
preset: linux-arm64 | |
- ext: dylib | |
prefix: lib | |
dist: macos | |
os: macOS-13 | |
arch: x64 | |
preset: macOS-x64 | |
- ext: dylib | |
prefix: lib | |
dist: macos | |
os: macOS-13 | |
arch: arm64 | |
preset: macOS-arm64 | |
- ext: dylib | |
prefix: lib | |
dist: iOS | |
os: macOS-13 | |
arch: arm64 | |
preset: ios-arm64 | |
- ext: dll | |
dist: win | |
os: windows-2022 | |
arch: x64 | |
preset: win64 | |
- ext: dll | |
dist: win | |
arch: x86 | |
os: windows-2022 | |
preset: win32 | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install Linux pkg-config | |
if: matrix.os == 'ubuntu-20.04' | |
run: | | |
sudo apt update -y | |
sudo apt install -y pkg-config ninja-build | |
- name: Install Crossbuild tools | |
if: matrix.os == 'ubuntu-20.04' && contains(matrix.arch, 'arm') | |
run: | | |
sudo apt update -y | |
sudo apt install -y crossbuild-essential-armhf crossbuild-essential-arm64 | |
- name: Install MacOS Ninja | |
if: matrix.os == 'macOS-13' | |
run: | | |
brew install ninja | |
- name: Set up MSVC 2019 | |
if: matrix.dist == 'win' | |
uses: microsoft/[email protected] | |
- name: Restore vcpkg packages | |
working-directory: ${{env.GITHUB_WORKSPACE}} | |
run: vcpkg integrate install | |
- name: Set VCPKG_ROOT | |
if: matrix.os == 'ubuntu-20.04' || matrix.os == 'macOS-13' | |
run: echo "VCPKG_ROOT=/usr/local/share/vcpkg" >> $GITHUB_ENV | |
- name: Set VCPKG_ROOT | |
if: matrix.dist == 'win' | |
run: echo "VCPKG_ROOT=C:/vcpkg" >> $env:GITHUB_ENV | |
- name: configure / build CMake | |
working-directory: ${{ github.workspace }}/ZitiNativeApiForDotnetCore | |
run: | | |
echo "VCPKG_ROOT = ${{ env.VCPKG_ROOT }}" | |
cmake -E make_directory ${{ env.TARGETDIR }} | |
cmake -S ${{ env.BASEDIR }} -B ${{ env.TARGETDIR }} --preset ${{ matrix.preset }} | |
cmake --build ${{ env.TARGETDIR }} --config ${{ env.ZITI_DEBUG_OR_RELEASE }} | |
- name: upload artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.dist }}.${{ matrix.arch }}.${{ matrix.prefix }}ziti4dotnet.${{ matrix.ext }} | |
path: ${{ env.TARGETDIR }}/library/${{ env.ZITI_DEBUG_OR_RELEASE }}/${{ matrix.prefix }}ziti4dotnet.${{ matrix.ext }} | |
if-no-files-found: error | |
create-nuget-package: | |
needs: [set-build-info, native-matrix-build] | |
env: | |
now: ${{needs.set-build-info.outputs.now}} | |
repo: ${{needs.set-build-info.outputs.repo}} | |
branch: ${{needs.set-build-info.outputs.branch}} | |
qualifier: ${{needs.set-build-info.outputs.qualifier}} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set resolves version to env | |
run: | | |
echo "resolvedversion=${{ env.ZITI_SDK_C_BRANCH }}${repo}${qualifier}" >> $GITHUB_ENV | |
- run: mkdir ${{github.workspace}}/native | |
- name: download all artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
path: ${{github.workspace}}/native | |
- name: move files to expected locations | |
run: | | |
echo "locating all the built libraries:" | |
find . -name "*ziti4dotnet.*" | |
echo "creating the RIDs" | |
mkdir -p ${{github.workspace}}/runtimes/osx-x64/native | |
mkdir -p ${{github.workspace}}/runtimes/osx-arm64/native | |
mkdir -p ${{github.workspace}}/runtimes/ios-arm64/native | |
mkdir -p ${{github.workspace}}/runtimes/linux-arm/native | |
mkdir -p ${{github.workspace}}/runtimes/linux-arm64/native | |
mkdir -p ${{github.workspace}}/runtimes/linux-x64/native | |
mkdir -p ${{github.workspace}}/runtimes/win-x86/native | |
mkdir -p ${{github.workspace}}/runtimes/win-x64/native | |
echo "moving the build libraries to the RIDs" | |
mv ${{github.workspace}}/native/macos.x64.libziti4dotnet.dylib/libziti4dotnet.dylib ${{github.workspace}}/runtimes/osx-x64/native | |
mv ${{github.workspace}}/native/macos.arm64.libziti4dotnet.dylib/libziti4dotnet.dylib ${{github.workspace}}/runtimes/osx-arm64/native | |
mv ${{github.workspace}}/native/iOS.arm64.libziti4dotnet.dylib/libziti4dotnet.dylib ${{github.workspace}}/runtimes/ios-arm64/native | |
mv ${{github.workspace}}/native/Linux-arm64.arm64.libziti4dotnet.so/libziti4dotnet.so ${{github.workspace}}/runtimes/linux-arm64/native | |
mv ${{github.workspace}}/native/Linux-arm.arm.libziti4dotnet.so/libziti4dotnet.so ${{github.workspace}}/runtimes/linux-arm/native | |
mv ${{github.workspace}}/native/linux.x64.libziti4dotnet.so/libziti4dotnet.so ${{github.workspace}}/runtimes/linux-x64/native | |
mv ${{github.workspace}}/native/win.x64.ziti4dotnet.dll/ziti4dotnet.dll ${{github.workspace}}/runtimes/win-x64/native | |
mv ${{github.workspace}}/native/win.x86.ziti4dotnet.dll/ziti4dotnet.dll ${{github.workspace}}/runtimes/win-x86/native | |
- name: Setup .NET Core | |
uses: actions/setup-dotnet@v2 | |
with: | |
dotnet-version: 6.x | |
- name: Create the Nuget package | |
run: nuget pack -version ${{env.resolvedversion}} ${{ github.workspace }}/native-package.nuspec | |
- name: upload nuget package | |
uses: actions/upload-artifact@v3 | |
with: | |
path: ${{ github.workspace }}/OpenZiti.NET.native.${{env.resolvedversion}}.nupkg | |
name: OpenZiti.NET.native.${{env.resolvedversion}}.nupkg | |
if-no-files-found: error | |
- name: Upload OpenZiti.NET.native to job | |
uses: actions/upload-artifact@v3 | |
with: | |
name: OpenZiti.NET.native.${{env.resolvedversion}}.nupkg | |
path: OpenZiti.NET.native.${{env.resolvedversion}}.nupkg | |
if-no-files-found: error | |
- name: Publish OpenZiti.NET.native | |
if: "${{ github.repository == 'openziti/ziti-sdk-csharp'}}" | |
run: dotnet nuget push OpenZiti.NET.native.${{env.resolvedversion}}.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json |