Skip to content

Improvements

Improvements #20

name: 'Build and Test'
on:
workflow_call:
workflow_dispatch:
inputs:
reason:
description: 'The reason for running the workflow'
required: false
default: 'Manual build and run tests'
push:
tags-ignore:
- '[0-9]+.[0-9]+.[0-9]+*'
paths:
- '**.cs'
- '**.csproj'
- '**.sln'
pull_request:
branches: [ master ]
paths:
- '**.cs'
- '**.csproj'
- '**.sln'
# concurrency:
# group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
# cancel-in-progress: true
env:
# Disable the .NET logo in the console output.
DOTNET_NOLOGO: true
# Stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_ADD_GLOBAL_TOOLS_TO_PATH: false
DOTNET_MULTILEVEL_LOOKUP: 0
PROJECT_PATH: .
CONFIGURATION: Release
jobs:
before:
name: Before
runs-on: ubuntu-latest
steps:
- name: Info Before
run: |
echo "[${{ github.event_name }}] event automatically triggered this job."
echo "branch name is ${{ github.ref }}"
echo "This job has a '${{ job.status }}' status."
- name: Run a one-line script
run: |
echo "Is true: $( [ \"$EVENT_NAME\" = 'push' ] && [ \"$GITHUB_REF\" != 'refs/tags/' ] ) || [ \"$EVENT_NAME\" = 'workflow_dispatch' ]"
env:
EVENT_NAME: ${{ github.event_name }}
GITHUB_REF: ${{ github.ref }}
build:
needs: before
name: Build ${{ matrix.os }} - dotnet ${{ matrix.dotnet }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
steps:
- name: Print manual run reason
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo 'Reason: ${{ github.event.inputs.reason }}'
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
- name: Setup .NET (global.json)
uses: actions/setup-dotnet@v4
- name: Display dotnet version
run: dotnet --version
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget
- name: Restore
run: dotnet restore "${{ env.PROJECT_PATH }}"
- name: Build
run: >-
dotnet build "${{ env.PROJECT_PATH }}"
--configuration "${{ env.CONFIGURATION }}"
--no-restore
- name: Test
timeout-minutes: 60
run: >-
dotnet test "${{ env.PROJECT_PATH }}"
--no-restore
--no-build
--verbosity normal
--logger trx
--results-directory "TestResults-${{ matrix.os }}" || true
- name: Upload test results
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.os }}
path: TestResults-${{ matrix.os }}