Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve workflows #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 46 additions & 26 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,44 @@ name: CD

on:
workflow_call:
inputs:
path:
description: The path where to look for a Visual Studio Solution file (without a trailing slash).
type: string
required: false
default: ''
secrets:
NUGET_API_KEY:
required: true

env:
BUILD_CONFIG: Release
DOTNET_GLOBAL_JSON: ${{ inputs.path != '' && format('{0}/global.json', inputs.path) || 'global.json' }}
RESTORE_PATTERN: ${{ inputs.path != '' && format('{0}/**/packages.lock.json', inputs.path) || '**/packages.lock.json' }}
ARTIFACTS_PATH: ${{ inputs.path != '' && format('{0}/nupkg', inputs.path) || 'nupkg' }}

jobs:
release:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.1.0
uses: actions/checkout@v3
with:
# Required by NBGV
fetch-depth: 0

- name: .NET Setup
uses: flobernd/actions/dotnet/setup@master
uses: zyactions/dotnet-setup@v1
with:
# Use version defined in 'global.json'
dotnet-version: ''
disable-problem-matcher: true
global-json-file: ${{ env.DOTNET_GLOBAL_JSON }}
problem-matcher: false

- name: Detect Version
uses: dotnet/nbgv@master
id: nbgv
uses: dotnet/nbgv@master
with:
path: ${{ inputs.path }}

- name: Create Release
uses: flobernd/actions/github/create-release@master
Expand All @@ -41,52 +51,63 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
FILTERED_SOLUTION: ${{ inputs.path != '' && format('{0}/Packages.slnf', inputs.path) || 'Packages.slnf' }}
steps:
- name: Checkout
uses: actions/checkout@v3.1.0
uses: actions/checkout@v3
with:
# Required by NBGV
fetch-depth: 0

- name: Find Solution
id: find
uses: flobernd/actions/dotnet/find-solution@master
with:
directory: ${{ inputs.path }}

- uses: flobernd/actions/dotnet/filter-solution@master
name: Filter Solution
with:
solution: ${{ steps.find.outputs.solution }}
# This pattern is relative to the solution file and does not need to be prefixed with
# the 'directory' input value
pattern: |
**/*.csproj
!**/*.Test*.csproj
!**/*.Examples*.csproj
output: ./Packages.slnf
output: ${{ env.FILTERED_SOLUTION }}

- name: .NET Setup
uses: flobernd/actions/dotnet/setup@master
uses: zyactions/dotnet-setup@v1
with:
global-json-file: ${{ env.DOTNET_GLOBAL_JSON }}
problem-matcher: true

- name: .NET Cache Packages
uses: actions/cache@v3
with:
# Use version defined in 'global.json'
dotnet-version: ''
disable-problem-matcher: false
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles(env.RESTORE_PATTERN) }}
restore-keys: ${{ runner.os }}-nuget-

- name: .NET Restore
uses: flobernd/actions/dotnet/restore@master
uses: zactions/dotnet-restore@v1
with:
workspace: ./Packages.slnf
cache-key: ${{ hashFiles('**/packages.lock.json') }}
workspace: ${{ env.FILTERED_SOLUTION }}

- name: .NET Pack
uses: flobernd/actions/dotnet/pack@master
with:
workspace: ./Packages.slnf
workspace: ${{ env.FILTERED_SOLUTION }}
configuration: ${{ env.BUILD_CONFIG }}
output: ./nupkg
output: ${{ env.ARTIFACTS_PATH }}

- name: Upload Artifact
uses: actions/upload-artifact@v3.1.1
uses: actions/upload-artifact@v3
with:
name: packages
path: ./nupkg
path: ${{ env.ARTIFACTS_PATH }}

publish:
name: Publish to ${{ matrix.feed.name }}
Expand All @@ -100,21 +121,20 @@ jobs:
needs: build
steps:
- name: .NET Setup
uses: flobernd/actions/dotnet/setup@master
uses: zyactions/dotnet-setup@v1
with:
# Use version defined in 'global.json'
dotnet-version: ''
disable-problem-matcher: true
global-json-file: ${{ env.DOTNET_GLOBAL_JSON }}
problem-matcher: false

- name: Download Packages
uses: actions/download-artifact@v3.0.1
uses: actions/download-artifact@v3
with:
name: packages
path: ./nupkg
path: ${{ env.ARTIFACTS_PATH }}

- name: .NET NuGet Push
uses: flobernd/actions/dotnet/nuget-push@master
with:
packages: ./nupkg/*.nupkg
packages: ${{ format('{0}/*.nupkg', env.ARTIFACTS_PATH) }}
nuget-source: ${{ matrix.feed.source }}
nuget-api-key: ${{ secrets[matrix.feed.key] }}
120 changes: 70 additions & 50 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ name: CI
on:
workflow_call:
inputs:
directory:
description: >
The directory in which a Visual Studio Solution file is to be searched for.
Do not add a trailing slash.
path:
description: The path where to look for a Visual Studio Solution file (without a trailing slash).
type: string
required: false
default: ''
Expand All @@ -16,57 +14,73 @@ on:

env:
BUILD_CONFIG: Debug
DOTNET_GLOBAL_JSON: ${{ inputs.path != '' && format('{0}/global.json', inputs.path) || 'global.json' }}
RESTORE_PATTERN: ${{ inputs.path != '' && format('{0}/**/packages.lock.json', inputs.path) || '**/packages.lock.json' }}
TESTS_PATTERN: ${{ inputs.path != '' && format('{0}/**/*.Test*.csproj', inputs.path) || '**/*.Test*.csproj' }}

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: .NET Setup (SDK 8)
uses: zyactions/dotnet-setup@v1
with:
dotnet-version: '8.x.x'

- name: Install latest .NET Format tool
shell: bash
run: |
dotnet tool install -g dotnet-format --version "8.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json

- name: Checkout
uses: actions/checkout@v3.1.0
uses: actions/checkout@v3
with:
# Retrieve the preceding commit to enable 'changed-files' to create a diff.
fetch-depth: 2

- name: Get Changed Files
id: changed-files
uses: tj-actions/changed-files@932dad31974f07bd23cab5870d45c6e5ad5c8b73
# TODO: This step should honor the directory input

- name: Find Solution
id: find
uses: flobernd/actions/dotnet/find-solution@master
uses: tj-actions/changed-files@f569b77fb1d9ad9f1a125757d7e9e07b1f320199
with:
directory: ${{ inputs.directory }}
files: ${{ inputs.path != '' && format('{0}/**', inputs.path) || '' }}

- name: .NET Setup
uses: flobernd/actions/dotnet/setup@master
uses: zyactions/dotnet-setup@v1
with:
# Use version defined in 'global.json'
dotnet-version: ''
disable-problem-matcher: true
global-json-file: ${{ env.DOTNET_GLOBAL_JSON }}
problem-matcher: false

- name: .NET Cache Packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles(env.RESTORE_PATTERN) }}
restore-keys: ${{ runner.os }}-nuget-

- name: .NET Restore
uses: flobernd/actions/dotnet/restore@master
uses: zyactions/dotnet-restore@v1
with:
workspace: ${{ steps.find.outputs.solution }}
cache-key: ${{ hashFiles('**/packages.lock.json') }}
working-directory: ${{ inputs.path }}

# TODO: Add additional generic '.editorconfig' linting, e.g. for `*.csproj` files

- name: .NET Lint
uses: flobernd/actions/dotnet/lint@master
uses: zyactions/dotnet-lint@v1
with:
workspace: ${{ steps.find.outputs.solution }}
working-directory: ${{ inputs.path }}
# This list is empty for the initial commit. NET Lint will lint all files in this case.
include: ${{ steps.changed-files.outputs.all_changed_files }}
use-standalone-tool: true

test:
name: Run Tests
runs-on: ubuntu-latest
env:
FILTERED_SOLUTION: ${{ inputs.path != '' && format('{0}/Tests.slnf', inputs.path) || 'Tests.slnf' }}
steps:
- name: Checkout
uses: actions/checkout@v3.1.0
uses: actions/checkout@v3
with:
# Required by NBGV
fetch-depth: 0
Expand All @@ -75,52 +89,55 @@ jobs:
id: find
uses: flobernd/actions/dotnet/find-solution@master
with:
directory: ${{ inputs.directory }}
directory: ${{ inputs.path }}

- name: Filter Solution
uses: flobernd/actions/dotnet/filter-solution@master
with:
solution: ${{ steps.find.outputs.solution }}
pattern: |
**/*.Test*.csproj
output: ./Tests.slnf
# TODO: This step should honor the directory input for outputting the Solution Filter
# This pattern is relative to the solution file and does not need to be prefixed with
# the 'directory' input value
pattern: '**/*.Test*.csproj'
output: ${{ env.FILTERED_SOLUTION }}

- name: .NET Setup
uses: flobernd/actions/dotnet/setup@master
uses: zyactions/dotnet-setup@v1
with:
# Use version defined in 'global.json'
dotnet-version: ''
disable-problem-matcher: true
global-json-file: ${{ env.DOTNET_GLOBAL_JSON }}
problem-matcher: false

- name: .NET Cache Packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles(env.RESTORE_PATTERN) }}
restore-keys: ${{ runner.os }}-nuget-

- name: .NET Restore
uses: flobernd/actions/dotnet/restore@master
uses: zyactions/dotnet-restore@v1
with:
workspace: ./Tests.slnf
cache-key: ${{ hashFiles('**/packages.lock.json') }}
# TODO: This step should honor the directory input for hashing
workspace: ${{ env.FILTERED_SOLUTION }}

- name: .NET Build
uses: flobernd/actions/dotnet/build@master
with:
workspace: ./Tests.slnf
workspace: ${{ env.FILTERED_SOLUTION }}
configuration: ${{ env.BUILD_CONFIG }}

- name: .NET Test
uses: flobernd/actions/dotnet/test@master
with:
projects: '**/*.Test*.csproj'
projects: ${{ env.TESTS_PATTERN }}
fail-on-error: false
log-results: true
collect-coverage: false
maxdop: 4
# TODO: This step should honor the directory input for test discovery

- name: Generate Test Report
uses: zyactions/test-reporter@main
with:
name: Test Results
path: '**/TestResults/*.trx'
path: ${{ inputs.path != '' && format('{0}/**/TestResults/*.trx', inputs.path) || '**/TestResults/*.trx' }}
reporter: dotnet-trx
fail-on-error: true
only-summary: false
Expand All @@ -131,7 +148,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.1.0
uses: actions/checkout@v3
with:
# Required by NBGV and SonarCloud scanner
fetch-depth: 0
Expand All @@ -140,21 +157,25 @@ jobs:
id: find
uses: flobernd/actions/dotnet/find-solution@master
with:
directory: ${{ inputs.directory }}
directory: ${{ inputs.path }}

- name: .NET Setup
uses: flobernd/actions/dotnet/setup@master
uses: zyactions/dotnet-setup@v1
with:
global-json-file: ${{ env.DOTNET_GLOBAL_JSON }}
problem-matcher: true

- name: .NET Cache Packages
uses: actions/cache@v3
with:
# Use version defined in 'global.json'
dotnet-version: ''
disable-problem-matcher: false
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles(env.RESTORE_PATTERN) }}
restore-keys: ${{ runner.os }}-nuget-

- name: .NET Restore
uses: flobernd/actions/dotnet/restore@master
uses: zyactions/dotnet-restore@v1
with:
workspace: ${{ steps.find.outputs.solution }}
cache-key: ${{ hashFiles('**/packages.lock.json') }}
# TODO: This step should honor the directory input for hashing

- name: SonarCloud Names
id: sonarcloud-names
Expand Down Expand Up @@ -185,11 +206,10 @@ jobs:
- name: .NET Test
uses: flobernd/actions/dotnet/test@master
with:
projects: '**/*.Test*.csproj'
projects: ${{ env.TESTS_PATTERN }}
log-results: true
collect-coverage: true
maxdop: 4
# TODO: This step should honor the directory input for test discovery

- name: SonarCloud End
uses: flobernd/actions/sonarcloud/end@master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: CI
uses: ./.github/workflows/ci.yaml
with:
directory: test
path: test
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Expand Down
Loading