Permission denied to github-actions[bot]. The requested URL returned error: 403
Asked Answered
A

2

34

I want to push files into the current repository using Github Actions.

I've written a basic configuration that uses the official actions/checkout@v3 action. My configuration is almost the same as in the readme example:

name: Example
on: workflow_dispatch
jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - shell: bash
        run: |
          date > 1.txt
          git config user.name github-actions
          git config user.email [email protected]
          git add 1.txt
          git commit -m updated
          git push

This configuration works well for any repository, except Github Pages repository. The error is:

remote: Permission to sirekanian/sirekanian.github.io.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/sirekanian/sirekanian.github.io/': The requested URL returned error: 403
Error: Process completed with exit code 128.

Why GitHub Pages repository differs from the ordinary one? Does the GitHub Pages repository have different permissions that do not allow to push into?

The most similar question I found is How let github actions workflow push generated documentation to other repository in same organization using a bot name. The answer was to use tokens, but I believe I should use a default token.

Azeotrope answered 12/9, 2022 at 9:31 Comment(0)
K
49

You have to configure your repository - Settings -> Action -> General -> Workflow permissions and choose read and write permissions

Kibitz answered 19/1, 2023 at 16:48 Comment(2)
For people using organization repos, it might have different setting at Organization's Settings. I changed there and it works now.Triturate
Keep in mind that this changes the default for all workflows in this repository. What you probably want, is to give more fine-grained permissions to just this workflow and only allow it to write to content (which tags falls under). Therefore, I suggest using the other answer to set the permissions.Insomnia
A
19

The permissions for GITHUB_TOKEN are read-only by default. If you want to push tags, you need to have write permissions to contents.

If you add a permission to write to contents, you will be able to push to your repository using GitHub checkout action:

name: Example
on: workflow_dispatch
permissions:
  contents: write
jobs:
  # your push job here
Azeotrope answered 12/9, 2022 at 9:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.