2

I used to publish gem packages to GitHub Packages using the following GitHub Actions and it was always successful.

name: Deploy to Github Packages

on:
  release:
    types:
      - published

env:
  ORGANIZATION: MYGITHUBNAME
  RELEASE_TAG_NAME: ${{ github.event.release.tag_name }}

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master

      - name: Set up JDK 8
        uses: actions/setup-java@v3
        with:
          java-version: 8
          distribution: temurin

      - name: gradlew build
        run: |
          VERSION=$(echo $RELEASE_TAG_NAME | sed -E 's/(v)(.*)/\2/')
          ./gradlew gem -Pversion=$VERSION

      - name: Set up Ruby
        uses: actions/setup-ruby@v1
        with:
          ruby-version: 3.0

      - name: Setup Release Credentials
        env:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
        run: |
          mkdir -p $HOME/.gem
          touch $HOME/.gem/credentials
          chmod 600 $HOME/.gem/credentials
          echo "---" >$HOME/.gem/credentials
          echo ":github: Bearer ${GITHUB_TOKEN}" >> $HOME/.gem/credentials

      - name: Publish Gem to GitHub Packages
        run: |
          PACKAGE=$(find build/gems -type f | sort | tail -n 1)
          gem push --KEY github --host https://rubygems.pkg.github.com/${ORGANIZATION} ${PACKAGE}`

However, with the repository I created today, it suddenly stopped working. Also, when I create it in an existing repository, it succeeds.

The error message when it fails is:

Pushing gem to https://rubygems.pkg.github.com/MYGITHUBNAME...
Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.
Error: Process completed with exit code 1.

When I use PAT to push the gem from my local environment, it succeeds, but it doesn't appear in the "packages" of the repository.

If anyone knows what is causing this, please let me know. Thank you.

  • Unified repository and gem names (failed)
  • I cloned the repository where gem push was successful and tried with a different repository and Gem name (failed)
Azeem
  • 11,148
  • 4
  • 27
  • 40
  • Hi! Did you try it with a new PAT with write read/write access to packages? – Azeem Jan 12 '23 at 11:40
  • thanks Azeem, I tried with the new PAT and I can push it, but it doesn't show up in packages in the repository. After further investigation, it seems that the link below is affected. https://github.blog/changelog/2023-01-10-packages-fine-grained-permissions-and-organization-level-publishing-are-now-available-for-the-github-packages-rubygems-registry/ Also, since I solved it, I will write down the method. – oysterdaisuki Jan 12 '23 at 12:16
  • Awesome! Glad you could make it work. Lately, I haven't pushed any package to GitHub Packages so I cannot say anything about that. If you already pushed one, you might want to click on that to see that. Maybe, it's under that somewhere. – Azeem Jan 12 '23 at 12:36

1 Answers1

2

This was solved!

Apparently, an item called Workflow permissions has been added to the repository's Settings > Actions > General, and it seems that the existing repository has Read and Write permissions, but the new repository has read-only permissions, hence the permission denied error.

After changing this to Read and Write, I was able to push packages. If this information is incorrect, could someone please correct it? Thank you.

Azeem
  • 11,148
  • 4
  • 27
  • 40