chore: initial commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
name: CI
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
jobs:
|
||||
ci:
|
||||
name: Build, Format, and Test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
- name: Build
|
||||
run: dotnet build --no-restore
|
||||
- name: Check formatting
|
||||
run: dotnet format --verify-no-changes
|
||||
- name: Run tests
|
||||
run: dotnet test --no-build --verbosity normal
|
||||
@@ -0,0 +1,122 @@
|
||||
name: Release
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
jobs:
|
||||
release:
|
||||
name: Version, Build, and Release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
- name: Determine version
|
||||
id: version
|
||||
run: |
|
||||
$commits = git log main..HEAD --format="%s"
|
||||
$commitList = $commits -split "`n"
|
||||
$major = 0
|
||||
$minor = 0
|
||||
$patch = 0
|
||||
|
||||
foreach ($message in $commitList) {
|
||||
if ($message -match " BREAKING CHANGE|!:") {
|
||||
$major = 1
|
||||
} elseif ($message -match "^feat(\(.*\))?:") {
|
||||
$minor = 1
|
||||
} elseif ($message -match "^fix(\(.*\))?:") {
|
||||
$patch = 1
|
||||
}
|
||||
}
|
||||
|
||||
if ($major -eq 1) {
|
||||
$minor = 0
|
||||
$patch = 0
|
||||
} elseif ($minor -eq 1) {
|
||||
$patch = 0
|
||||
} elseif ($patch -eq 0 -and $commitList.Count -gt 0 -and $commitList[0]) {
|
||||
$patch = 1
|
||||
}
|
||||
|
||||
$currentVersion = "0.0.0"
|
||||
$tag = git describe --tags --abbrev=0 2>$null
|
||||
|
||||
$hasExistingTag = $false
|
||||
if ($tag) {
|
||||
$hasExistingTag = $true
|
||||
$currentVersion = $tag -replace "^v", ""
|
||||
}
|
||||
|
||||
$parts = $currentVersion.Split(".")
|
||||
$majorCurrent = [int]$parts[0]
|
||||
$minorCurrent = [int]$parts[1]
|
||||
$patchCurrent = [int]$parts[2]
|
||||
|
||||
$majorNew = $majorCurrent + $major
|
||||
$minorNew = if ($major -eq 1) { 0 } else { $minorCurrent + $minor }
|
||||
$patchNew = if ($major -eq 1 -or $minor -eq 1) { 0 } else { $patchCurrent + $patch }
|
||||
|
||||
if ($majorNew -eq $majorCurrent -and $minorNew -eq $minorCurrent -and $patchNew -eq $patchCurrent) {
|
||||
if (-not $hasExistingTag) {
|
||||
$version = "0.0.0"
|
||||
echo "VERSION=$version" >> $env:GITHUB_OUTPUT
|
||||
Write-Host "First release: publishing version 0.0.0"
|
||||
} else {
|
||||
Write-Host "No version bump needed, skipping release"
|
||||
exit 0
|
||||
}
|
||||
} else {
|
||||
$version = "$majorNew.$minorNew.$patchNew"
|
||||
echo "VERSION=$version" >> $env:GITHUB_OUTPUT
|
||||
}
|
||||
shell: pwsh
|
||||
- name: Update version in csproj
|
||||
if: steps.version.outputs.VERSION
|
||||
run: |
|
||||
$version = "${{ steps.version.outputs.VERSION }}"
|
||||
$csprojPath = "src/StevanFreeborn.Results/StevanFreeborn.Results.csproj"
|
||||
$content = Get-Content $csprojPath -Raw
|
||||
|
||||
if ($content -match "<Version>.*?</Version>") {
|
||||
$content = $content -replace "<Version>.*?</Version>", "<Version>$version</Version>"
|
||||
} elseif ($content -match "<PropertyGroup>") {
|
||||
$content = $content -replace "<PropertyGroup>", "<PropertyGroup>`n <Version>$version</Version>"
|
||||
}
|
||||
|
||||
Set-Content -Path $csprojPath -Value $content
|
||||
- name: Create commit
|
||||
if: steps.version.outputs.VERSION
|
||||
run: |
|
||||
git config user.name "gitea-actions[bot]"
|
||||
git config user.email "gitea-actions[bot]@users.noreply.gitea.io"
|
||||
git add -A
|
||||
git commit -m "Bump version to ${{ steps.version.outputs.VERSION }}" || echo "No changes to commit"
|
||||
- name: Create tag
|
||||
if: steps.version.outputs.VERSION
|
||||
run: |
|
||||
git tag "v${{ steps.version.outputs.VERSION }}"
|
||||
- name: Push changes and tags
|
||||
if: steps.version.outputs.VERSION
|
||||
run: |
|
||||
git push origin main
|
||||
git push origin v${{ steps.version.outputs.VERSION }}
|
||||
- name: Restore dependencies
|
||||
if: steps.version.outputs.VERSION
|
||||
run: dotnet restore
|
||||
- name: Build
|
||||
if: steps.version.outputs.VERSION
|
||||
run: dotnet build --configuration Release --no-restore
|
||||
- name: Run tests
|
||||
if: steps.version.outputs.VERSION
|
||||
run: dotnet test --configuration Release --no-build --verbosity normal
|
||||
- name: Pack
|
||||
if: steps.version.outputs.VERSION
|
||||
run: dotnet pack --configuration Release --no-build --output ./artifacts /p:PackageVersion=${{ steps.version.outputs.VERSION }}
|
||||
- name: Push to NuGet
|
||||
if: steps.version.outputs.VERSION
|
||||
run: dotnet nuget push ./artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
|
||||
Reference in New Issue
Block a user