Skip to content

Create "All required checks succeeded" check run when "All required checks done" CI job is actually successful #32

Create "All required checks succeeded" check run when "All required checks done" CI job is actually successful

Create "All required checks succeeded" check run when "All required checks done" CI job is actually successful #32

Workflow file for this run

name: CI
on:
push:
pull_request:
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
jobs:
check-format:
if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
name: Check format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Code formating check
run: |
dotnet tool restore
dotnet jb cleanupcode --profile="Built-in: Reformat Code" --settings="ParquetSharp.DataFrame.DotSettings" --verbosity=WARN "ParquetSharp.DataFrame" "ParquetSharp.DataFrame.Test"
files=($(git diff --name-only))
if [ ${#files[@]} -gt 0 ]
then
for file in $files; do echo "::error file=$file::Code format check failed"; done
exit 1
fi
# Build the nuget package and upload it as an artifact.
build-nuget:
if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
name: Build NuGet package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Build project
run: dotnet build ParquetSharp.DataFrame --configuration=Release
- name: Build NuGet package
run: dotnet pack ParquetSharp.DataFrame --configuration=Release --no-build --output nuget
- name: Upload NuGet artifact
uses: actions/upload-artifact@v3
with:
name: nuget-package
path: nuget
# Run .NET unit tests with the nuget package on all platforms and all supported .NET runtimes (thus testing the user workflow).
test-nuget:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
dotnet: [netcoreapp3.1, net6.0, net7.0]
arch: [x64]
include:
- os: windows-latest
dotnet: net472
arch: x64
fail-fast: false
name: Test NuGet package (.NET ${{ matrix.dotnet }} ${{ matrix.arch }} on ${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: build-nuget
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get version
id: get-version
run: echo "version=$((Select-Xml -Path ./ParquetSharp.DataFrame/ParquetSharp.DataFrame.csproj -XPath '/Project/PropertyGroup/Version/text()').node.Value)" >> $env:GITHUB_OUTPUT
shell: pwsh
- name: Download NuGet artifact
uses: actions/download-artifact@v3
with:
name: nuget-package
path: nuget
- name: Setup .NET Core 3.1 SDK
if: matrix.dotnet == 'netcoreapp3.1'
uses: actions/setup-dotnet@v3
with:
dotnet-version: 3.1.x
- name: Setup .NET 6 SDK
if: matrix.dotnet == 'net6.0'
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Setup .NET 7 SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Add local NuGet feed
run: |
dotnet new nugetconfig
dotnet nuget add source -n local $PWD/nuget
- name: Change test project references to use local NuGet package
run: |
dotnet remove ParquetSharp.DataFrame.Test reference ParquetSharp.DataFrame/ParquetSharp.DataFrame.csproj
dotnet add ParquetSharp.DataFrame.Test package ParquetSharp.DataFrame -v ${{ steps.get-version.outputs.version }}
- name: Build & Run .NET unit tests
run: dotnet test ParquetSharp.DataFrame.Test --configuration=Release --framework ${{ matrix.dotnet }}
# Virtual job that can be configured as a required check before a PR can be merged.
all-required-checks-done:
name: All required checks done
if: ${{ always() && (github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id) }}
needs:
- check-format
- test-nuget
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const results = ${{ toJSON(needs.*.result) }};
if (results.every(res => res === 'success')) {
core.info('All required checks succeeded');
} else {
core.setFailed('Some required checks failed');
}
# Create a GitHub release and publish the NuGet packages to nuget.org when a tag is pushed.
publish-release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && !github.event.repository.fork
name: Publish release
runs-on: ubuntu-latest
needs: all-required-checks-done
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check version
id: check-version
shell: pwsh
run: |
$version = (Select-Xml -Path ./ParquetSharp.DataFrame/ParquetSharp.DataFrame.csproj -XPath '/Project/PropertyGroup/Version/text()').node.Value
$tag = "${{ github.ref }}".SubString(10)
if (-not ($tag -eq $version)) {
echo "::error ::There is a mismatch between the project version ($version) and the tag ($tag)"
exit 1
}
echo "version=$version" >> $env:GITHUB_OUTPUT
- name: Download NuGet artifact
uses: actions/download-artifact@v3
with:
name: nuget-package
path: nuget
# if version contains "-" treat it as pre-release
# example: 1.0.0-beta1
- name: Create release
uses: softprops/action-gh-release@v1
with:
name: ParquetSharp.DataFrame ${{ steps.check-version.outputs.version }}
draft: true
prerelease: ${{ contains(steps.check-version.outputs.version, '-') }}
files: |
nuget/ParquetSharp.DataFrame.${{ steps.check-version.outputs.version }}.nupkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to NuGet
run: dotnet nuget push nuget/ParquetSharp.DataFrame.${{ steps.check-version.outputs.version }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json