Skip to content

Commit 15238b8

Browse files
committed
feat(workflows): add examples tests and publish packages workflow; remove redundant test step
1 parent 64836c8 commit 15238b8

File tree

4 files changed

+167
-4
lines changed

4 files changed

+167
-4
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ jobs:
3939
- name: Test & Code Coverage
4040
run: dotnet test --no-restore --filter "Category!=E2E" --collect:"XPlat Code Coverage" --results-directory ./codecov --verbosity normal
4141

42-
- name: Test Examples
43-
run: dotnet test ../examples/ --verbosity normal
44-
4542
- name: Codecov
4643
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # 5.4.0
4744
with:

.github/workflows/examples-tests.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Examples Tests
2+
3+
on:
4+
push:
5+
paths:
6+
- "examples/**"
7+
branches: [develop]
8+
pull_request:
9+
paths:
10+
- "examples/**"
11+
branches: [develop]
12+
13+
defaults:
14+
run:
15+
working-directory: ./examples
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
26+
- name: Setup .NET SDK
27+
uses: actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # 4.3.0
28+
with:
29+
dotnet-version: |
30+
6.0.x
31+
8.0.x
32+
33+
- name: Install dependencies
34+
run: dotnet restore
35+
36+
- name: Build
37+
run: dotnet build --configuration Release --no-restore /tl
38+
39+
- name: Test Examples
40+
run: dotnet test --no-restore --verbosity normal
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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

libraries/src/Directory.Build.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
<LangVersion>default</LangVersion>
55
<!-- Version is generated when packaging the individual csproj -->
6-
<Version>0.0.1</Version>
6+
<Version>$(Version)</Version>
77
<Authors>Amazon Web Services</Authors>
88
<Company>Amazon.com, Inc</Company>
99
<Title>Powertools for AWS Lambda (.NET)</Title>
@@ -16,6 +16,7 @@
1616
<PackageIcon>AWSLogo128x128.png</PackageIcon>
1717
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1818
<GenerateDocumentationFile>true</GenerateDocumentationFile>
19+
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
1920

2021
</PropertyGroup>
2122

0 commit comments

Comments
 (0)