dotnet #227
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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | |
name: dotnet | |
permissions: read-all | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Release version to tag and create' | |
required: false | |
env: | |
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | |
DOTNET_NOLOGO: true | |
NuGetDirectory: ${{ github.workspace }}/nuget | |
jobs: | |
build: | |
strategy: | |
matrix: | |
os: [windows-latest, ubuntu-latest, macos-13] # macos-13 is x64, macos-latest is arm64. See https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners | |
configuration: [Debug, Release] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Important for Nerdbank.GitVersioning to calculate versions | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
global-json-file: global.json | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Build | |
run: dotnet build -c ${{ matrix.configuration }} -p:Platform="Any CPU" --no-restore | |
- name: Test | |
run: dotnet test -c ${{ matrix.configuration }} -p:Platform="Any CPU" --no-build --verbosity normal --collect:"XPlat Code Coverage" | |
- name: Upload coverage reports to Codecov | |
if: matrix.os != 'macos-13' # Temporary disable for macos-13 until issue fixed. See https://github.com/codecov/codecov-action/issues/1549 | |
uses: codecov/codecov-action@v3 | |
with: | |
flags: ${{ matrix.os }},${{ matrix.configuration }} | |
format: | |
strategy: | |
matrix: | |
os: [ubuntu-latest] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
global-json-file: global.json | |
- name: Format verify no changes | |
run: dotnet format --verify-no-changes | |
pack: | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Important for Nerdbank.GitVersioning to calculate versions | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
global-json-file: global.json | |
- name: Pack XGBoostSharp | |
run: dotnet pack src/XGBoostSharp/XGBoostSharp.csproj -c Release -p:Platform="Any CPU" --output ${{ env.NuGetDirectory }} | |
- name: Add local package source | |
run: dotnet nuget add source ${{ env.NuGetDirectory }} --name local | |
- name: Get version of dll | |
run: | | |
$dllPath = Get-ChildItem -Path ./build -Filter XGBoostSharp.dll -Recurse | Select-Object -First 1 | |
if ($dllPath) { | |
(Get-Item $dllPath.FullName).VersionInfo.ProductVersion | |
} else { | |
Write-Error "DLL file not found" | |
} | |
- name: Pack XGBoostSharp-cpu | |
if: ${{ github.event.inputs.version != '' && github.actor == 'mdabros'}} | |
run: nuget pack pkg/XGBoostSharp-cpu.nuspec -Version ${{ github.event.inputs.version }} -OutputDirectory ${{ env.NuGetDirectory }} | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: nuget | |
if-no-files-found: error | |
retention-days: 7 | |
path: ${{ env.NuGetDirectory }}/*nupkg | |
create-release-push: | |
needs: [ build, pack ] | |
runs-on: windows-latest | |
permissions: | |
contents: write | |
if: ${{ github.event.inputs.version != '' && github.actor == 'mdabros'}} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Download nuget packages | |
uses: actions/download-artifact@v4 | |
with: | |
name: nuget | |
path: ${{ env.NuGetDirectory }} | |
- name: Create release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.ACTION_GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ github.event.inputs.version }} | |
release_name: ${{ github.event.inputs.version }} | |
draft: true | |
- name: Create tag (for release) | |
run: | | |
git tag v${{ github.event.inputs.version }} | |
git push origin v${{ github.event.inputs.version }} | |
- name: Upload XGBoostSharp package | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.ACTION_GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ env.NuGetDirectory }}/XGBoostSharp.${{ github.event.inputs.version }}.nupkg | |
asset_name: XGBoostSharp.${{ github.event.inputs.version }}.nupkg | |
asset_content_type: application/zip | |
- name: Upload XGBoostSharp-cpu package | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.ACTION_GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ${{ env.NuGetDirectory }}/XGBoostSharp-cpu.${{ github.event.inputs.version }}.nupkg | |
asset_name: XGBoostSharp-cpu.${{ github.event.inputs.version }}.nupkg | |
asset_content_type: application/zip | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
global-json-file: global.json | |
- name: Push XGBoostSharp package | |
run: dotnet nuget push ${{ env.NuGetDirectory }}/XGBoostSharp.${{ github.event.inputs.version }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate | |
- name: Push XGBoostSharp-cpu package | |
run: dotnet nuget push ${{ env.NuGetDirectory }}/XGBoostSharp-cpu.${{ github.event.inputs.version }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate |