APMSP-1542 feat: setup dotnet CI and add support for win-x64, win-x86, linux-x64, linux-arm64 & osx-arm64 #159
Workflow file for this run
This file contains hidden or 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: .NET | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| env: | |
| OUTPUT_DIR: bin | |
| PACKAGES_DIR: packages | |
| NUGET_NAME: ganeshnj.libdatadog | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| # only set container for linux builds | |
| container: ${{ matrix.container }} | |
| env: | |
| ACTIONS_RUNNER_FORCE_ACTIONS_NODE_VERSION: node16 | |
| ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true | |
| strategy: | |
| matrix: | |
| include: | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| - os: windows-latest | |
| target: i686-pc-windows-msvc | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| container: centos:7 | |
| - os: arm-4core-linux-ubuntu24.04 | |
| target: aarch64-unknown-linux-gnu | |
| container: centos:7 | |
| # - os: ubuntu-latest | |
| # target: x86_64-unknown-linux-musl | |
| # - os: ubuntu-latest | |
| # target: aarch64-unknown-linux-musl | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Prepare toolset | |
| if: matrix.container == 'centos:7' | |
| run: | | |
| sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* | |
| sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* | |
| yum install epel-release -y | |
| yum clean all -y && yum makecache -y && yum update -y | |
| yum install -y centos-release-scl \ | |
| && sed -i s/mirror.centos.org/buildlogs.centos.org/g /etc/yum.repos.d/CentOS-SCLo-*.repo \ | |
| && sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/CentOS-SCLo-*.repo \ | |
| && sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/CentOS-SCLo-*.repo \ | |
| && yum install -y --setopt=tsflags=nodocs --nogpgcheck \ | |
| curl \ | |
| devtoolset-9 \ | |
| git \ | |
| make \ | |
| pkg-config \ | |
| unzip \ | |
| strace \ | |
| zlib-devel \ | |
| jq \ | |
| && yum clean all --enablerepo='*' \ | |
| scl enable devtoolset-9 bash | |
| gcc --version | |
| - name: Install rustup | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| $ProgressPreference = "SilentlyContinue" | |
| Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe | |
| .\rustup-init.exe -y --default-host=${{ matrix.target }} --default-toolchain stable --profile minimal | |
| del rustup-init.exe | |
| rustup target add ${{ matrix.target }} | |
| shell: powershell | |
| - name: Install rustup | |
| if: matrix.os == 'macos-latest' | |
| run: | | |
| curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | |
| source $HOME/.cargo/env | |
| rustup target add ${{ matrix.target }} | |
| cargo install --force cbindgen | |
| shell: bash | |
| - name: Install rustup | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | |
| source $HOME/.cargo/env | |
| rustup target add ${{ matrix.target }} | |
| cargo install --force cbindgen | |
| shell: bash | |
| - name: Setup cross-compilation | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| cat .cargo/config.github >> .cargo/config | |
| # - name: Install musl x86_64 dependencies | |
| # if: matrix.target == 'x86_64-unknown-linux-musl' | |
| # run: sudo apt-get install musl-tools | |
| # - name: Install musl aarch64 dependencies | |
| # if: matrix.target == 'aarch64-unknown-linux-musl' | |
| # run: | | |
| # mkdir -p $HOME/.local | |
| # curl -o /tmp/musl.tgz https://musl.cc/aarch64-linux-musl-cross.tgz | |
| # tar -xzf /tmp/musl.tgz -C $HOME/.local | |
| # echo "$HOME/.local/aarch64-linux-musl-cross/bin" >> $GITHUB_PATH | |
| # cat .cargo/config.github >> .cargo/config | |
| - name: Build | |
| run: ./windows/build-artifacts.ps1 ${{ env.OUTPUT_DIR }} ${{ matrix.target }} | |
| if : matrix.os == 'windows-latest' | |
| shell: pwsh | |
| - name: Build | |
| run: | | |
| source $HOME/.cargo/env | |
| ./windows/build-artifacts.sh ${{ env.OUTPUT_DIR }} ${{ matrix.target }} | |
| if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' || matrix.os == 'arm-4core-linux-ubuntu24.04' | |
| shell: bash | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v3.0.0 | |
| with: | |
| name: ${{ env.OUTPUT_DIR }}-${{ matrix.target }} | |
| path: | | |
| bin/* | |
| !bin/*/*/build | |
| !bin/*/*/deps | |
| !bin/*/*/examples | |
| !bin/*/*/incremental | |
| !bin/*/*/.fingerprint | |
| !bin/debug | |
| !bin/release | |
| pack: | |
| runs-on: windows-latest | |
| needs: build | |
| outputs: | |
| NUGET_VERSION: ${{ steps.dotnet-pack.outputs.NUGET_VERSION }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Download x86_64-pc-windows-msvc | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: ${{ env.OUTPUT_DIR }}-x86_64-pc-windows-msvc | |
| path: bin | |
| - name: Download i686-pc-windows-msvc | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: ${{ env.OUTPUT_DIR }}-i686-pc-windows-msvc | |
| path: bin | |
| - name: Download x86_64-unknown-linux-gnu | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: ${{ env.OUTPUT_DIR }}-x86_64-unknown-linux-gnu | |
| path: bin | |
| - name: Download aarch64-unknown-linux-gnu | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: ${{ env.OUTPUT_DIR }}-aarch64-unknown-linux-gnu | |
| path: bin | |
| # - name: Download x86_64-unknown-linux-musl | |
| # uses: actions/download-artifact@v3 | |
| # with: | |
| # name: ${{ env.OUTPUT_DIR }}-x86_64-unknown-linux-musl | |
| # path: bin | |
| # - name: Download aarch64-unknown-linux-musl | |
| # uses: actions/download-artifact@v3 | |
| # with: | |
| # name: ${{ env.OUTPUT_DIR }}-aarch64-unknown-linux-musl | |
| # path: bin | |
| - name: Download aarch64-apple-darwin | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: ${{ env.OUTPUT_DIR }}-aarch64-apple-darwin | |
| path: bin | |
| - name: Download x86_64-apple-darwin | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: ${{ env.OUTPUT_DIR }}-x86_64-apple-darwin | |
| path: bin | |
| - name: dotnet pack | |
| id: dotnet-pack | |
| run: | | |
| $cargo_content=Get-Content Cargo.toml -Raw | |
| $cargo_content -match '(?m)^version += +"([^"]+)"' | |
| $current_version=$Matches[1] | |
| $version_suffix="ci.${{ github.event.number }}.${{ github.run_number }}" | |
| $version="$current_version-$version_suffix" | |
| echo "NUGET_VERSION=$version" >> $env:GITHUB_OUTPUT | |
| dotnet pack windows/libdatadog.csproj -p:LibDatadogBinariesOutputDir=../${{ env.OUTPUT_DIR }} -p:LibDatadogVersion=$version -p:PackageID=${{ env.NUGET_NAME }} -o ${{ env.PACKAGES_DIR }} | |
| - name: Upload package | |
| uses: actions/upload-artifact@v3.0.0 # v4 | |
| with: | |
| name: ${{ env.PACKAGES_DIR }} | |
| path: ${{ env.PACKAGES_DIR }} | |
| test: | |
| runs-on: ${{ matrix.os }} | |
| needs: pack | |
| strategy: | |
| matrix: | |
| include: | |
| - os: windows-latest | |
| - os: ubuntu-latest | |
| - os: macos-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Download package | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: ${{ env.PACKAGES_DIR }} | |
| path: ${{ env.PACKAGES_DIR }} | |
| - name: Install .NET SDK | |
| uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25 #v4 | |
| with: | |
| dotnet-version: 6.0.X | |
| - name: Test | |
| run: | | |
| cd tests/nuget_package | |
| dotnet add nuget_package.csproj package ${{ env.NUGET_NAME }} --version ${{ needs.pack.outputs.NUGET_VERSION }} | |
| dotnet run | |
| nuget-push: | |
| runs-on: windows-latest | |
| needs: test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Download package | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: ${{ env.PACKAGES_DIR }} | |
| path: ${{ env.PACKAGES_DIR }} | |
| - name: Install .NET SDK | |
| uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25 #v4 | |
| with: | |
| dotnet-version: 6.0.X | |
| - name: NuGet push | |
| run: | | |
| cd ${{ env.PACKAGES_DIR }} | |
| dotnet nuget push *.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate |