To push back to a repo in a github action

I wanted to have a GitHub Action step push back to the repo it is running in.

For that you need the write permission. which can be added like so:

permissions:
  contents: write

from: git - Push to origin from GitHub action - Stack Overflow

eg in: add write permission · jamesmstone/chess@d0a3250 · GitHub

name: Push commit
on: push
permissions:
  contents: write
jobs:
  report:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Create report file
        run: date +%s > report.txt
      - name: Commit report
        run: |
          git config --global user.name 'Your Name'
          git config --global user.email 'your-username@users.noreply.github.com'
          git commit -am "Automated report"
          git push

It it discussed on the github blog: GitHub Actions: Control permissions for GITHUB_TOKEN - GitHub Changelog

and here is the docs: Automatic token authentication - GitHub Docs

Related

Created 2024-12-10T20:20:37+07:00, updated 2024-12-11T08:26:03+07:00 · History · Edit