Publish to Nuget #102
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
name: "Publish to Nuget" | |
on: | |
workflow_run: | |
workflows: | |
- "Update Changelog" | |
types: | |
- completed | |
permissions: | |
packages: write | |
contents: read | |
jobs: | |
get_changelog_versions: | |
runs-on: ubuntu-latest | |
outputs: | |
ctl-version-number: ${{ steps.get-ctl-version.outputs.version }} | |
di-version-number: ${{ steps.get-di-version.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get Cmpnnt.Pia.Ctl Version | |
id: get-ctl-version | |
env: | |
regex: '##\s\[v([0-9\.]+)\]\s-\s[0-9]{4}-[0-9]{2}-[0-9]{2}' | |
run: echo version=$(sed -nr "s/$regex/\1/p" CHANGELOG.md | head -n1) >> $GITHUB_OUTPUT | |
- name: Check ctl version number | |
if: steps.get-ctl-version.outputs == '' | |
run: echo "error parsing version number from ctl changelog"; exit 1 | |
- name: Get Cmpnnt.Pia.DependencyInjection Version | |
id: get-di-version | |
env: | |
regex: '##\s\[v([0-9\.]+)\]\s-\s[0-9]{4}-[0-9]{2}-[0-9]{2}' | |
run: echo version=$(sed -nr "s/$regex/\1/p" CHANGELOG.md | head -n1) >> $GITHUB_OUTPUT | |
- name: Check di version number | |
if: steps.get-di-version.outputs == '' | |
run: echo "error parsing version number from ctl changelog"; exit 1 | |
get_published_packages_versions: # The version numbers are the same for all OSes, so only getting Linux here | |
runs-on: ubuntu-latest | |
outputs: | |
ctl-package-version: ${{ steps.get-ctl-package-version.outputs.version }} | |
di-package-version: ${{ steps.get-di-package-version.outputs.version }} | |
steps: | |
- name: Get Published Get Cmpnnt.Pia.Ctl Version | |
id: get-ctl-package-version | |
run: | | |
echo version=$(curl https://api.nuget.org/v3-flatcontainer/cmpnnt.pia.ctl/index.json | jq -r .versions[-1]) >> $GITHUB_OUTPUT | |
- name: Get Published Get Cmpnnt.Pia.DependencyInjection Version | |
id: get-di-package-version | |
run: | | |
echo version=$(curl https://api.nuget.org/v3-flatcontainer/cmpnnt.pia.dependencyinjection/index.json | jq -r .versions[-1]) >> $GITHUB_OUTPUT | |
create_ctl_packages: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-13, macos-14] | |
include: | |
- { os: ubuntu-latest, rid_os: linux, rid_arch: x64 } | |
- { os: windows-latest, rid_os: win, rid_arch: x64 } | |
- { os: macos-13, rid_os: osx, rid_arch: x64 } | |
- { os: macos-14, rid_os: osx, rid_arch: arm64 } | |
needs: [get_changelog_versions, get_published_packages_versions] | |
if: needs.get_changelog_versions.outputs.ctl-version-number != needs.get_published_packages_versions.outputs.ctl-package-version | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build Ctl Project | |
id: build-ctl-project | |
run: dotnet publish -c Release -r ${{matrix.rid_os}}-${{matrix.rid_arch}} --nologo --version-suffix ${{ needs.get_changelog_versions.outputs.ctl-version-number }} Cmpnnt.Pia.Ctl/Cmpnnt.Pia.Ctl.csproj | |
- uses: actions/upload-artifact@v4 | |
with: # upload the DLL files to be used in a meta-package in a later step | |
name: Cmpnnt.Pia.Ctl.dll-${{matrix.rid_os}}-${{matrix.rid_arch}} | |
path: Cmpnnt.Pia.Ctl/bin/Release/net8.0/${{matrix.rid_os}}-${{matrix.rid_arch}}/publish | |
publish_meta_package: | |
runs-on: ubuntu-latest | |
needs: [get_changelog_versions, get_published_packages_versions, create_ctl_packages] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download Windows Library | |
uses: actions/download-artifact@v4 | |
with: | |
name: Cmpnnt.Pia.Ctl.dll-win-x64 | |
path: Cmpnnt.Pia.Ctl.Meta/runtimes/win-x64/native | |
- name: Download Linux Library | |
uses: actions/download-artifact@v4 | |
with: | |
name: Cmpnnt.Pia.Ctl.dll-linux-x64 | |
path: Cmpnnt.Pia.Ctl.Meta/runtimes/linux-x64/native | |
- name: Download MacOS x64 Library | |
uses: actions/download-artifact@v4 | |
with: | |
name: Cmpnnt.Pia.Ctl.dll-osx-x64 | |
path: Cmpnnt.Pia.Ctl.Meta/runtimes/osx-x64/native | |
- name: Download MacOS ARM Library | |
uses: actions/download-artifact@v4 | |
with: | |
name: Cmpnnt.Pia.Ctl.dll-osx-arm64 | |
path: Cmpnnt.Pia.Ctl.Meta/runtimes/osx-arm64/native | |
- name: Create Meta Package | |
id: create-meta-package | |
run: dotnet pack -c Release --nologo -p:PackageVersion=${{ needs.get_changelog_versions.outputs.ctl-version-number }} Cmpnnt.Pia.Ctl/Cmpnnt.Pia.Ctl.csproj | |
- name: Push Meta Package to Nuget | |
id: push-meta-package | |
run: dotnet nuget push 'Cmpnnt.Pia.Ctl/bin/Release/Cmpnnt.Pia.Ctl.${{ needs.get_changelog_versions.outputs.ctl-version-number }}.nupkg' --api-key ${{ secrets.NUGET_DEFAULT_TOKEN }} --source https://api.nuget.org/v3/index.json | |
publish_di_package: | |
runs-on: ubuntu-latest | |
needs: [get_changelog_versions, get_published_packages_versions, publish_meta_package] | |
if: needs.get_changelog_versions.outputs.di-version-number != needs.get_published_packages_versions.outputs.di-package-version | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Create DI Package | |
id: create-di-package | |
run: dotnet pack -c Release --nologo -p:PackageVersion=${{ needs.get_changelog_versions.outputs.di-version-number }} Cmpnnt.Pia.DependencyInjection/Cmpnnt.Pia.DependencyInjection.csproj | |
- name: Push DI Package to Nuget | |
id: push-di-package | |
run: dotnet nuget push 'Cmpnnt.Pia.DependencyInjection/bin/Release/Cmpnnt.Pia.DependencyInjection.${{ needs.get_changelog_versions.outputs.di-version-number }}.nupkg' --api-key ${{ secrets.NUGET_DEFAULT_TOKEN }} --source https://api.nuget.org/v3/index.json | |
# TODO: figure a better way to distribute the debug symbols. Might have to create a new .nupkg file just for the debug symbols | |
# TODO: determine a way to automatically update the relevant sub-changelogs when conventional commits are added to any given package. | |