github actions publish gem package suddenly started to fail

343 Views Asked by At

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)
1

There are 1 best solutions below

0
On

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.