Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

GitHub Actions: automatically push NuGet package

$
0
0

I'm trying to configure my Github repository in order to automatically have a NuGet package built and pushed to both nuget.org and github.com. So what I want is that each time a commit is made on the master branch, or another branch is merged into the master, github publishes a new Nuget package of the head of the master to both Nuget and Github.

NuGet

  1. On my nuget organization account, I generated an access token (username - API keys - Create)
  2. On Github (select your organization - View organization - Settings tab - Secrets) I added a secret with the name PUBLISH_TO_NUGET_ORG and my nuget access token

Github

  1. On my personal account, I generated an access token (Account - Settings - Developer settings - Personal access tokens - generate)
  2. On Github I added a secret with the name PUBLISH_TO_GITHUB_COM and my github access token

These are the scopes for my Github access token:

Scopes for my Github access token

Setup

In my github repository I've setup an action to restore, build, test, pack and publish:

name: .NET Coreon:  push:    branches: [ master ]  pull_request:    branches: [ master ]jobs:  build:    runs-on: ubuntu-latest    steps:    - uses: actions/checkout@v2    - name: Setup .NET Core      uses: actions/setup-dotnet@v1      with:        dotnet-version: 3.1.301    - name: Install dependencies      run: dotnet restore    - name: Build      run: dotnet build --configuration Release --no-restore    - name: Test      run: dotnet test --no-restore --verbosity normal#    - name: Publish#      uses: brandedoutcast/publish-nuget@v2.5.2#      with:#          PROJECT_FILE_PATH: MintPlayer.SeasonChecker/MintPlayer.SeasonChecker.csproj#          NUGET_KEY: ${{secrets.PUBLISH_TO_NUGET_ORG}}#          INCLUDE_SYMBOLS: true    - name: Pack      run: dotnet pack --no-build --configuration Release MintPlayer.SeasonChecker/MintPlayer.SeasonChecker.csproj --output .    - name: PushNuget      run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.PUBLISH_TO_NUGET_ORG}} --skip-duplicate    - name: AddGithubSource      run: dotnet nuget add source --username PieterjanDeClippel --password ${{secrets.PUBLISH_TO_GITHUB_COM}} --name github https://nuget.pkg.github.com/MintPlayer/index.json    - name: PushGithub      run: dotnet nuget push *.nupkg --source github --skip-duplicate

The push to nuget.org works fine, but the push to my GitHub feed fails with an Unauthorized error.

I've taken a look at some plugins like this one, and I want to embed this into my action in order not to build my project multiple times.

First take:

dotnet nuget push *.nupkg --source https://nuget.pkg.github.com/MintPlayer/index.json --api-key ${{secrets.PUBLISH_TO_GITHUB_COM}} --skip-duplicate

Result:warn : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

warn : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

Second take with multiple commands:

dotnet nuget add source --username PieterjanDeClippel --password ${{secrets.PUBLISH_TO_GITHUB_COM}} --name github https://nuget.pkg.github.com/MintPlayer/index.jsondotnet nuget push *.nupkg --source github --skip-duplicate

This one fails with the following (obvious) message:

error: Password encryption is not supported on .NET Core for this platform. The following feed try to use an encrypted password: 'github'. You can use a clear text password as a workaround.error:   Encryption is not supported on non-Windows platforms.

Does anyone have any experience with automated publishing of Nuget packages to Github?

Link to action configuration file

Edit

I tried sending a POST request:

And I'm getting my user information, so my access token definitely works.

Edit

I also tried running the command on my computer, replacing the token with my own and that as well does work.


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>