brandedoutcast / publish-nuget

📦 GitHub action to automate publishing NuGet packages when project version changes
https://github.com/marketplace/actions/publish-nuget
MIT License
197 stars 101 forks source link

add nupkg to release #29

Closed b3b00 closed 4 years ago

b3b00 commented 4 years ago

Hello,

First thanks for your github action. Would it be possible to automatically add the nupkg to the gtihub release when it is generated ? I personnaly always add a nupkg to each github release and would find it very helpful if publish-nuget does it for me.

brandedoutcast commented 4 years ago

Thanks for the issue, I can certainly help with that but the action itself won't deal with a release directly

My idea of a GitHub action is a tiny code of automation that's built for a specific task & can be combined with other actions to build a pipeline

I'll update publish-nuget to create output variables for nupkg name & path info. You can use these variables in actions further down the pipeline to create a release with create release action & upload the generated package with upload-release-asset action

I'll update this issue with output variable names & maybe a sample pipeline for your need

brandedoutcast commented 4 years ago

@b3b00 closing this issue as v2.4.0 landed with output variables & you could do something like this for your need

steps:
    - uses: actions/checkout@v2
    - name: push
      id: publish_nuget
      uses: rohith/publish-nuget@v2
      with:
          PROJECT_FILE_PATH: Sample/Sample.fsproj
          NUGET_KEY: ${{ secrets.NUGET_API_KEY }}
    - name: Create Release
      if: ${{ success() }}
      id: create_release
      uses: actions/create-release@latest
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ steps.publish_nuget.outputs.VERSION }}
        release_name: Release ${{ steps.publish_nuget.outputs.VERSION }}
        draft: false
        prerelease: false
    - name: Upload Release Asset
      id: upload-release-asset 
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: ${{ steps.publish_nuget.outputs.PACKAGE_PATH }}
        asset_name: ${{ steps.publish_nuget.outputs.PACKAGE_NAME }}
        asset_content_type: application/zip
b3b00 commented 4 years ago

I tried your sample on a project (yaml below).

but I got an error on the create-release step following publish-nuget : I guess htat the error comes from the uses: rohith/publish-nuget@v2 line but can't find what to change.

##[error]Input required and not supplied: tag_name
name: .NET Core

on:
  push:
    branches: [ dev ]
  pull_request:
    branches: [ dev ]

jobs:
  build:

    runs-on: windows-2019

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.101   
    - name: Build with dotnet -c Debug -f netcoreapp2.0
      run: dotnet build --configuration Debug    
    - name: debug test
      run: ls ParserTests/bin/Debug/*
    - name: Test with dotnet
      run: dotnet test -c Debug 
      # -c Release --no-build /p:coverletOutput=./lcov /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:exclude='[while]*,[expressionParser]*,[GenericLexerWithCallbacks]*,[jsonparser]*,[SimpleExpressionParser]*' ParserTests/ParserTests.csproj 
    #- name: coveralls
    #  uses: coverallsapp/github-action@v1.1.1
   #   with:
   #     github-token: ${{ secrets.GITHUB_TOKEN }} 
   #     path-to-lcov: ./lcov 
    - name: push
      id: publish_nuget
      uses: rohith/publish-nuget@v2
      with:
          VERSION_REGEX: <version>(.*)<\/version>  
          PROJECT_FILE_PATH: sly/sly.csproj
          NUGET_KEY: ${{ secrets.NUGET_API_KEY }}
    - name: Create Release
      if: ${{ success() }}
      id: create_release
      uses: actions/create-release@latest
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ steps.publish_nuget.outputs.VERSION }}
        release_name: Release ${{ steps.publish_nuget.outputs.VERSION }}
        draft: false
        prerelease: false
    - name: Upload Release Asset
      id: upload-release-asset 
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: ${{ steps.publish_nuget.outputs.PACKAGE_PATH }}
        asset_name: ${{ steps.publish_nuget.outputs.PACKAGE_NAME }}
        asset_content_type: application/zip
b3b00 commented 4 years ago

@brandedoutcast , I found it :

uses: brandedoutcast/publish-nuget@v2.5.2
b3b00 commented 4 years ago

Just in case someone need it. I had to condition the create release step with an if

- name: Create Release
      if: ${{ success() && steps.publish_nuget.outputs.VERSION != ''  && steps.publish_nuget.outputs.VERSION != null }}
      id: create_release
      uses: actions/create-release@latest
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ steps.publish_nuget.outputs.VERSION }}
        release_name: Release ${{ steps.publish_nuget.outputs.VERSION }}
        draft: false
        prerelease: false

and so for updload asset step

- name: Upload Release Asset
      if: ${{ success() && steps.create_release.outputs.upload_url != ''  && steps.create_release.outputs.upload_url != null }}
      id: upload-release-asset 
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: ${{ steps.publish_nuget.outputs.PACKAGE_PATH }}
        asset_name: ${{ steps.publish_nuget.outputs.PACKAGE_NAME }}
        asset_content_type: application/zip