Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 5

Workflow not run for action-initiated push to PR using personal access token

Solved! Go to Solution.

In my repo I have two actions: one for running tests and one for generating and committing documentation. The triggers for these are defined as:

 

name: Run tests
on:
  pull_request:
    branches:
      - '**'
  push:
    branches:
      - master
      - 'release/**'

and

name: Generate docs
on:
  pull_request:
    branches:
      - '**'

Now when I push a change to a PR branch, both of these kick off. The docs are generated and committed + pushed back to the branch within ~30 seconds (if there are any documentation changes). The tests take a lot longer, 5+ minutes is not uncommon. 

 

Since the documentation is pushed to the PR branch using a personal access token, I was under the impression that this should trigger a new round of workflows, but it seems the push done by the docs action never triggers anything. The result is that the checks for the test workflow on the PR display as "Expected — Waiting for status to be reported".

 

When I look at the actions tab, I can see that the workflows were run for the first (human-initiated) push, but not for the second (action-initiated).

 

What am I doing wrong here? Does the fact that the tests workflow is still running when the second push is done make a difference?

4 Replies
Highlighted
GitHub Partner
Message 2 of 5

Re: Workflow not run for action-initiated push to PR using personal access token

@Hihaj Could you please share your yml content of the workflow which named "Generate docs" here? 

Do you want to trigger the test workflow by pull_request event or push event when action-initiated push happened

>>Since the documentation is pushed to the PR branch using a personal access token.

I tested in my side, I have a PR from yan0320 branch to master branch, and I have a workflow to push changes to yan0320 in an action. 

name: Generate docs
on: 
  pull_request:
    branches:
      - '**'
jobs:
  job1:
    name: push
    runs-on: ubuntu-latest    
    steps:
    - uses: actions/checkout@v1
    - name: Create local changes
      run: |
       touch $(hexdump -n 16 -v -e '/1 "%02X"' -e '/16 "\n"' /dev/urandom).yml
       git add --all
      working-directory: data/comments/3DACF59A72960405D3B93DF91EE3C060
    - name: Commit files
      run: |
        git config --local user.email "action@github.com"
        git config --local user.name "GitHub Action"
        git commit -m "Add changes" -a
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.PAT }}
        branch: yan0320 
           

With personal access token, after this action-initiated push, new workflows with on:pull_request is triggered . As in my workflow, there always have changes to push to yan0320, it makes this "Generate docs" workflow be triggered in loop. 

Please share us your scenario and expacted behavior in detail. 

 

Highlighted
Copilot Lvl 3
Message 3 of 5

Re: Workflow not run for action-initiated push to PR using personal access token

The expected behavior is this:

  • on pull_request event:
    • run test action
    • run generate docs action
  • if generated docs results in a diff, commit the changes and push back to the PR branch
    • this should result in a new pull_request event, triggering the tests again (docs will trigger again too, but result in no diff so the recursion stops here)

 

This is the "generate docs" workflow:

name: Generate docs

on:
  pull_request:
    branches:
      - '**'
env:
  CI: true
jobs:
  docs:
    runs-on: ubuntu-16.04
    strategy:
      matrix:
        node-version: [12.x]
    steps:
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
          registry-url: 'https://npm.pkg.github.com'
          scope: '@example-org'

      - name: Run npm docs
        run: |
          npm run docs
        env:
          NODE_AUTH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

      - name: Commit files
        run: |
          git config --local user.email "documentation-bot@example.com"
          git config --local user.name "Documentation Bot"
          git diff --quiet && git diff --staged --quiet || git commit -am "Updated docs"

      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          branch: ${{ github.head_ref }}
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

 

The only difference from your scenario @Yanjingzhu is probably the run duration of my tests action?

Highlighted
Solution
GitHub Partner
Message 4 of 5

Re: Workflow not run for action-initiated push to PR using personal access token

@Hihaj The difference  from your scenario and mine is the checkout action version. You are using actions/checkout@v2 . Checkout action uses the default ${{ github.token }} as the credential, and git client will persist credentials in default.

You need to add persist-credentials to false. And then when you push changes, git client will use your PAT instead of github.token.  

    - uses: actions/checkout@v2
      with:
          ref: ${{ github.head_ref }}
          persist-credentials: false

Using PAT to push changes could trigger a new workflow. Please try it and let me know your result. 

Highlighted
Copilot Lvl 3
Message 5 of 5

Re: Workflow not run for action-initiated push to PR using personal access token

It works! Super! Big thanks!