Skip to content

Commit cc7508b

Browse files
authored
Publish nuget packages
Update and rename build.yml to cicd.yml Update cicd.yml to pack and publish nuget packages to github.
1 parent 0b70c93 commit cc7508b

File tree

2 files changed

+97
-30
lines changed

2 files changed

+97
-30
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/cicd.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: CI/CD
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
tags:
9+
- 'v*'
10+
11+
jobs:
12+
build_test_pack:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup .NET
22+
uses: actions/setup-dotnet@v4
23+
with:
24+
dotnet-version: 8.0.x
25+
26+
- name: Install GitVersion
27+
uses: gittools/actions/gitversion/setup@v3.0.0
28+
with:
29+
versionSpec: '6.x'
30+
31+
- name: Determine generated version number
32+
id: version_step # step id used as reference for output values
33+
uses: gittools/actions/gitversion/execute@v3.0.0
34+
35+
- name: Determine version number to use
36+
run: |
37+
## Default to using the version from GitVersion
38+
version=${{ steps.version_step.outputs.fullSemVer }}
39+
40+
## If this is a tag, use the version from the tag
41+
if [[ ${{ github.event_name }} == 'push' && ${{ github.ref }} == 'refs/tags/v*' ]]; then
42+
version=${{ github.ref_name }}
43+
version=${version:1} ## Remove the leading 'v'
44+
fi
45+
46+
echo "Version to use: $version"
47+
echo "VERSION=$version" >> $GITHUB_ENV
48+
49+
- name: Restore dependencies
50+
run: dotnet restore
51+
52+
- name: Build
53+
run: dotnet build --configuration Release --no-restore
54+
55+
- name: Test
56+
run: dotnet test --configuration Release --no-build --verbosity normal
57+
58+
- name: Pack
59+
run: |
60+
dotnet pack --configuration Release --no-build --output ./nupkg /p:PackageVersion=$VERSION
61+
62+
- name: Upload NuGet package (for use by later jobs)
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: nupkg
66+
path: ./nupkg/*.nupkg
67+
68+
publish:
69+
## Only attempt to publish if the build job was successful
70+
needs: build_test_pack
71+
runs-on: ubuntu-latest
72+
73+
steps:
74+
- name: Checkout
75+
uses: actions/checkout@v4
76+
with:
77+
fetch-depth: 0
78+
79+
- name: Download NuGet package
80+
uses: actions/download-artifact@v4
81+
with:
82+
name: nupkg
83+
path: ./nupkg
84+
85+
## Publish to GitHub Packages - including pre-release versions
86+
- name: Publish to GitHub
87+
env:
88+
NUGET_API_KEY: ${{ secrets.GITHUB_TOKEN }}
89+
run: dotnet nuget push ./nupkg/*.nupkg --api-key $NUGET_API_KEY --source "https://nuget.pkg.github.com/DFE-Digital/index.json"
90+
91+
## Publish to NuGet.org - only for main branch pushes
92+
##- name: Publish to NuGet.org
93+
## if: github.ref == 'refs/heads/main' && github.event_name == 'push'
94+
## env:
95+
## NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
96+
## run: dotnet nuget push ./nupkg/*.nupkg --api-key $NUGET_API_KEY --source "https://api.nuget.org/v3/index.json"
97+

0 commit comments

Comments
 (0)