Skip to content

Commit

Permalink
Add CI workflow for GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreeve committed Oct 17, 2023
1 parent a121c7e commit 6191bd1
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
99 changes: 99 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: CI

on:
push:
pull_request:

jobs:

build-nuget:
if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
name: Build NuGet package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Build project
run: dotnet build src/SemanticVersioning --configuration=Release
- name: Build NuGet package
run: dotnet pack src/SemanticVersioning --configuration=Release --no-build --output nuget
- name: Upload NuGet artifact
uses: actions/upload-artifact@v3
with:
name: nuget-package
path: nuget

test-nuget:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
dotnet: [net6.0, net7.0]
include:
- os: windows-latest
dotnet: net472
fail-fast: false
name: Test NuGet package (${{ matrix.dotnet }} on ${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: build-nuget
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get version
id: get-version
run: echo "version=$((Select-Xml -Path ./src/SemanticVersioning/SemanticVersioning.csproj -XPath '/Project/PropertyGroup/Version/text()').node.Value)" >> $env:GITHUB_OUTPUT
shell: pwsh
- name: Download NuGet artifact
uses: actions/download-artifact@v3
with:
name: nuget-package
path: nuget
- name: Setup .NET 6 SDK
if: matrix.dotnet == 'net6.0'
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Setup .NET 7 SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Add local NuGet feed
run: |
dotnet new nugetconfig
dotnet nuget add source -n local $PWD/nuget
- name: Change test project references to use local NuGet package
run: |
dotnet remove test/SemanticVersioning.Tests reference src/SemanticVersioning/SemanticVersioning.csproj
dotnet add test/SemanticVersioning.Tests package SemanticVersioning -v ${{ steps.get-version.outputs.version }}
- name: Build & Run .NET unit tests
run: dotnet test test/SemanticVersioning.Tests --configuration=Release --framework ${{ matrix.dotnet }}

publish-release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && !github.event.repository.fork
name: Publish release
runs-on: ubuntu-latest
needs: test-nuget
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check version
id: check-version
shell: pwsh
run: |
$version = (Select-Xml -Path ./src/SemanticVersioning/SemanticVersioning.csproj -XPath '/Project/PropertyGroup/Version/text()').node.Value
$tag = "${{ github.ref }}".SubString(10)
if (-not ($tag -eq $version)) {
echo "::error ::There is a mismatch between the project version ($version) and the tag ($tag)"
exit 1
}
echo "version=$version" >> $env:GITHUB_OUTPUT
- name: Download NuGet artifact
uses: actions/download-artifact@v3
with:
name: nuget-package
path: nuget
- name: Publish to NuGet
run: dotnet nuget push nuget/SemanticVersioning.${{ steps.check-version.outputs.version }}.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AssemblyName>SemanticVersioning.Tests</AssemblyName>
<PackageId>SemanticVersioning.Tests</PackageId>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)'=='Windows_NT'">$(TargetFrameworks);net472</TargetFrameworks>
<AssemblyOriginatorKeyFile>..\..\build\semver-key.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
Expand Down

0 comments on commit 6191bd1

Please sign in to comment.