generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathpublish-artifacts-examples-tests.yml
More file actions
139 lines (117 loc) · 4.5 KB
/
publish-artifacts-examples-tests.yml
File metadata and controls
139 lines (117 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# PROCESS
#
# 1. Build and pack all libraries in the solution
# 2. Set up examples to use these local packages
# 3. Run tests on examples to verify they work with the latest code
# 4. Publish packages to GitHub Packages (on develop branch only)
# USAGE
#
# This workflow is triggered on push to the develop branch or manually via workflow_dispatch.
name: Publish Packages and Examples Tests
on:
workflow_dispatch:
push:
paths:
- "libraries/**"
branches:
- develop
permissions:
contents: read
jobs:
pack-libraries:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup .NET
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # 4.3.1
with:
dotnet-version: |
6.0.x
8.0.x
- name: Build libraries
run: dotnet build ./libraries/ --configuration Release
- name: Pack libraries
run: |
mkdir -p ./packages
VERSION_SUFFIX=${{ github.run_id }}
dotnet pack ./libraries/ --configuration Release --no-build --output ./packages --version-suffix $VERSION_SUFFIX
- name: Upload packages
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #4.6.2
with:
name: nuget-packages
path: ./packages/
run-tests:
permissions:
id-token: write
runs-on: ubuntu-latest
needs: pack-libraries
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up .NET
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # 4.3.1
with:
dotnet-version: |
6.0.x
8.0.x
- name: Download packages
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # 5.0.0
with:
name: nuget-packages
path: ./packages/
- name: Configure local NuGet source
run: |
dotnet nuget add source ${{ github.workspace }}/packages --name local
# Ensure we preserve access to NuGet.org
- name: Configure NuGet.org source
continue-on-error: true
run: |
dotnet nuget add source https://api.nuget.org/v3/index.json --name nuget.org
- name: Update examples to use local packages
run: |
find ./examples -name "*.csproj" | while read project; do
echo "Updating $project to use local packages"
for package in ./packages/*.nupkg; do
# Extract package name and version
packageName=$(basename $package .nupkg | sed -E 's/(.*)\.([0-9]+\.[0-9]+\.[0-9]+.*)$/\1/')
packageVersion=$(basename $package .nupkg | sed -E 's/(.*)\.([0-9]+\.[0-9]+\.[0-9]+.*)$/\2/')
# Check if project references this package
if grep -q "<PackageReference.*Include=\"$packageName\"" "$project"; then
echo " - Updating $packageName to version $packageVersion"
# Use --no-restore to avoid restoring during each add
dotnet add "$project" package "$packageName" --version "$packageVersion" --source "local" --no-restore
fi
done
done
- name: Dotnet restore
run: dotnet restore ./examples/
- name: Test Examples
run: dotnet test ./examples/ --no-restore --configuration Release --verbosity normal
publish-packages:
if: (github.event_name == 'push' && github.ref == 'refs/heads/develop') || ${{ github.event_name == 'workflow_dispatch' }}
needs: run-tests
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Download packages
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # 5.0.0
with:
name: nuget-packages
path: ./packages/
- name: Setup .NET
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # 4.3.1
with:
dotnet-version: |
6.0.x
8.0.x
- name: Setup GitHub Packages source
run: |
dotnet nuget add source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json \
--name github
- name: Publish packages to GitHub Packages
run: |
for package in ./packages/*.nupkg; do
dotnet nuget push $package --source github --api-key ${{ secrets.GITHUB_TOKEN }}
done