Skip to content

Final version of Release Package workflow #15

Final version of Release Package workflow

Final version of Release Package workflow #15

Workflow file for this run

# Releases non-beta versions, without 'beta*' suffix
name: Release Package
on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
jobs:
release:
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- name: .NET Info
run: dotnet --info
- name: Install XML tools
run: |
sudo apt update
sudo apt install libxml2-utils xmlstarlet
- name: Read XML
id: xml
run: |
xml_value=$(xmllint --xpath "string(//Project/PropertyGroup/Version)" ./src/Ocelot.Testing.csproj)
echo "Version: $xml_value"
echo "Version=$xml_value" >> $GITHUB_OUTPUT
xml_value=$(xmllint --xpath "string((//Project/ItemGroup)[2]/PackageReference[@Include='Ocelot']/@Version)" ./src/Ocelot.Testing.csproj)
echo "Ocelot Ref Ver: $xml_value"
echo "OcelotRefVer=$xml_value" >> $GITHUB_OUTPUT
- name: Replace Version
id: ver
run: |
echo "Version: ${{ steps.xml.outputs.Version }}"
echo "Ocelot Ref Ver: ${{ steps.xml.outputs.OcelotRefVer }}"
s_Version="${{ steps.xml.outputs.Version }}"
if [[ "$s_Version" == *-* ]]; then
echo "Version contains '-'"
first_part=$(echo "$s_Version" | cut -d'-' -f1)
echo "First part: $first_part"
new_value=$first_part
else
new_value=$s_Version
fi
echo "Going to replace version $s_Version -> $new_value"
xmlstarlet ed -L -u "//Project/PropertyGroup/Version" -v "$new_value" ./src/Ocelot.Testing.csproj
xml_value=$(xmllint --xpath "string(//Project/PropertyGroup/Version)" ./src/Ocelot.Testing.csproj)
echo "Replaced Version: $xml_value"
echo "PkgVersion=$xml_value" >> $GITHUB_OUTPUT
- name: Restore dependencies
run: dotnet restore ./Ocelot.Testing.sln
- name: Build project
run: dotnet build ./src/Ocelot.Testing.csproj --configuration Release --no-restore
- name: Pack project
run: dotnet pack ./src/Ocelot.Testing.csproj --configuration Release --output ./packages
- name: Publish to GitHub Packages
run: dotnet nuget push ./packages/*.nupkg --source "https://nuget.pkg.github.com/ThreeMammals/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
- name: Publish to NuGet
run: dotnet nuget push ./packages/*.nupkg --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY_2025 }} --skip-duplicate
# - name: Find assets
# id: assets
# run: |
# echo "ASSETS=$(find packages/*.* -print | tr '\n' ' ')" >> $GITHUB_OUTPUT
# echo "ASSETS=$(find packages/ -name '*.*pkg' -printf '%f\n')"
# - name: Use files in another step
# run: |
# echo "Files found: ${{ steps.assets.outputs.ASSETS }}"
- name: GitHub Release
uses: softprops/action-gh-release@v2
env:
PACKAGE_VERSION: ${{ steps.ver.outputs.PkgVersion }}
OCELOT_VERSION: ${{ steps.xml.outputs.OcelotRefVer }}
with:
# tag_name: 0.0.5 # Name of a tag. defaults to github.ref_name
body: |
## Version [${{ env.PACKAGE_VERSION }}](https://www.nuget.org/packages/Ocelot.Testing/${{ env.PACKAGE_VERSION }})
- Ocelot dependency package: v[${{ env.OCELOT_VERSION }}](https://www.nuget.org/packages/Ocelot/${{ env.OCELOT_VERSION }})
- For Ocelot release: [${{ env.OCELOT_VERSION }}](https://github.com/ThreeMammals/Ocelot/releases/tag/${{ env.OCELOT_VERSION }})
files: |
packages/*.*pkg
draft: false
prerelease: false