Skip to content

Publish NuGet packages #82

Publish NuGet packages

Publish NuGet packages #82

name: Publish NuGet packages
on:
workflow_run:
branches:
- master
workflows:
- "Build .NET project"
types:
- completed
permissions:
packages: write
env:
PACKAGE_NAME: "org.miniscript.MiniScript"
jobs:
check_nuget:
name: Check what kind of NuGet release is required
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
release: ${{ steps.compare.outputs.new-version }}
defaults:
run:
working-directory: MiniScript-cs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- name: Get latest package version from Github Packages
id: nuget-ver
run: |
export NUGET_VER=$(gh api -H "Accept: application/vnd.github+json" /users/${{ github.repository_owner }}/packages/nuget/${{ env.PACKAGE_NAME }}/versions | jq '.[0].name' | tr -d '"' | awk -F'-' '{print $1}')
echo "version=${NUGET_VER}" >> $GITHUB_OUTPUT
- name: Compare vs current version
id: compare
run: |
export CURRENT_VER=$(grep -e "Version" Miniscript.csproj | awk -F'>' '{print $2}' | awk -F'<' '{print $1}')
[[ "${{ steps.nuget-ver.outputs.version }}" != "$CURRENT_VER" ]] \
&& echo "new-version=true" >> $GITHUB_OUTPUT \
|| echo "new-version=false" >> $GITHUB_OUTPUT
nuget:
name: Release NuGet package
runs-on: ubuntu-latest
needs: check_nuget
if: ${{ github.event.workflow_run.conclusion == 'success' }}
defaults:
run:
working-directory: MiniScript-cs
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Authenticate to Github Packages
run: dotnet nuget add source --username "${{ github.repository_owner }}" --password "${{ secrets.GITHUB_TOKEN }}" --store-password-in-clear-text --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
- name: Package
run: |
[[ "${{ needs.check_nuget.outputs.release }}" == "true" ]] \
&& dotnet pack -c Release -p:RepositoryBranch="master" -p:RepositoryCommit="$(git rev-parse HEAD)" \
|| dotnet pack -c Release -p:RepositoryBranch="master" -p:RepositoryCommit="$(git rev-parse HEAD)" --version-suffix "p$(git rev-parse --short HEAD)"
- name: Publish to GitHub Packages
run: dotnet nuget push "bin/Release/${{ env.PACKAGE_NAME }}.*.nupkg" --source "github" --api-key "${{ secrets.GHPR_TOKEN }}"
- name: Publish to NuGet
run: dotnet nuget push "bin/Release/${{ env.PACKAGE_NAME }}.*.nupkg" --api-key "${{ secrets.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json