Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra commit when commiting #20

Closed
estensen opened this issue Oct 17, 2019 · 4 comments
Closed

Extra commit when commiting #20

estensen opened this issue Oct 17, 2019 · 4 comments

Comments

@estensen
Copy link
Contributor

estensen commented Oct 17, 2019

I'm trying to create a workflow that generates a file and then commits this file. This should happen on a separate branch and be merged when the action is complete. I currently use another action to merge and delete the branch.

workflow.yaml

    - name: Add changes
      run: |
        git config --local user.email "[email protected]"
        git config --local user.name "GitHub Action"
        git commit -m "Add pipeline" -a

    - name: Commit
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ github.HEAD_REF }}

    - name: Merge and delete branch
      uses: estensen/auto_merge_my_pull_requests@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}

When I specify branch: ${{ github.HEAD_REF }} an extra commit is created where some merging is done.

With branch: ${{ github.BRANCH }} the branch is merged and then the commit is applied.

With branch: ${{ github.REF }} I get the error:

Push to branch refs/pull/25/merge
To https://github.com/estensen/python-actions.git
 ! [remote rejected] HEAD -> refs/pull/25/merge (deny updating a hidden ref)
error: failed to push some refs to 'https://estensen:***@github.com/estensen/python-actions.git'

Overview here.

Screenshot 2019-10-17 at 11 49 49

Is it possible to have the commit happen on the branch without creating the extra merge commit?

@estensen
Copy link
Contributor Author

Solved this by specifying the correct ref when checking out:

- uses: actions/checkout@v1
  with:
    ref: refs/heads/${{ github.head_ref }}

kenorb added a commit to EA31337/EA31337 that referenced this issue Jul 13, 2020
@kenorb
Copy link

kenorb commented Jul 13, 2020

I think I've got the same issue.
image

My configuration is like:

  Push:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          persist-credentials: false
          # Otherwise, you will failed to push refs to dest repo.
          fetch-depth: 0
          ref: refs/heads/${{ github.head_ref }}
      - uses: actions/download-artifact@v2
         name: MyArtifact
      - name: Commit files
        run: |
          git config --local core.autocrlf false
          git config --local user.email $git_email
          git config --local user.name "${{ github.actor }}"
          git add . && git add --renormalize .
          git pull origin "${{ github.ref }}" --autostash --rebase -Xours
          git commit -am "${{ github.workflow }}"
        env:
          git_email: "${{ github.actor }}@users.noreply.github.com"
      - name: Push changes (not PR)
        if: github.event_name != 'pull_request'
        uses: ad-m/github-push-action@master
        with:
          branch: ${{ github.ref }}
          github_token: ${{ secrets.GITHUB_TOKEN }}
      - name: Push changes (PR)
        if: github.event_name == 'pull_request'
        uses: ad-m/github-push-action@master
        with:
          branch: refs/heads/${{ github.head_ref }}
          github_token: ${{ secrets.GITHUB_TOKEN }}

Specifying ref: refs/heads/${{ github.head_ref }} as suggested didn't help.

@kenorb kenorb mentioned this issue Jul 13, 2020
@murilogok
Copy link

Solved this issue (deny updating a hidden ref) with:

     with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ github.head_ref }} <---- Add this
        force: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants