1

Fully studied the github doc on pushing packages to Git. All the points in the docs are met in the code from the instructor that I'm using.

Looked for typos, etc.

This is the course YAML, it compares exactly to the instructor version:

name: Push to GitHub Packages

on:
  push:
  workflow_dispatch:

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x
    - name: Restore dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore 

    - name: Pack
      run: dotnet pack --configuration Release --no-build --output .
      
    - name: Push
      run: |
        dotnet nuget add source --username *** --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/***/index.json"
        dotnet nuget push ./*.nupkg --skip-duplicate --source "github" --api-key ${GITHUB_TOKEN}
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Here is the error I get when pushing my package to Git, sensitive info redacted. The Push section of the job run says the package was successfully added.

I'm using the GITHUB_TOKEN with the valid organization / username.

Run dotnet nuget add source --username *** -*** --store-password-in-clear-text --name github "https://nuget.pkg.github.com/***/index.json"
  dotnet nuget add source --username *** -*** --store-password-in-clear-text --name github "https://nuget.pkg.github.com/***/index.json"
  dotnet nuget push ./*.nupkg --skip-duplicate --source "github" --api-key ${GITHUB_TOKEN}
  shell: /usr/bin/bash -e {0}
  env:
    DOTNET_ROOT: /home/runner/.dotnet
    GITHUB_TOKEN: ***
Package source with Name: github added successfully.
Pushing MyCoolClassLibrary.1.0.1.nupkg to 'https://nuget.pkg.github.com/***'...
  PUT https://nuget.pkg.github.com/***/
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.
  Forbidden https://nuget.pkg.github.com/***/ 224ms
error: Response status code does not indicate success: 403 (Forbidden).

As the old saying goes, this isn't rocket science but it does have a few moving parts.

This code has been parsed over many times. I have to be missing something, just don't see what that is.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
user1585204
  • 827
  • 1
  • 10
  • 14

1 Answers1

1

First, add a

permissions:
  packages: write
  contents: read

See:

The defaults for your repository might be set to read-only (Repository - ⚙️ Settings - ▶️ Actions - General):

enter image description here

And be sure to link the package to the repository

If you are using a GitHub Actions workflow to manage your packages, you can grant an access role to the repository the workflow is stored in by using the Add Repository button under "Manage Actions access" in the package's settings. For more information, see "Configuring a package's access control and visibility."

On your package's landing page, on the right-hand side, click ⚙️ Package settings.

enter image description here

To ensure your workflow has access to your package, you must add the repository where the workflow is stored. Under "Manage Actions access", click Add repository and search for the repository you want to add.

enter image description here

Use the Role drop-down menu to select the default access level that you'd like the repository to have to your package.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • This worked perfect, was added in the jobs: section right after the runs-on: block: permissions: packages: write contents: read It ran straight away. Now the question is why the GITHUB_TOKEN didn't take care of this. Per the course, with this repo being in my organization scope, it should just run, right? That should be the full access? I'll push this solution out to the instructor as well. – user1585204 Aug 07 '23 at 15:13
  • The organisation can set the default for the tokens. – jessehouwing Aug 07 '23 at 16:07
  • And for new repos, GitHub now configures a least privigedge token instead of giving you all permissions by default. – jessehouwing Aug 07 '23 at 16:15
  • You said it all with this: "And for new repos, GitHub now configures a least privilege token instead of giving you all permissions by default." This course was created 2 years ago, the repo for me to follow along was created just last week. Thanks! – user1585204 Aug 07 '23 at 16:43