Skip to content

Commit

Permalink
chore(workflow): Add CI/CD workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
PerfectlyNormal committed Sep 2, 2023
1 parent 4145959 commit e31b85b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI

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

jobs:
build:

env:
BUILD_CONFIG: 'Release'
SOLUTION: 'TypeContractor.sln'

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Get Build Version
run: |
Import-Module .\build\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: Setup NuGet
uses: NuGet/setup-nuget@v1
with:
nuget-api-key: ${{secrets.NUGET_API_KEY}}

- name: Restore dependencies
run: nuget restore $SOLUTION

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x

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

- name: Run tests
run: dotnet test /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}}
8 changes: 6 additions & 2 deletions TypeContractor.Tool/TypeContractor.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
<Nullable>enable</Nullable>

<PackAsTool>true</PackAsTool>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>TypeContractor</PackageId>
<Authors>Hogia HR Systems</Authors>
<Description>Provide TypeContractor as .NET tool</Description>
<Authors>Per Christian B. Viken</Authors>
<Description>
Provides a dotnet tool for generating TypeScript
definitions from an ASP.NET Core API.
</Description>
<PackageTags>dotnet-tool TypeContractor TypeScript generator</PackageTags>
<ToolCommandName>typecontractor</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
Expand Down
34 changes: 34 additions & 0 deletions build/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 e31b85b

Please sign in to comment.