Skip to content

Commit

Permalink
Add package publish automation
Browse files Browse the repository at this point in the history
Extend the build workflow to output the NuGet package name and version and then dispatch a `nuget_packages_published` event when the NuGet package is published to NuGet.org.
  • Loading branch information
martincostello committed May 25, 2024
1 parent d7cc765 commit b33de01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
outputs:
dotnet-sdk-version: ${{ steps.setup-dotnet.outputs.dotnet-version }}
dotnet-validate-version: ${{ steps.get-dotnet-validate-version.outputs.dotnet-validate-version }}
package-names: ${{ steps.build.outputs.package-names }}
package-version: ${{ steps.build.outputs.package-version }}

permissions:
attestations: write
Expand Down Expand Up @@ -57,6 +59,7 @@ jobs:
id: setup-dotnet

- name: Build, Test and Package
id: build
shell: pwsh
run: ./build.ps1

Expand Down Expand Up @@ -199,3 +202,16 @@ jobs:
API_KEY: ${{ secrets.NUGET_TOKEN }}
SOURCE: https://api.nuget.org/v3/index.json
run: dotnet nuget push "*.nupkg" --api-key "${API_KEY}" --skip-duplicate --source "${SOURCE}"

- name: Publish nuget_packages_published
uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3.0.0
with:
event-type: nuget_packages_published
repository: ${{ github.repository_owner }}/github-automation
token: ${{ secrets.COSTELLOBOT_TOKEN }}
client-payload: |-
{
"repository": "${{ github.repository }}",
"packages": "${{ needs.build.outputs.package-names }}",
"version": "${{ needs.build.outputs.package-version }}"
}
4 changes: 4 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@
</PropertyGroup>
<WriteLinesToFile Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' " ContinueOnError="WarnAndContinue" File="$(GITHUB_STEP_SUMMARY)" Lines="$(_ReportSummaryContent)" />
</Target>
<Target Name="SetNuGetPackageOutputs" AfterTargets="Pack" Condition=" '$(GITHUB_OUTPUT)' != '' ">
<WriteLinesToFile File="$(GITHUB_OUTPUT)" Lines="package-names=$(PackageId)" />
<WriteLinesToFile File="$(GITHUB_OUTPUT)" Lines="package-version=$(Version)" />
</Target>
</Project>

0 comments on commit b33de01

Please sign in to comment.