Skip to content

Extra commit when commiting #20

Closed
Closed

Description

@estensen

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 "action@github.com"
        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?

Activity

  1. estensen commented on Oct 17, 2019

    @estensen
    ContributorAuthor

    Solved this by specifying the correct ref when checking out:

    - uses: actions/checkout@v1
      with:
        ref: refs/heads/${{ github.head_ref }}
    
  2. added a commit that references this issue on Jul 13, 2020
  3. kenorb commented on Jul 13, 2020

    @kenorb

    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.

  4. added a commit that references this issue on Jul 15, 2020
  5. murilogok commented on Aug 6, 2021

    @murilogok

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions