Skip to content

Matrix Build and publish Ziti Native to nuget #153

Matrix Build and publish Ziti Native to nuget

Matrix Build and publish Ziti Native to nuget #153

name: Matrix Build and publish Ziti Native to nuget
on:
workflow_dispatch:
inputs:
version:
description: Version of CSDK/Nuget Package
default: _CHANGE_
required: true
env:
ZITI_SDK_C_BRANCH: ${{ github.event.inputs.version }}
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.isotime.outputs.val }}
buildnum_official: "${{ steps.buildnum_official.outputs.val }}"
buildnum_dev: "${{ steps.buildnum_dev.outputs.val }}"
steps:
- name: Set date
id: isotime
run: echo "val=$(date '+%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
- name: Set buildnum_dev
id: buildnum_dev
if: "${{ github.repository != 'openziti/ziti-sdk-csharp'}}"
run: echo "val=-build.$(date '+%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
- name: Set buildnum_official
if: "${{ github.repository == 'openziti/ziti-sdk-csharp'}}"
id: buildnum_official
run: echo "val=.${{env.BUILD_NUMBER}}" >> $GITHUB_OUTPUT
native-matrix-build:
needs: set-build-info
env:
now: ${{needs.set-build-info.outputs.now}}
buildnum: ${{needs.set-build-info.outputs.buildnum_official}}${{needs.set-build-info.outputs.buildnum_dev}}
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
cmake_arch_flag: '-A Win32'
os: windows-2022
preset: win32
steps:
- name: Echo Vars
run: |
echo "now = ${{ env.now }}"
echo "build number = ${{ env.buildnum }}"
- 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/setup-msbuild@v1.1
- 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 "build number = ${{ env.buildnum }}"
echo "VCPKG_ROOT = ${{ env.VCPKG_ROOT }}"
cmake -E make_directory ${{ env.TARGETDIR }}
cmake -S ${{ env.BASEDIR }} -B ${{ env.TARGETDIR }} --preset ${{ matrix.preset }} ${{ matrix.cmake_arch_flag }}
cmake --build ${{ env.TARGETDIR }} --config Release
- name: upload artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.dist }}.${{ matrix.arch }}.${{ matrix.prefix }}ziti4dotnet.${{ matrix.ext }}
path: ${{ env.TARGETDIR }}/library/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}}
buildnum: ${{needs.set-build-info.outputs.buildnum_official}}${{needs.set-build-info.outputs.buildnum_dev}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- 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.ZITI_SDK_C_BRANCH }}${{ env.buildnum }} ${{ github.workspace }}/native-package.nuspec
- name: upload nuget package
uses: actions/upload-artifact@v3
with:
path: ${{ github.workspace }}/OpenZiti.NET.native.${{ env.ZITI_SDK_C_BRANCH }}${{ env.buildnum }}.nupkg
name: OpenZiti.NET.native.${{ env.ZITI_SDK_C_BRANCH }}${{ env.buildnum }}.nupkg
if-no-files-found: error
- name: Upload OpenZiti.NET.native to job
uses: actions/upload-artifact@v3
with:
name: OpenZiti.NET.native.${{ env.ZITI_SDK_C_BRANCH }}${{ env.buildnum }}.nupkg
path: OpenZiti.NET.native.${{ env.ZITI_SDK_C_BRANCH }}${{ env.buildnum }}.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.ZITI_SDK_C_BRANCH }}${{ env.buildnum }}.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json