Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update examples for release 1.30 and add workflows #813

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ jobs:
- name: Test & Code Coverage
run: dotnet test --no-restore --filter "Category!=E2E" --collect:"XPlat Code Coverage" --results-directory ./codecov --verbosity normal

- name: Test Examples
run: dotnet test ../examples/ --verbosity normal

- name: Codecov
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # 5.4.0
with:
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/examples-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Examples Tests

on:
push:
paths:
- "examples/**"
branches: [develop]
pull_request:
paths:
- "examples/**"
branches: [develop]

defaults:
run:
working-directory: ./examples

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup .NET SDK
uses: actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # 4.3.0
with:
dotnet-version: |
6.0.x
8.0.x

- name: Install dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore /tl

- name: Test Examples
run: dotnet test --no-restore --verbosity normal
125 changes: 125 additions & 0 deletions .github/workflows/publish-artifacts-examples-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# 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@3951f0dfe7a07e2313ec93c75700083e2005cbab # 4.3.0
with:
dotnet-version: '8.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@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 #4.6.1
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@3951f0dfe7a07e2313ec93c75700083e2005cbab # 4.3.0
with:
dotnet-version: '8.x'

- name: Download packages
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # 4.1.9
with:
name: nuget-packages
path: ./packages/

- name: Configure local NuGet source
run: |
dotnet nuget add source ${{ github.workspace }}/packages --name local

- 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/')

# Use xmlstarlet to check and update package references
if grep -q "<PackageReference.*Include=\"$packageName\"" "$project"; then
echo " - Updating $packageName to version $packageVersion"
dotnet add "$project" package "$packageName" --version "$packageVersion" --source ${{ github.workspace }}/packages
fi
done
done

- name: Test Examples
run: dotnet test ./examples/ --configuration Release --verbosity normal

publish-packages:
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
needs: run-tests
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Download packages
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # 4.1.9
with:
name: nuget-packages
path: ./packages/

- name: Setup .NET
uses: actions/setup-dotnet@3951f0dfe7a07e2313ec93c75700083e2005cbab # 4.3.0
with:
dotnet-version: '8.x'

- name: Setup GitHub Packages source
run: |
dotnet nuget add source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json \
--name github \
--username ${{ github.actor }} \
--password ${{ secrets.GITHUB_TOKEN }}

- 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0"/>
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0"/>
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3"/>
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.3" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.5" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0"/>
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0"/>
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3"/>
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.7.1" />
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="2.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0"/>
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0"/>
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3"/>
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="1.6.0" />
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="1.6.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion examples/BatchProcessing/src/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
<PackageReference Include="AWS.Lambda.Powertools.BatchProcessing" Version="1.1.2" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.3" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions examples/Idempotency/src/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
<PackageReference Include="AWS.Lambda.Powertools.Idempotency" Version="1.2.2" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.3" />
<PackageReference Include="AWS.Lambda.Powertools.Idempotency" Version="1.3.0" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.5" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion examples/Logging/src/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.3" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.5" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />
</ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions examples/Metrics/src/HelloWorld/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyReques

// Add Metric to capture the amount of time
Metrics.PushSingleMetric(
metricName: "CallingIP",
name: "CallingIP",
value: 1,
unit: MetricUnit.Count,
service: "lambda-powertools-metrics-example",
defaultDimensions: new Dictionary<string, string>
dimensions: new Dictionary<string, string>
{
{ "Metric Type", "Single" }
});
Expand All @@ -104,11 +104,11 @@ public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyReques
try
{
Metrics.PushSingleMetric(
metricName: "RecordsSaved",
name: "RecordsSaved",
value: 1,
unit: MetricUnit.Count,
service: "lambda-powertools-metrics-example",
defaultDimensions: new Dictionary<string, string>
dimensions: new Dictionary<string, string>
{
{ "Metric Type", "Single" }
});
Expand Down
4 changes: 2 additions & 2 deletions examples/Metrics/src/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.3" />
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.7.1" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.5" />
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="2.0.0" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="9.0.0" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.3" />
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.7.1" />
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="1.6.0" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.5" />
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="2.0.0" />
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="1.6.1" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions examples/Tracing/src/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.3" />
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="1.6.0" />
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.6.5" />
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="1.6.1" />
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion libraries/src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<LangVersion>default</LangVersion>
<!-- Version is generated when packaging the individual csproj -->
<Version>0.0.1</Version>
<Version>$(Version)</Version>
<Authors>Amazon Web Services</Authors>
<Company>Amazon.com, Inc</Company>
<Title>Powertools for AWS Lambda (.NET)</Title>
Expand All @@ -16,6 +16,7 @@
<PackageIcon>AWSLogo128x128.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>

</PropertyGroup>

Expand Down
Loading