Skip to content

Commit 94fe619

Browse files
author
James Blair
committed
Draft of nuget publish workflow
1 parent b1e2371 commit 94fe619

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

.github/workflows/ci_build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
13
name: build
24

35
on:

.github/workflows/publish.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
3+
name: publish
4+
5+
on:
6+
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
7+
push:
8+
branches:
9+
- main # Run the workflow when pushing to the main branch
10+
- 'releases/**' # Run the workflow when pushing to a release branch
11+
pull_request:
12+
branches:
13+
- '*' # Run the workflow for all pull requests
14+
release:
15+
types:
16+
- published # Run the workflow when a new GitHub release is published
17+
# Publish to nuget.org will only occur when a new release is published
18+
19+
env:
20+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
21+
DOTNET_NOLOGO: true
22+
NuGetDirectory: ${{ github.workspace}}/nuget
23+
24+
jobs:
25+
create_nuget:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer
31+
32+
- name: Setup .NET
33+
uses: actions/setup-dotnet@v4
34+
35+
- run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}
36+
37+
# Publish the NuGet package as an artifact, so they can be used in the following jobs
38+
- uses: actions/upload-artifact@v3
39+
with:
40+
name: nuget
41+
if-no-files-found: error
42+
retention-days: 7
43+
path: ${{ env.NuGetDirectory }}/*.nupkg
44+
45+
run_test:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v3
49+
- name: Setup .NET
50+
uses: actions/setup-dotnet@v4
51+
- name: Run tests
52+
run: dotnet test --configuration Release
53+
54+
deploy:
55+
# Publish only when creating a GitHub Release
56+
# https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
57+
# You can update this logic if you want to manage releases differently
58+
if: github.event_name == 'release'
59+
runs-on: ubuntu-latest
60+
needs: [ create_nuget, run_test ]
61+
steps:
62+
# Download the NuGet package created in the previous job
63+
- uses: actions/download-artifact@v3
64+
with:
65+
name: nuget
66+
path: ${{ env.NuGetDirectory }}
67+
68+
- name: Setup .NET Core
69+
uses: actions/setup-dotnet@v4
70+
71+
# Publish all NuGet packages to NuGet.org
72+
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
73+
# If you retry a failed workflow, already published packages will be skipped without error.
74+
- name: Publish NuGet package
75+
run: |
76+
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
77+
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
78+
}

0 commit comments

Comments
 (0)