Skip to content

Commit

Permalink
A bit of cleanup for consistency (#235)
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.

- Code formatting, spelling, and style changes (pattern matching).
- Simplified a switch expression to remove a warning suppression.
- Now adding the `GeneratedCodeAttribute` attribute to the generated VS
versions file.
  - Updated VS versions as a result.
- Added some tests to increase branch coverage.
- Added the
[Microsoft.Build.CopyOnWrite](https://github.com/microsoft/MSBuildSdks/tree/main/src/CopyOnWrite)
package to speed up MSBuild file copies on certain file systems.
- 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 11, 2023
1 parent 1150aa6 commit 4b4358a
Show file tree
Hide file tree
Showing 25 changed files with 360 additions and 215 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
110 changes: 17 additions & 93 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'SlnUp-CI'
name: SlnUp-CI

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

env:
# Stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

jobs:
build:
name: 'Build SlnUp'
runs-on: ubuntu-latest

build_ci:
name: Build SlnUp
if: "!contains(github.event.head_commit.message, 'ci skip')"

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 SlnUp to NuGet.org'
runs-on: ubuntu-latest
needs: build
environment:
name: NuGet.org
url: https://www.nuget.org/packages/SlnUp/

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

if: ${{ !contains(needs.build.outputs.package_version, '-') }}

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/SlnUp.*.nupkg -ApiKey ${{ secrets.NUGET_API_KEY }} -Source https://api.nuget.org/v3/index.json
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 SlnUp to NuGet.org
needs: build_ci
if: ${{ !contains(needs.build_ci.outputs.package_version, '-') }}
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: 'SlnUp-PR'
name: SlnUp-PR

on: pull_request

env:
# Stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

jobs:
build:
name: 'Build SlnUp'
build_pr:
name: Build SlnUp
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/packages/SlnUp/

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/SlnUp.*.nupkg -ApiKey ${{ secrets.NUGET_API_KEY }} -Source https://api.nuget.org/v3/index.json
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
https://learn.microsoft.com/nuget/consume-packages/central-package-management#global-package-references
-->
<ItemGroup>
<GlobalPackageReference Include="Microsoft.Build.CopyOnWrite" Version="1.0.282" />
<GlobalPackageReference Include="Treasure.Analyzers.MemberOrder" Version="0.3.2" />
</ItemGroup>

Expand Down
19 changes: 14 additions & 5 deletions slnup.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ 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.Packages.props = Directory.Packages.props
global.json = global.json
nuget.config = nuget.config
Packages.props = Packages.props
README.md = README.md
version.json = version.json
EndProjectSection
Expand All @@ -33,14 +32,23 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnUp.Core.Tests", "tests\S
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnUp.TestLibrary", "tests\SlnUp.TestLibrary\SlnUp.TestLibrary.csproj", "{CB0DCF5C-167B-42AC-BF07-97FDAA739B27}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{55C166C6-AA31-4FC2-AE0B-1A2C08803AEC}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{55C166C6-AA31-4FC2-AE0B-1A2C08803AEC}"
ProjectSection(SolutionItems) = preProject
tests\.editorconfig = tests\.editorconfig
tests\Directory.Build.props = tests\Directory.Build.props
tests\Directory.Packages.props = tests\Directory.Packages.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnUp.Json", "src\SlnUp.Json\SlnUp.Json.csproj", "{E36BA407-6D12-440A-8286-B1C718CF15B3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnUp.Json", "src\SlnUp.Json\SlnUp.Json.csproj", "{E36BA407-6D12-440A-8286-B1C718CF15B3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnUp.Json.Tests", "tests\SlnUp.Json.Tests\SlnUp.Json.Tests.csproj", "{80A1C405-1105-4E88-96FF-877D8F9F0495}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlnUp.Json.Tests", "tests\SlnUp.Json.Tests\SlnUp.Json.Tests.csproj", "{80A1C405-1105-4E88-96FF-877D8F9F0495}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5E4596F4-E635-4A0C-BCB7-14A031D375CE}"
ProjectSection(SolutionItems) = preProject
src\.editorconfig = src\.editorconfig
src\Directory.Build.props = src\Directory.Build.props
src\Directory.Packages.props = src\Directory.Packages.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -91,6 +99,7 @@ Global
{CB0DCF5C-167B-42AC-BF07-97FDAA739B27} = {E392EF9F-8A64-4B8D-AC44-6E760ED65348}
{55C166C6-AA31-4FC2-AE0B-1A2C08803AEC} = {05A480CD-9D37-4CC7-8B9B-8418B6B413AA}
{80A1C405-1105-4E88-96FF-877D8F9F0495} = {E392EF9F-8A64-4B8D-AC44-6E760ED65348}
{5E4596F4-E635-4A0C-BCB7-14A031D375CE} = {05A480CD-9D37-4CC7-8B9B-8418B6B413AA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {077C9799-D020-472A-A37B-BCDDD2AF3641}
Expand Down
7 changes: 7 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildThisFileDirectory)/../Directory.Build.props" />

<ItemGroup>
<InternalsVisibleTo Include="$(AssemblyName).Tests" />
</ItemGroup>
</Project>
Loading

0 comments on commit 4b4358a

Please sign in to comment.