1
+ # PROCESS
2
+ #
3
+ # 1. Build and pack all libraries in the solution
4
+ # 2. Set up examples to use these local packages
5
+ # 3. Run tests on examples to verify they work with the latest code
6
+ # 4. Publish packages to GitHub Packages (on develop branch only)
7
+
8
+ # USAGE
9
+ #
10
+ # This workflow is triggered on push to the develop branch or manually via workflow_dispatch.
11
+
12
+ name : Publish Packages and Examples Tests
13
+
14
+ on :
15
+ workflow_dispatch :
16
+ push :
17
+ paths :
18
+ - " libraries/**"
19
+ branches :
20
+ - develop
21
+
22
+ permissions :
23
+ contents : read
24
+
25
+ jobs :
26
+ pack-libraries :
27
+ runs-on : ubuntu-latest
28
+ steps :
29
+ - name : Checkout code
30
+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
31
+
32
+ - name : Setup .NET
33
+ uses : actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # 4.3.0
34
+ with :
35
+ dotnet-version : ' 8.x'
36
+
37
+ - name : Build libraries
38
+ run : dotnet build ./libraries/ --configuration Release
39
+
40
+ - name : Pack libraries
41
+ run : |
42
+ mkdir -p ./packages
43
+ VERSION_SUFFIX=${{ github.run_id }}
44
+ dotnet pack ./libraries/ --configuration Release --no-build --output ./packages --version-suffix $VERSION_SUFFIX
45
+
46
+ - name : Upload packages
47
+ uses : actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # 4.6.1
48
+ with :
49
+ name : nuget-packages
50
+ path : ./packages/
51
+
52
+ run-tests :
53
+ permissions :
54
+ id-token : write
55
+ runs-on : ubuntu-latest
56
+ needs : pack-libraries
57
+ steps :
58
+ - name : Checkout code
59
+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
60
+
61
+ - name : Set up .NET
62
+ uses : actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # 4.3.0
63
+ with :
64
+ dotnet-version : ' 8.x'
65
+
66
+ - name : Download packages
67
+ uses : actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # 4.1.9
68
+ with :
69
+ name : nuget-packages
70
+ path : ./packages/
71
+
72
+ - name : Configure local NuGet source
73
+ run : |
74
+ dotnet nuget add source ${{ github.workspace }}/packages --name local
75
+
76
+ - name : Update examples to use local packages
77
+ run : |
78
+ find ./examples -name "*.csproj" | while read project; do
79
+ echo "Updating $project to use local packages"
80
+ for package in ./packages/*.nupkg; do
81
+ # Extract package name and version
82
+ packageName=$(basename $package .nupkg | sed -E 's/(.*)\.([0-9]+\.[0-9]+\.[0-9]+.*)$/\1/')
83
+ packageVersion=$(basename $package .nupkg | sed -E 's/(.*)\.([0-9]+\.[0-9]+\.[0-9]+.*)$/\2/')
84
+
85
+ # Use xmlstarlet to check and update package references
86
+ if grep -q "<PackageReference.*Include=\"$packageName\"" "$project"; then
87
+ echo " - Updating $packageName to version $packageVersion"
88
+ dotnet add "$project" package "$packageName" --version "$packageVersion" --source ${{ github.workspace }}/packages
89
+ fi
90
+ done
91
+ done
92
+
93
+ - name : Test Examples
94
+ run : dotnet test ./examples/ --configuration Release --verbosity normal
95
+
96
+ publish-packages :
97
+ if : github.event_name == 'push' && github.ref == 'refs/heads/develop'
98
+ needs : run-tests
99
+ runs-on : ubuntu-latest
100
+ permissions :
101
+ packages : write
102
+ steps :
103
+ - name : Download packages
104
+ uses : actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # 4.1.9
105
+ with :
106
+ name : nuget-packages
107
+ path : ./packages/
108
+
109
+ - name : Setup .NET
110
+ uses : actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # 4.3.0
111
+ with :
112
+ dotnet-version : ' 8.x'
113
+
114
+ - name : Setup GitHub Packages source
115
+ run : |
116
+ dotnet nuget add source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json \
117
+ --name github \
118
+ --username ${{ github.actor }} \
119
+ --password ${{ secrets.GITHUB_TOKEN }}
120
+
121
+ - name : Publish packages to GitHub Packages
122
+ run : |
123
+ for package in ./packages/*.nupkg; do
124
+ dotnet nuget push $package --source github --api-key ${{ secrets.GITHUB_TOKEN }}
125
+ done
0 commit comments