Git actions on push only works for my user

Hi everyone!

I’ve created a very simple workflow in Github Actions. It is merged already to the main branch and it works fine for my user.

It always trigger when I open / reopen a PR, or when I push commits to my branch.

For my workmates however, who all are members of the same repo, and have same accesses I do, this Action only ever triggers upon a PR opening, but never when they push code to their branches.

I can’t figure out why that’s the case.

I have some further logic in the job defined within the workflow, to make sure it only runs each step if a PR is pre-existent, but I guess this is irrelevant, since the Action should be triggered regardless of what conditionals I set there.

Here is the workflow:

name: CI

on:
  # Trigger the workflow on push or pull request
  push:
    branches: ['*']
  pull_request:
    types: [opened, reopened]
    branches: ['*']

jobs:
  test_react_app:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [16.x]

    steps:
      - uses: jwalton/gh-find-current-pr@v1.2.0
        id: findPr
        with:
          state: open
          
      - uses: actions/checkout@v2
        with:
          node-version: ${{ matrix.node-version }}

      - uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}

      - name: npm install
        if: ${{ steps.findPr.outputs.pr || github.event.pull_request.number }}
        run: npm ci

      - name: compile TS and check for errors
        if: ${{ steps.findPr.outputs.pr || github.event.pull_request.number }}
        run: npx tsc --noEmit

      - name: run tests
        if: ${{ steps.findPr.outputs.pr || github.event.pull_request.number }}
        run: |
          npm run lint
          npm run test
          npm run integration

Any ideas why this is happening?

Do they have /s in their branch names?

1 Like

Yes… looks like you just found the culprit! Thx!

Strange enough that this would still trigger for the PR opening event, so I didn’t think of that!

I just re-tested with:

push:
    branches: ['*', '*/*']

which seems to fix that. Is there a better approach to guarantee this will work for any amount of /s used in the branch name?

I guess ['**'] would be the best choice!

1 Like

I think that this is a union:

pull_request:
    types: [opened, reopened]
    branches: ['*']

Which is why you got the open events.

And yes, '**' is the solution.

1 Like