Skip to content

Commit 9327e3d

Browse files
committed
Add publish workflow for NuGet and GitHub Releases
- Introduce `.github/workflows/publish.yml` for publishing to NuGet upon tagging. - Automate GitHub Releases with versioned artifacts. - Update solution structure to include the new workflow.
1 parent aad9634 commit 9327e3d

File tree

3 files changed

+85
-3
lines changed

3 files changed

+85
-3
lines changed

.github/workflows/publish.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Publish to NuGet
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: '9.0.x'
21+
22+
- name: Set up Docker Compose
23+
uses: docker/setup-compose-action@v1
24+
25+
- name: Start Docker Compose services
26+
working-directory: ./NullOpsDevs.LibSsh.Test
27+
run: docker compose up -d
28+
29+
- name: Build test project (Release)
30+
run: dotnet build -c Release --self-contained -r linux-x64 ./NullOpsDevs.LibSsh.Test/NullOpsDevs.LibSsh.Test.csproj
31+
32+
- name: Run tests
33+
working-directory: ./NullOpsDevs.LibSsh.Test/bin/Release/net9.0/linux-x64/
34+
run: ./NullOpsDevs.LibSsh.Test
35+
36+
- name: Cleanup Docker Compose
37+
if: always()
38+
working-directory: ./NullOpsDevs.LibSsh.Test
39+
run: docker compose down -v
40+
41+
publish:
42+
needs: test
43+
runs-on: ubuntu-latest
44+
permissions:
45+
contents: write
46+
47+
steps:
48+
- name: Checkout code
49+
uses: actions/checkout@v4
50+
51+
- name: Setup .NET
52+
uses: actions/setup-dotnet@v4
53+
with:
54+
dotnet-version: '9.0.x'
55+
56+
- name: Extract version from tag
57+
id: get_version
58+
run: |
59+
TAG_NAME=${GITHUB_REF#refs/tags/}
60+
echo "VERSION=$TAG_NAME" >> $GITHUB_OUTPUT
61+
echo "Building version: $TAG_NAME"
62+
63+
- name: Build library with version
64+
run: dotnet build -c Release /p:Version=${{ steps.get_version.outputs.VERSION }} ./NullOpsDevs.LibSsh/NullOpsDevs.LibSsh.csproj
65+
66+
- name: Pack NuGet package
67+
run: dotnet pack -c Release --no-build /p:Version=${{ steps.get_version.outputs.VERSION }} ./NullOpsDevs.LibSsh/NullOpsDevs.LibSsh.csproj -o ./artifacts
68+
69+
- name: Publish to NuGet
70+
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
71+
72+
- name: Create GitHub Release
73+
uses: softprops/action-gh-release@v2
74+
with:
75+
name: Release ${{ steps.get_version.outputs.VERSION }}
76+
tag_name: ${{ steps.get_version.outputs.VERSION }}
77+
draft: false
78+
prerelease: false
79+
files: ./artifacts/*.nupkg
80+
generate_release_notes: true
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ name: Test
22

33
on:
44
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
5+
branches:
6+
- main
87
workflow_dispatch:
98

109
jobs:

NullOpsDevs.LibSsh.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Solution>
22
<Folder Name="/CI-CD/">
33
<File Path=".github\workflows\test.yml" />
4+
<File Path=".github\workflows\publish.yml" />
45
</Folder>
56
<Project Path="NullOpsDevs.LibSsh.Test\NullOpsDevs.LibSsh.Test.csproj" Type="Classic C#" />
67
<Project Path="NullOpsDevs.LibSsh/NullOpsDevs.LibSsh.csproj" />

0 commit comments

Comments
 (0)