Closed vetlekise closed 12 months ago
If I change the Push commits step to not use your action and run a git command instead, I don't get a permission error and instead I get this:
Run git push origin HEAD:fmt-test1[2](https://github.com/CorpAutomationOrg-NearShore/sg/actions/runs/6810250500/job/18518192132#step:9:2) --force-with-lease -u ***
git push origin HEAD:fmt-test12 --force-with-lease -u ***
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
env:
TF_LOG: INFO
working-dir: ./LandingZones-Corp/Apport
TERRAFORM_CLI_PATH: /home/runner/work/_temp/aac644ef-2077-4e9e-9801-5d1fe194441[3](https://github.com/CorpAutomationOrg-NearShore/sg/actions/runs/6810250500/job/18518192132#step:9:3)
AZURE_HTTP_USER_AGENT:
AZUREPS_HOST_ENVIRONMENT:
error: src refspec *** does not match any
error: failed to push some refs to 'https://github.com/CorpAutomationOrg-NearShore/sg'
Error: Process completed with exit code 1.
When searches this error, it looks like it is unable to find the branch, but the branch is 100% present.
# Push previously commited changes
- name: Push Formatting Changes
run: |
git push origin HEAD:${{ github.head_ref }} --force-with-lease -u ${{ secrets.GITHUB_TOKEN }}
Hi @vetlekise, could you please share your findings? What went wrong on your end?
From my end, it looks like your GH repository action settings are not configured properly.
I got it working by using a PAT (fine-grained) targeting the organization repo with the permissions; PullRequest:Read&Write and Contents:Read&Write, instead of the GITHUB_TOKEN.
New workflow that worked for me:
# Commit formatting changes
- name: Commit Formatting Changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git branch -a
git add .
git commit -a -m "${{ github.event.pull_request.title }}"
continue-on-error: true
# Push previously commited changes
- name: Push Formatting Changes
run: |
git push --force origin HEAD:${{ github.event.pull_request.head.ref }}
# Update the pull request branch with new code
- name: Update Pull Request Branch
run: |
git fetch origin ${{ github.event.pull_request.head.ref }}
git merge origin/${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
@vetlekise Thank you for sharing your solution, but in general, it should also work with the GH Action, and if you are pushing to the same repository as the origin content comes from also with the default token. I think you've maybe missed to set-up the GitHub Action push settings beforehand.
Trying to accomplish
Disclaimer (if it matters): Repo is in an organization repo. I am creating a workflow that runs on a PR in a specified directory and the workflow will lint my code by running
terraform fmt -write=true
. This lint should be committed and then pushed to the pull request branch. Is this not possible or am I doing it wrong?The error is showing the correct branch and URL, and I am using GITHUB_TOKEN for the permissions. Does this token not work for this use case or is the permissions not correct?
Workflow error
Workflow used