Skip to content

Instantly share code, notes, and snippets.

@deitry
Last active March 29, 2023 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save deitry/02311c4f5729b0ae97eb8a7c0093a179 to your computer and use it in GitHub Desktop.
Save deitry/02311c4f5729b0ae97eb8a7c0093a179 to your computer and use it in GitHub Desktop.
Simple GitHub action to build NuGet package
name: Build NuGet package and push to GitHub registry
on:
workflow_call:
inputs:
organizationName:
required: true
type: string
nuspecPath:
required: true
type: string
nugetPackageName:
required: true
type: string
permissions:
contents: read
packages: write
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup NuGet.exe for use with actions
uses: NuGet/setup-nuget@v1.0.6
- name: Create NuGet package
id: nugetPack
run: |
$xml = [xml](Get-Content ${{inputs.nuspecPath}})
$version = $xml.package.metadata.version
echo "::set-output name=version::$version"
nuget pack ${{inputs.nuspecPath}} -Version $version
- name: Setup NuGet Source
run: |
nuget sources Add `
-Name github `
-Source "https://nuget.pkg.github.com/${{ inputs.organizationName }}/index.json" `
-UserName ${{ github.actor }} `
-Password ${{ secrets.GITHUB_TOKEN }} `
-StorePasswordInClearText
- name: Publish NuGet package
run: |
nuget push `
${{ inputs.nugetPackageName }}.${{ steps.nugetPack.outputs.version }}.nupkg `
-Source "github" `
-ApiKey ${{secrets.GITHUB_TOKEN}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment