Merge pull request #813 from hjgraca/chore/update-examples-130 #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |