From ec5966c80d1c8c8cdc1885ed423e75816bbe6fa1 Mon Sep 17 00:00:00 2001 From: gbakeman Date: Sun, 28 Apr 2024 16:37:34 -0400 Subject: [PATCH] Moving workflows over to dotnet build system - Removing msbuild helper action - Disable debug build from running during a release - Added semver extractor (ignore the v character) - Ensured metadata is correct with currently published NuGet package - Automatic NuGet package publishing for (pre)releases - Create a draft GitHub release --- .github/actions/msbuild-helper/action.yaml | 60 ---------------- .github/get-ver.ps1 | 22 ++++++ .github/workflows/build-debug.yaml | 31 ++++----- .github/workflows/build-release.yaml | 81 ++++++++++------------ AGauge/AGauge.csproj | 2 +- AGauge/AGauge.nuspec | 4 +- 6 files changed, 76 insertions(+), 124 deletions(-) delete mode 100644 .github/actions/msbuild-helper/action.yaml create mode 100644 .github/get-ver.ps1 diff --git a/.github/actions/msbuild-helper/action.yaml b/.github/actions/msbuild-helper/action.yaml deleted file mode 100644 index 83c9715..0000000 --- a/.github/actions/msbuild-helper/action.yaml +++ /dev/null @@ -1,60 +0,0 @@ -# https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-reference -# Requires Windows Server runner - -name: "MSBuild-Helper" -description: "Execute Visual Studio's MSBuild system on a Project or Solution with desired settings." - -branding: - icon: "loader" - color: "green" - -inputs: - directory: - description: "Full path where MSBuild should look for Project (or Solution) definition file, default to current working dir." - required: false - default: "" - - build-config: - description: "Solution configuration to use when building." - required: true - - # https://andrewlock.net/version-vs-versionsuffix-vs-packageversion-what-do-they-all-mean/#version - version: - description: "Version string to pass to MSBuild. Ex. 0.1.0, 1.2.3.5, 99.0.3-rc-preview-2-final" - required: false - - verbosity: - description: "Modify the verbosity of MSBuild. Options: q[uiet], m[inimal], n[ormal] (default), d[etailed], and diag[nostic]." - required: false - default: "normal" - -outputs: - buildOutputDir: - description: "Final directory of Project or Solution output(s)." - value: ${{ steps.vars.outputs.BUILD_OUTPUT_DIR }} - - logFile: - description: "Location of the MSBuild log file." - value: "msbuild.log" - -runs: - using: "composite" - steps: - # Need to define "global" variables for this script. See https://github.com/orgs/community/discussions/51280#discussioncomment-8726096 - - name: Set variables - id: vars - shell: pwsh - run: | - echo "BUILD_OUTPUT_DIR=${{ runner.temp }}\msbuild-out" >> $env:GITHUB_OUTPUT - - - name: Setup MSBuild - uses: microsoft/setup-msbuild@v2 - - - name: Build Solution - id: build - shell: pwsh - run: > - msbuild ${{ inputs.directory }} -nologo -fileLogger -verbosity:${{ inputs.verbosity }} - -property:Configuration=${{ inputs.build-config }} - -property:AssemblyVersion=1.2.3.4 - -property:OutDir=${{ steps.vars.outputs.BUILD_OUTPUT_DIR }} \ No newline at end of file diff --git a/.github/get-ver.ps1 b/.github/get-ver.ps1 new file mode 100644 index 0000000..5b28b0e --- /dev/null +++ b/.github/get-ver.ps1 @@ -0,0 +1,22 @@ +# Verify valid semver from Ref string, and provide it along with an AssemblyVersion-compatible string as outputs. + +# Set to the value provided by github.ref +param([string]$ghRef) + +$semVerRegex = "(?0|[1-9]\d*)\.(?0|[1-9]\d*)\.(?0|[1-9]\d*)(?:-(?(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$" +$matchInfo = [regex]::Match($ghRef, $semVerRegex) + +if (!($matchInfo.Success)) { + Write-Host "Could not find valid semver within ref. string. Given: $ghRef" + Exit 1 +} + +$verRes = "ASMVER={0}.{1}.{2}" -f $matchInfo.Groups["major"], $matchInfo.Groups["minor"], $matchInfo.Groups["patch"] +$semVerRes = "SEMVER=" + $matchInfo.Value +$isPr = "ISPRERELEASE=" + $matchInfo.Groups.ContainsKey("prerelease") + +echo $verRes >> $env:GITHUB_OUTPUT +echo $semVerRes >> $env:GITHUB_OUTPUT +echo $isPr >> $env:GITHUB_OUTPUT + +Write-Host "Result: $verRes, $semVerRes, $isPr" \ No newline at end of file diff --git a/.github/workflows/build-debug.yaml b/.github/workflows/build-debug.yaml index 8a0bc7a..9f00900 100644 --- a/.github/workflows/build-debug.yaml +++ b/.github/workflows/build-debug.yaml @@ -3,11 +3,15 @@ name: build-debug on: workflow_dispatch: + # Cause GH to build only for modified code files in a PR, but not when a tag is specified (https://stackoverflow.com/a/71879890/530172) pull_request: paths: - "**.cs" - "**.csproj" +env: + PRIMARY_FOLDER: AGauge + jobs: build-debug: runs-on: windows-latest @@ -15,26 +19,19 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Run MSBuild - id: msbuild - uses: ./.github/actions/msbuild-helper - with: - directory: "AGauge\\AGauge.csproj" - build-config: "Debug" - version: ${{ vars.VER_RELEASE }}.* + - name: Setup dotnet + uses: actions/setup-dotnet@v4 - - name: Get AssemblyVersion generated by msbuild - id: getversion - uses: berglie/assembly-version/get@v1 - with: - directory: ${{ steps.msbuild.outputs.buildOutputDir }} + - name: Build Project + run: > + dotnet build ${{ env.PRIMARY_FOLDER }}\AGauge.csproj + --nologo + -c Debug + -p:Version=1.0.0.0 - name: Upload Artifact uses: actions/upload-artifact@v4 with: - name: AGauge-Debug-v${{ steps.getversion.outputs.version }} - path: | - ${{ steps.msbuild.outputs.buildOutputDir }} - ${{ steps.msbuild.outputs.logFile }} - + name: AGauge-Debug-CIBuild_${{ github.run_number }} + path: ${{ env.PRIMARY_FOLDER }}\bin\Debug if-no-files-found: error diff --git a/.github/workflows/build-release.yaml b/.github/workflows/build-release.yaml index d42b8ae..5fc34c7 100644 --- a/.github/workflows/build-release.yaml +++ b/.github/workflows/build-release.yaml @@ -1,60 +1,53 @@ -# name: build-release-$(git rev-parse --short "$GITHUB_SHA") -run-name: Build-Release Num. ${{ github.run_number }} +name: build-release on: - workflow_dispatch: - # inputs: - # configuration: - # description: 'Compiler configuration preset' - # required: false - # default: 'Debug' - # pull_request: - # branches: [ main ] - # paths: - # - '**.vb' - # - '**.vbproj' - # - '**.cs' - # - '**.csproj' - # - '**.resx' + push: + tags: "v*" + branches: "main" env: - DOTNET_VERSION: '4.7.2' # The .NET SDK version to use - SLN_FILE: AGauge/AGauge.sln - OUTPUT: AGauge/bin/Release - CONFIG: Release + PRIMARY_FOLDER: AGauge + NUGET_API_URL: https://api.nuget.org/v3/index.json jobs: build: - - name: debug-build-${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [windows-latest] # Should have MSBuild. + runs-on: windows-latest steps: - # Make MSBuild available from $PATH. - - name: setup-msbuild - uses: microsoft/setup-msbuild@v1 + - name: Checkout code + uses: actions/checkout@v4 - - name: Checkout Code - uses: actions/checkout@v3 + - name: Extract version info + id: exVer + run: .\.github\get-ver.ps1 ${{ github.ref }} - # - name: Restore Packages - # run: msbuild -t:restore + - name: Setup dotnet + uses: actions/setup-dotnet@v4 - - name: Build solution - run: msbuild $env:SLN_FILE -p:Configuration=$env:CONFIG + - name: Build Project + run: > + dotnet build ${{ env.PRIMARY_FOLDER }}\AGauge.csproj + --nologo + -c Release + -p:Version=${{ steps.exVer.outputs.ASMVER }} + -p:PackageVersion=${{ steps.exVer.outputs.SEMVER }} - - name: Get AssemblyVersion generated by msbuild - id: getversion - uses: berglie/assembly-version/get@v1 - with: - directory: ${{ env.OUTPUT }} + - name: Push to NuGet + run: > + dotnet nuget push + ${{ env.PRIMARY_FOLDER }}\bin\Release\*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source ${{ env.NUGET_API_URL }} - name: Upload Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: ${{ format('AGauge-v{0}', steps.getversion.outputs.version) }} + name: AGauge-Release-CIBuild_${{ github.run_number }} + path: ${{ env.PRIMARY_FOLDER }}\bin\Release if-no-files-found: error - path: ${{ env.OUTPUT }} - \ No newline at end of file + + - name: Create GH Release + uses: softprops/action-gh-release@v2 + with: + draft: true + prerelease: ${{ steps.exVer.outputs.ISPRERELEASE }} + files: ${{ env.PRIMARY_FOLDER }}/bin/Release/* + fail_on_unmatched_files: true + generate_release_notes: true \ No newline at end of file diff --git a/AGauge/AGauge.csproj b/AGauge/AGauge.csproj index 037cc2e..3ebfe87 100644 --- a/AGauge/AGauge.csproj +++ b/AGauge/AGauge.csproj @@ -30,7 +30,6 @@ - AGauge Classic Customizable WinForms gauge control - maintained by the NUTDotNet organization. A. J. Bauer, with further work by Code Artist and others. @@ -45,5 +44,6 @@ LICENSE True snupkg + AGauge.Classic \ No newline at end of file diff --git a/AGauge/AGauge.nuspec b/AGauge/AGauge.nuspec index ad29dc1..87ed901 100644 --- a/AGauge/AGauge.nuspec +++ b/AGauge/AGauge.nuspec @@ -3,12 +3,12 @@ $id$ - 2.0.5-prerelease.1 + $version$ $description$ $author$ - docs\README.md + docs\README.md false MIT