Skip to content

Commit ce04c95

Browse files
Configure GitHub Actions
1 parent 84417c7 commit ce04c95

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

.github/workflows/build.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: build-CI
2+
3+
on:
4+
create:
5+
branches:
6+
- feature/**
7+
push:
8+
branches:
9+
- ace
10+
- main
11+
- develop
12+
- feature/**
13+
- bugfix/**
14+
15+
jobs:
16+
build:
17+
18+
env:
19+
CONFIG: 'Release'
20+
SOLUTION: 'src/Ace.CSharp.StructuredAutoMapper.sln'
21+
TEST_PROJECT: 'src\sample\Ace.CSharp.StructuredAutoMapper.Sample.Tests/Ace.CSharp.StructuredAutoMapper.Sample.Tests.csproj'
22+
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
29+
- name: Setup .NET
30+
uses: actions/setup-dotnet@v2
31+
with:
32+
dotnet-version: 6.0.x
33+
34+
- name: dotnet restore
35+
run: dotnet restore $SOLUTION
36+
37+
- name: dotnet build
38+
run: dotnet build $SOLUTION --configuration $CONFIG --no-restore
39+
40+
- name: dotnet test
41+
run: dotnet test $TEST_PROJECT --configuration $CONFIG --no-restore --no-build --verbosity normal

.github/workflows/release.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: release-CI
2+
3+
on:
4+
create:
5+
branches:
6+
- release/**
7+
push:
8+
branches:
9+
- ace
10+
- main
11+
12+
jobs:
13+
build:
14+
15+
env:
16+
CONFIG: 'Release'
17+
SOLUTION: 'src/Ace.CSharp.StructuredAutoMapper.sln'
18+
TEST_PROJECT: 'src\sample\Ace.CSharp.StructuredAutoMapper.Sample.Tests/Ace.CSharp.StructuredAutoMapper.Sample.Tests.csproj'
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
26+
- name: Get build version
27+
run: |
28+
Import-Module .\build\GetBuildVersion.psm1
29+
Write-Host $Env:GITHUB_REF
30+
$version = GetBuildVersion -VersionString $Env:GITHUB_REF
31+
echo "BUILD_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
32+
shell: pwsh
33+
34+
- name: Setup .NET
35+
uses: actions/setup-dotnet@v2
36+
with:
37+
dotnet-version: 6.0.x
38+
39+
- name: dotnet restore
40+
run: dotnet restore $SOLUTION
41+
42+
- name: dotnet build
43+
run: dotnet build $SOLUTION --configuration $CONFIG -p:Version=$BUILD_VERSION --no-restore
44+
45+
- name: dotnet test
46+
run: dotnet test $TEST_PROJECT --configuration $CONFIG --no-restore --no-build --verbosity normal
47+
48+
- name: dotnet nuget push
49+
if: startsWith(github.ref, 'refs/heads/release')
50+
run: dotnet nuget push **\*.nupkg -s 'https://api.nuget.org/v3/index.json' -k ${{secrets.NUGETSECRET}}

build/GetBuildVersion.psm1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Function GetBuildVersion {
2+
Param (
3+
[string]$VersionString
4+
)
5+
6+
$VersionString -match "(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(\-(?<pre>[0-9A-Za-z\-\.]+))?(\+(?<build>\d+))?" | Out-Null
7+
if ($matches -eq $null) {
8+
return "1.0.0-build"
9+
}
10+
11+
$Major = [uint64]$matches['major']
12+
$Minor = [uint64]$matches['minor']
13+
$Patch = [uint64]$matches['patch']
14+
15+
$PreReleaseTag = [string]$matches['pre']
16+
$BuildRevision = [uint64]$matches['build']
17+
18+
$Version = [string]$Major + '.' + [string]$Minor + '.' + [string]$Patch;
19+
20+
if ($PreReleaseTag -ne [string]::Empty) {
21+
$Version = $Version + '-' + $PreReleaseTag
22+
}
23+
24+
if ($BuildRevision -ne 0) {
25+
$Version = $Version + '.' + [string]$BuildRevision
26+
}
27+
28+
return $Version
29+
}

0 commit comments

Comments
 (0)