Skip to content

Commit

Permalink
Moving workflows over to dotnet build system
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
gbakeman committed May 1, 2024
1 parent f41aff6 commit ec5966c
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 124 deletions.
60 changes: 0 additions & 60 deletions .github/actions/msbuild-helper/action.yaml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/get-ver.ps1
Original file line number Diff line number Diff line change
@@ -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 = "(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[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"
31 changes: 14 additions & 17 deletions .github/workflows/build-debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,35 @@ 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
steps:
- 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
81 changes: 37 additions & 44 deletions .github/workflows/build-release.yaml
Original file line number Diff line number Diff line change
@@ -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 }}


- 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
2 changes: 1 addition & 1 deletion AGauge/AGauge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
</None>
</ItemGroup>
<PropertyGroup>
<Title>AGauge Classic</Title>
<Description>Customizable WinForms gauge control - maintained by the NUTDotNet organization.</Description>
<Authors>A. J. Bauer, with further work by Code Artist and others.</Authors>
<Version />
Expand All @@ -45,5 +44,6 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageId>AGauge.Classic</PackageId>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions AGauge/AGauge.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<metadata>
<!-- Required elements-->
<id>$id$</id>
<version>2.0.5-prerelease.1</version>
<version>$version$</version>
<description>$description$</description>
<authors>$author$</authors>
<readme>docs\README.md</readme>

<!-- Optional elements -->
<readme>docs\README.md</readme>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<!-- <icon>AGauge.bmp</icon> -->
Expand Down

0 comments on commit ec5966c

Please sign in to comment.