@@ -3,7 +3,7 @@ name: Build, Test, and Publish NuGet Package
3
3
on :
4
4
push :
5
5
branches :
6
- - main
6
+ - test
7
7
tags :
8
8
- ' v*.*.*' # Ensure that NuGet publishing is triggered on version tags like v1.0.0
9
9
@@ -13,7 +13,7 @@ permissions:
13
13
14
14
jobs :
15
15
16
- build :
16
+ build_and_test :
17
17
runs-on : ubuntu-latest
18
18
steps :
19
19
- name : Checkout code
@@ -24,48 +24,19 @@ jobs:
24
24
with :
25
25
dotnet-version : ' 8.x'
26
26
27
- - name : Copy README.md to the project folder
28
- run : cp README.md src/Solcast/README.md
27
+ - name : Set API Key Environment Variable
28
+ run : echo "SOLCAST_API_KEY=${{ secrets.SOLCAST_API_KEY }}" >> $GITHUB_ENV
29
29
30
30
- name : Restore dependencies
31
31
run : dotnet restore
32
32
33
- - name : Build
34
- run : dotnet build --configuration Release
35
-
36
- - name : Upload Build Artifacts
37
- uses : actions/upload-artifact@v3
38
- with :
39
- name : build_artifacts
40
- path : src/Solcast/bin/Release/**
41
-
42
- test :
43
- runs-on : ubuntu-latest
44
- needs : build
45
- steps :
46
- - name : Checkout code
47
- uses : actions/checkout@v4
48
-
49
- - name : Setup .NET Core
50
- uses : actions/setup-dotnet@v3
51
- with :
52
- dotnet-version : ' 8.x'
53
-
54
- - name : Download Build Artifacts
55
- uses : actions/download-artifact@v3
56
- with :
57
- name : build_artifacts
58
-
59
- - name : Set API Key Environment Variable
60
- run : echo "SOLCAST_API_KEY=${{ secrets.SOLCAST_API_KEY }}" >> $GITHUB_ENV
61
-
62
33
- name : Run tests
63
- run : dotnet test --no-build --configuration Release
34
+ run : dotnet test
64
35
65
- package :
36
+ package_and_publish :
66
37
if : startsWith(github.ref, 'refs/tags/')
67
38
runs-on : ubuntu-latest
68
- needs : test
39
+ needs : build_and_test
69
40
steps :
70
41
- name : Checkout code
71
42
uses : actions/checkout@v4
@@ -75,43 +46,27 @@ jobs:
75
46
with :
76
47
dotnet-version : ' 8.x'
77
48
49
+ - name : Copy README.md to the project folder
50
+ run : cp README.md src/Solcast/README.md
51
+
52
+ - name : Restore dependencies
53
+ run : dotnet restore src/Solcast/Solcast.csproj
54
+
78
55
- name : Extract version from Git tag
79
56
run : |
80
57
CLEAN_VERSION="${GITHUB_REF##*/}" # Remove 'refs/tags/'
81
58
CLEAN_VERSION="${CLEAN_VERSION#v}" # Remove leading 'v'
82
59
echo "CLEAN_VERSION=$CLEAN_VERSION" >> $GITHUB_ENV # Set it as env variable
83
60
84
- - name : Copy README.md to the project folder
85
- run : cp README.md src/Solcast/README.md
86
-
87
- - name : Restore dependencies
88
- run : dotnet restore
89
-
90
61
- name : Pack NuGet Package with version from tag
91
62
run : dotnet pack src/Solcast/Solcast.csproj --configuration Release --output ./nupkg /p:PackageVersion=${{ env.CLEAN_VERSION }}
92
63
93
- - name : Upload Package Artifact
94
- uses : actions/upload-artifact@v3
95
- with :
96
- name : nuget_package
97
- path : ./nupkg/*.nupkg
98
-
99
- publish :
100
- if : startsWith(github.ref, 'refs/tags/')
101
- runs-on : ubuntu-latest
102
- needs : package
103
- steps :
104
- - name : Download Package Artifact
105
- uses : actions/download-artifact@v3
106
- with :
107
- name : nuget_package
108
-
109
64
- name : Publish NuGet Package to GitHub Packages
110
65
env :
111
66
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
112
- run : dotnet nuget push ./*.nupkg --source "https://nuget.pkg.github.com/solcast/index.json" --api-key ${{ secrets.GITHUB_TOKEN }}
67
+ run : dotnet nuget push ./nupkg/ *.nupkg --source "https://nuget.pkg.github.com/solcast/index.json" --api-key ${{ secrets.GITHUB_TOKEN }}
113
68
114
69
- name : Publish NuGet Package to NuGet.org
115
70
env :
116
71
NUGET_API_KEY : ${{ secrets.NUGET_API_KEY }}
117
- run : dotnet nuget push ./*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
72
+ run : dotnet nuget push ./nupkg/ *.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
0 commit comments