Current workflow run disconnects when push --force

According to this troubleshooting in Github page:
https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#example

I prepared separate workflow files with same name and job name:

  • /.github/workflows/feature-branches-build.yml
  • /.github/workflows/i18n-branch-build.yml

feature-branches-build.yml:

name: Feature branch CI
on:
  push:
    branches:
      - 'feature/**'

jobs:
  feature-branch:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16.x

      - name: Cache node modules
        id: cache-nodemodules
        uses: actions/cache@v3
        env:
          cache-name: cache-node-modules
        with:
          # caching node_modules
          path: node_modules
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-
            ${{ runner.os }}-build-
            ${{ runner.os }}-

      - name: Install Dependencies
        if: steps.cache-nodemodules.outputs.cache-hit != 'true'
        run: |
          npm ci
      - name: Code style
        run: |
          npm run prettier
      - name: Lint
        run: |
          npm run lint:all
      - name: Test
        run: |
          npm run test:all
      - name: Build
        run: |
          npm run build

i18n-branch-build.yml:

name: Feature branch CI
on:
  push:
    branches:
      - 'lingohub*'

jobs:
  feature-branch:
    runs-on: ubuntu-latest
    outputs:
      reformat-commit-sha: ${{ steps.push-changes.outputs.reformat-commit-sha }}
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 2
          ref: ${{ github.head_ref }}
      - uses: actions/setup-node@v3
        with:
          node-version: '14'
          cache: 'npm'
          cache-dependency-path: '**/package-lock.json'
      - run: npm install -g prettier
      - name: Formatting files
        run: npm run prettier:i18n
      - name: Check for modified files
        id: git-check
        run: echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)
      - name: Push changes
        id: push-changes
        if: steps.git-check.outputs.modified == 'true'
        run: |
          git config user.name 'Github Actions'
          git config user.email 'github-actions@users.noreply.github.com'
          git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
          git add .
          git commit --amend --no-edit --allow-empty
          git push --force --no-verify
          echo "::set-output name=reformat-commit-sha::$(git rev-parse HEAD)"

      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16.x

      - name: Cache node modules
        id: cache-nodemodules
        uses: actions/cache@v3
        env:
          cache-name: cache-node-modules
        with:
          # caching node_modules
          path: node_modules
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-
            ${{ runner.os }}-build-
            ${{ runner.os }}-

      - name: Install Dependencies
        if: steps.cache-nodemodules.outputs.cache-hit != 'true'
        run: |
          npm ci
      - name: Code style
        run: |
          npm run prettier
      - name: Lint
        run: |
          npm run lint:all
      - name: Test
        run: |
          npm run test:all
      - name: Build
        run: |
          npm run build

The issue:

  1. Push branch lingohub-.... with incorrect formatting
  2. Workflow i18n-branch-build starts.
  3. The required check feature-branch spinning
  4. When workflow does the push --force then the connection between running workflow and the pull request checks - is missing.


After pushing new branch. Everything seems to be ok.

But when workflow completes the push --force:

And the check is out of sync. Even if whole workflow ends with success:

I have no idea why it happens. Any ideas?

I really didn’t know it would do that

I’m surprised by this behavior. Because when i do changes on my local branch lingohub-something and push with force manually → then another, new workflow triggers.

So what is the diference… i don’t know.

The issue is probably that you use the GITHUB_TOKEN to authorize the push. As described in the documentation:

When you use the repository’s GITHUB_TOKEN to perform tasks, events triggered by the GITHUB_TOKEN will not create a new workflow run.

This means your check doesn’t run again for the pushed commit, so it’s not available for the PR.

As a side note, GITHUB_TOKEN or not, you shouldn’t apply a token by embedding it in the URL. The easiest way is to use the token parameter for actions/checkout instead.

@airtower-luna Good point. But it looks like it still doesn’t work.

I’ve removed line:

git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}

Havent added anything to checkout action because default for token parameter is:

# Default: ${{ github.token }}

But still the same problem. Another workflow doesn’t trigger and current one is disconnected from the pull request. So there is feature-branch required job… and nothing happens with that.

As I mentioned in the first part of my post, if you push using the GITHUB_TOKEN your push can’t trigger another workflow run. That’s why the check run is missing: The check doesn’t run again for the new head commit. You need to use a PAT, that’s why I mentioned the token parameter for actions/checkout.

@airtower-luna Oh ok. Now i understand.

I don’t like this approach. Because it’s strictly connected with specific github user but i dig a little bit and found a solution with using “Deploy keys”.

And for action/checkout i use ssh-key parameter.

1 Like