Search code examples
githubgithub-actionspush

How i can comit and push with GitHub Actions


I am trying to push the changes that are made from the action, but it always throws an error. I already tried to use a token with all permissions, and it still doesn't work.

This is what i have in github atcions:

- name: Commit and push changes
      env:
        ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
      run: |
        git config --global user.name "Polareti"
        git config --global user.email "[email protected]"
        git add Investimentos.xlsx
        git commit -m "Atualizar arquivo com novos valores [skip ci]"
        git remote set-url origin https://github.com/Polareti/Excel-Automation.git
        git push origin main

and this is the error: error


Solution

  • I was able to commit and push with this code

    name: Commit and push
    
    on: 
        workflow_dispatch
    
    permissions:
        contents: write
    
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v3
          - run: |
              date > generated.txt
              git config user.name github-actions
              git config user.email [email protected]
              git add .
              git commit -m "generated"
              git push