Skip to content

Migrate to xUnit 3 #2059

Migrate to xUnit 3

Migrate to xUnit 3 #2059

name: Corelibrary Build & Publish
on:
push:
branches:
- "v[0-9]+.[0-9]+-?*"
pull_request:
workflow_dispatch:
env:
DOTNET_VERSION: 9.0.100
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
jobs:
event_file:
name: "Event File"
runs-on: ubuntu-latest
steps:
- name: Upload
uses: actions/upload-artifact@v4
with:
name: Event File
path: ${{ github.event_path }}
prepare:
name: Prepare & Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
publish_artifacts: ${{ steps.version.outputs.publish_artifacts }}
publish_nuget: ${{ steps.version.outputs.publish_nuget }}
artifacts_name: ${{ steps.version.outputs.artifacts_name }}
steps:
- name: Version
id: version
run: |
BRANCH=${GITHUB_REF#refs/*/}
if [[ $BRANCH =~ ^v([0-9]+.[0-9]+)(-[a-zA-Z0-9]+)?$ ]]
then
BUILD_NUMBER=$(( GITHUB_RUN_NUMBER + 500 )) # compensate for old jenkins CI
BRANCH_VERSION=${BASH_REMATCH[1]}
VERSION_SUFFIX=${BASH_REMATCH[2]}
VERSION="${BRANCH_VERSION}.${BUILD_NUMBER}${VERSION_SUFFIX}"
PUBLISH_ARTIFACTS=1
ARTIFACTS_NAME="LeanCode.CoreLibrary.$VERSION.zip"
else
VERSION="0.0.0"
PUBLISH_ARTIFACTS=0
ARTIFACTS_NAME="<none>"
fi
echo Building on "$BRANCH"
echo Building version: "$VERSION"
echo "Artifacts will be saved as $ARTIFACTS_NAME"
if [[ $GITHUB_EVENT_NAME == 'workflow_dispatch' ]]
then
echo "Packages will be published to NuGet"
PUBLISH_NUGET=1
else
PUBLISH_NUGET=0
fi
if [[ $PUBLISH_ARTIFACTS == 0 && $PUBLISH_NUGET == 1 ]]
then
echo "Only vX.Y branches can be published to NuGet, failing"
exit 1
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "publish_artifacts=${PUBLISH_ARTIFACTS}" >> $GITHUB_OUTPUT
echo "publish_nuget=${PUBLISH_NUGET}" >> $GITHUB_OUTPUT
echo "artifacts_name=${ARTIFACTS_NAME}" >> $GITHUB_OUTPUT
build:
name: Build
runs-on: ubuntu-latest
needs: [prepare]
permissions:
checks: write
pull-requests: write
env:
VERSION: ${{ needs.prepare.outputs.version }}
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore
run: dotnet restore
- name: Tool Restore
run: dotnet tool restore
- name: Check formatting
if: false
run: dotnet csharpier . --check
- name: Build
run: dotnet build --configuration Release --no-restore
env:
GIT_COMMIT: ${{ github.sha }}
- name: Pack
if: ${{ needs.prepare.outputs.publish_artifacts == '1' }}
env:
ZIP: ${{ needs.prepare.outputs.artifacts_name }}
run: |
dotnet pack --no-build -c Release -o "$PWD/packed"
zip -j "$ZIP" "$PWD"/packed/*.nupkg
- name: Publish artifacts
if: ${{ needs.prepare.outputs.publish_artifacts == '1' }}
uses: actions/upload-artifact@v4
with:
name: ${{ needs.prepare.outputs.artifacts_name }}
path: ${{ needs.prepare.outputs.artifacts_name }}
test:
runs-on: ubuntu-latest
name: Test
needs: [prepare, build]
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: Passw12#
ports:
- "1433:1433"
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: Passw12#
ports:
- "5432:5432"
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore
run: dotnet restore
- name: Unit tests
run: dotnet test
- name: Azure Test
run: dotnet test -- --explicit on --filter-trait 'service=azure'
env:
CORELIB_TESTS_TENANT_ID: ${{ secrets.CORELIB_TESTS_TENANT_ID }}
CORELIB_TESTS_CLIENT_ID: ${{ secrets.CORELIB_TESTS_CLIENT_ID }}
CORELIB_TESTS_CLIENT_SECRET: ${{ secrets.CORELIB_TESTS_CLIENT_SECRET }}
CORELIB_TESTS_NPGSQL_CONNECTION_STRING: ${{ secrets.CORELIB_TESTS_NPGSQL_CONNECTION_STRING }}
CORELIB_TESTS_AZURE_BLOB_STORAGE_SERVICE_URI: ${{ secrets.CORELIB_TESTS_AZURE_BLOB_STORAGE_SERVICE_URI }}
CORELIB_TESTS_AZURE_TABLE_STORAGE_SERVICE_URI: ${{ secrets.CORELIB_TESTS_AZURE_TABLE_STORAGE_SERVICE_URI }}
CORELIB_TESTS_AZURE_BLOB_STORAGE_CONTAINER_NAME: ${{ secrets.CORELIB_TESTS_AZURE_BLOB_STORAGE_CONTAINER_NAME }}
CORELIB_TESTS_AZURE_TABLE_STORAGE_TABLE_NAME: ${{ secrets.CORELIB_TESTS_AZURE_TABLE_STORAGE_TABLE_NAME }}
- name: Integration Test - SQL Server
run: dotnet test -- --explicit on --filter-query '/[(category=integration)&(database!=postgres)]'
env:
SqlServer__ConnectionStringBase: Server=localhost,1433;User Id=sa;Password=Passw12#;Encrypt=false
LeanCodeIntegrationTests__Database: sqlserver
- name: Integration Test - Postgres
run: dotnet test -- --explicit on --filter-trait 'category=integration'
env:
Postgres__ConnectionStringBase: Host=localhost;Username=postgres;Password=Passw12#
LeanCodeIntegrationTests__Database: postgres
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
working-directory: ./TestResults
- name: Upload test report
if: always()
run: |
# Strip BOM first :clown:
find TestResults -name '*.json' | xargs -n 1 sed -i "$(printf '1s/^\357\273\277//')"
npx ctrf merge TestResults --output merged.json
echo 'Summary'
npx github-actions-ctrf summary TestResults/merged.json
echo 'Failed'
npx github-actions-ctrf failed-folded TestResults/merged.json
echo 'Skipped'
npx github-actions-ctrf skipped TestResults/merged.json
echo 'Annotate'
npx github-actions-ctrf annotate TestResults/merged.json
echo 'pull request'
npx github-actions-ctrf pull-request TestResults/merged.json --overwrite-comment --comment-tag "${{ github.workflow }}-${{ github.job }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
runs-on: ubuntu-latest
name: Publish to feeds
needs: [prepare, build, test]
if: ${{ needs.prepare.outputs.publish_artifacts == '1' }}
steps:
- name: Fetch build
id: download
uses: actions/download-artifact@v4
with:
name: ${{ needs.prepare.outputs.artifacts_name }}
- name: Unzip
run: |
unzip "$ZIP"
env:
ZIP: ${{ needs.prepare.outputs.artifacts_name }}
- name: Push to Feedz
run: |
find -name '*.nupkg' -exec dotnet nuget push -k "$FEEDZ_API_KEY" -s 'https://f.feedz.io/leancode/public/nuget/index.json' -n '{}' ';'
env:
FEEDZ_API_KEY: ${{ secrets.FEEDZ_API_KEY }}
- name: Create release
if: ${{ needs.prepare.outputs.publish_nuget == '1' }}
uses: actions/create-release@v1
with:
tag_name: ${{ format('v{0}', needs.prepare.outputs.version) }}
release_name: ${{ format('Release v{0}', needs.prepare.outputs.version) }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Push to NuGet
if: ${{ needs.prepare.outputs.publish_nuget == '1' }}
run: |
find -name '*.nupkg' -exec dotnet nuget push -k "$NUGET_API_KEY" -s 'https://api.nuget.org/v3/index.json' -n '{}' ';'
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}