Skip to content

Commit

Permalink
added push yml (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Hegedus <jhegedus9@gmail.com>
  • Loading branch information
joshika39 and Joshua Hegedus committed Apr 12, 2023
1 parent f004e4c commit 7f31e4b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CD

on:
push:
branches:
- release/**
pull_request:
branches:
- release/**

jobs:
build:

env:
BUILD_CONFIG: 'Release'
SOLUTION: './Solution/Modules.sln'

runs-on: windows-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get Build Version
run: |
Import-Module .\Tools\GetBuildVersion.psm1
Write-Host $env:GITHUB_REF
$version = GetBuildVersion -VersionString $env:GITHUB_REF
echo "BUILD_VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf-8 -Append
shell: pwsh

- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 5.0.x

- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.0.2

- name: Setup NuGet
uses: NuGet/setup-nuget@v1.0.5

- name: Restore dependencies
run: nuget restore $env:SOLUTION

- name: Build
run: dotnet build $env:SOLUTION --configuration $env:BUILD_CONFIG -p:Version=$env:$BUILD_VERSION --no-restore

- name: Run tests
run: dotnet test $env:SOLUTION /p:Configuration=$env:BUILD_CONFIG --no-restore --no-build --verbosity normal

- name: Publish
if: startsWith(github.ref, 'refs/heads/release')
run: |
nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}}
nuget push **\*.nupkg -Source 'https://nuget.pkg.github.com/joshika39/index.json' --api-key ${{secrets.GIT_API_KEY}}
34 changes: 34 additions & 0 deletions Solution/Tools/GetBuildVersion.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Function GetBuildVersion {
Param (
[string]$VersionString
)

# Process through regex
$VersionString -match "(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(\-(?<pre>[0-9A-Za-z\-\.]+))?(\+(?<build>\d+))?" | Out-Null

if ($matches -eq $null) {
return "1.0.0-build"
}

# Extract the build metadata
$BuildRevision = [uint64]$matches['build']
# Extract the pre-release tag
$PreReleaseTag = [string]$matches['pre']
# Extract the patch
$Patch = [uint64]$matches['patch']
# Extract the minor
$Minor = [uint64]$matches['minor']
# Extract the major
$Major = [uint64]$matches['major']

$Version = [string]$Major + '.' + [string]$Minor + '.' + [string]$Patch;
if ($PreReleaseTag -ne [string]::Empty) {
$Version = $Version + '-' + $PreReleaseTag
}

if ($BuildRevision -ne 0) {
$Version = $Version + '.' + [string]$BuildRevision
}

return $Version
}

0 comments on commit 7f31e4b

Please sign in to comment.