Skip to content

Commit

Permalink
A bit of cleanup for consistency (#79)
Browse files Browse the repository at this point in the history
This PR includes some cleanup to make this repo consistent with my
learnings in other repos and some other trivial changes.

- Simplified common attributes and MSBuild properties and excluded
generated code from code coverage.
- Reconfigured workflows to reuse common portions.
  • Loading branch information
craigktreasure authored Nov 16, 2023
1 parent f2eed67 commit a93f99e
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 165 deletions.
15 changes: 15 additions & 0 deletions .github/actions/install-tools/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Install tools

runs:
using: "composite"
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.x
7.x
- name: Install .NET tools
shell: pwsh
run: dotnet tool restore
16 changes: 16 additions & 0 deletions .github/actions/version-vars/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Set version variables

outputs:
package_version:
description: The package version.
value: ${{ steps.version.outputs.package_version }}

runs:
using: "composite"
steps:
- name: Set version
id: version
shell: pwsh
run: |
$packageVersion = dotnet nbgv get-version --variable NuGetPackageVersion
"package_version=$packageVersion" >> $env:GITHUB_OUTPUT
108 changes: 17 additions & 91 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Treasure.Utils-CI'
name: Treasure.Utils-CI

on:
push:
Expand All @@ -11,95 +11,21 @@ on:
- 'docs/**'
- 'README.md'

env:
# Stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

jobs:
build:
name: 'Build Treasure.Utils'
runs-on: ubuntu-latest

outputs:
package_version: ${{steps.version.outputs.package_version}}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.x
7.x
- name: Patch global.json if necessary
shell: pwsh
run: ./scripts/PatchGlobalJson.ps1

- name: Set version
id: version
shell: pwsh
run: |
dotnet tool restore
$packageVersion = dotnet nbgv get-version --variable NuGetPackageVersion
"package_version=$packageVersion" >> $env:GITHUB_OUTPUT
- name: Install dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage"

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
name: codecov
directory: __test-results
fail_ci_if_error: true
verbose: true

- name: Upload output artifact
uses: actions/upload-artifact@v3
with:
name: __output
path: __output

- name: Upload package artifact
uses: actions/upload-artifact@v3
with:
name: __packages
path: __packages

release_nuget:
name: 'Release Treasure.Utils to NuGet.org'
runs-on: ubuntu-latest
needs: build
environment:
name: NuGet.org
url: https://www.nuget.org

env:
PACKAGE_VERSION: ${{ needs.build.outputs.package_version }}

build_ci:
name: Build Treasure.Utils
if: "!contains(github.event.head_commit.message, 'ci skip')"
uses: ./.github/workflows/workflow_build.yml
secrets: inherit
with:
# don't check format on CI builds due to common breaking changes in the .NET SDK
checkFormat: false

release_ci:
name: Release Treasure.Utils to NuGet.org
needs: build_ci
if: ${{ contains(github.event.head_commit.message, 'do release') }}

steps:
- name: Setup NuGet
uses: NuGet/setup-nuget@v1
with:
nuget-version: latest

- name: Download __packages
uses: actions/download-artifact@v3
with:
name: __packages
path: __packages

- name: Push ${{ env.PACKAGE_VERSION }} to NuGet.org
run: nuget push __packages/NuGet/Release/Treasure.Utils.*.nupkg -ApiKey ${{ secrets.NUGET_API_KEY }} -Source https://api.nuget.org/v3/index.json
uses: ./.github/workflows/workflow_release.yml
secrets: inherit
with:
package-version: ${{ needs.build_ci.outputs.package_version }}
63 changes: 7 additions & 56 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,16 @@
name: 'Treasure.Utils-PR'
name: Treasure.Utils-PR

on: pull_request

env:
# Stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

jobs:
build:
name: 'Build Treasure.Utils'
build_pr:
name: Build Treasure.Utils
strategy:
max-parallel: 3
fail-fast: false
matrix:
platform: [ windows, ubuntu, macos ]
runs-on: ${{ matrix.platform }}-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: |
6.x
7.x
- name: Patch global.json if necessary
shell: pwsh
run: ./scripts/PatchGlobalJson.ps1

- name: Install dependencies
run: dotnet restore

- name: DotNet Format
run: dotnet format --no-restore --verify-no-changes

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal --collect:"XPlat Code Coverage"

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
name: codecov-${{ matrix.platform }}
directory: __test-results
fail_ci_if_error: true
verbose: true

- name: Upload output artifact
uses: actions/upload-artifact@v3
with:
name: __output_${{ matrix.platform }}
path: __output

- name: Upload packages artifact
uses: actions/upload-artifact@v3
with:
name: __packages_${{ matrix.platform }}
path: __packages
uses: ./.github/workflows/workflow_build.yml
secrets: inherit
with:
platform: ${{ matrix.platform }}
72 changes: 72 additions & 0 deletions .github/workflows/workflow_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Build Workflow

on:
workflow_call:
inputs:
checkFormat:
type: boolean
default: true
platform:
type: string
default: ubuntu
outputs:
package_version:
description: 'The version of the package that was built.'
value: ${{ jobs.build.outputs.package_version }}

env:
# Stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

jobs:
build:
name: Build
runs-on: ${{ inputs.platform }}-latest

outputs:
package_version: ${{steps.version.outputs.package_version}}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install tools
uses: ./.github/actions/install-tools

- name: Set version variables
id: version
uses: ./.github/actions/version-vars

- name: Restore
run: dotnet restore

- name: Format validation
if: ${{ inputs.checkFormat }}
run: dotnet format --no-restore --verify-no-changes

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal /p:CollectCoverage=true

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
name: codecov
directory: __test-results
fail_ci_if_error: true
verbose: true

- name: Upload output artifact
uses: actions/upload-artifact@v3
with:
name: output_${{ inputs.platform }}
path: __output

- name: Upload package artifact
uses: actions/upload-artifact@v3
with:
name: packages_${{ inputs.platform }}
path: __packages
31 changes: 31 additions & 0 deletions .github/workflows/workflow_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release Workflow

on:
workflow_call:
inputs:
package-version:
type: string
required: true

jobs:
release:
name: Release
runs-on: ubuntu-latest
environment:
name: NuGet.org
url: https://www.nuget.org

steps:
- name: Setup NuGet
uses: NuGet/setup-nuget@v1
with:
nuget-version: latest

- name: Download packages artifact
uses: actions/download-artifact@v3
with:
name: packages_ubuntu
path: __packages

- name: Push ${{ inputs.package-version }} to NuGet.org
run: nuget push __packages/NuGet/Release/Treasure.Utils.*.nupkg -ApiKey ${{ secrets.NUGET_API_KEY }} -Source https://api.nuget.org/v3/index.json
21 changes: 14 additions & 7 deletions Treasure.Utils.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitattributes = .gitattributes
.gitignore = .gitignore
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
Directory.Build.rsp = Directory.Build.rsp
Directory.Packages.props = Directory.Packages.props
global.json = global.json
nuget.config = nuget.config
Packages.props = Packages.props
version.json = version.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{FDF5F72E-0C98-4976-8125-12C0ED9F89B4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Treasure.Utils.Argument.Benchmarks", "test\Treasure.Utils.Argument.Benchmarks\Treasure.Utils.Argument.Benchmarks.csproj", "{AB3B36BF-791F-4DC2-8B53-4BA812A80E86}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7C628D75-6B6A-4D42-A4D9-45C6ACA51FB5}"
ProjectSection(SolutionItems) = preProject
build\Defaults.props = build\Defaults.props
build\Defaults.targets = build\Defaults.targets
src\Directory.Packages.props = src\Directory.Packages.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Treasure.Utils.Argument.Benchmarks", "test\Treasure.Utils.Argument.Benchmarks\Treasure.Utils.Argument.Benchmarks.csproj", "{AB3B36BF-791F-4DC2-8B53-4BA812A80E86}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{61D20241-7C98-4A60-AA8D-C7614B7D6768}"
ProjectSection(SolutionItems) = preProject
test\.editorconfig = test\.editorconfig
test\Directory.Build.props = test\Directory.Build.props
test\Directory.Packages.props = test\Directory.Packages.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -54,8 +60,9 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{EF141707-718F-49EC-99B9-8D7B59CBCCEF} = {B012001D-4B86-460D-A3E1-FC3EEC840D13}
{FDF5F72E-0C98-4976-8125-12C0ED9F89B4} = {A18B8F8E-8296-4968-A569-16F3F4FE045E}
{AB3B36BF-791F-4DC2-8B53-4BA812A80E86} = {B012001D-4B86-460D-A3E1-FC3EEC840D13}
{7C628D75-6B6A-4D42-A4D9-45C6ACA51FB5} = {A18B8F8E-8296-4968-A569-16F3F4FE045E}
{61D20241-7C98-4A60-AA8D-C7614B7D6768} = {A18B8F8E-8296-4968-A569-16F3F4FE045E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1304A800-AFA8-4EDF-9EBC-06F8680BADF1}
Expand Down
9 changes: 0 additions & 9 deletions scripts/PatchGlobalJson.ps1

This file was deleted.

Loading

0 comments on commit a93f99e

Please sign in to comment.