GitHub Actions Status Check Pending

Viewed 3914

I have a GitHub required status check which gets executed every time a PR is opened/edited/reopened/synchronized to master.

The action itself gets executed successfully, however in the PR window, the check remains forever pending: Expected — Waiting for status to be reported

enter image description here

I have only 1 status check (to simplify the scenario to reproduce the case) and which is checked in the Branch policies for master. There are no other action workflows defined.

My script is:

name: ValidateFlow

on:
  pull_request:
    types: [opened, edited, reopened, synchronize]
    branches: 
      - master
env:
  GITHUB_PR_NUMBER: ${{github.event.pull_request.number}}
  
jobs:
  ValidateFlow:
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v2
      
      - name: Extract branch name
        run: echo "PR_Branch_Name=${{ github.head_ref }}" >> $GITHUB_ENV      
               
      - name: Write to a file
        run: |
                git config --global user.name "my_username"
                git config --global user.email "my_email"

                git fetch
                git checkout "${{ env.PR_Branch_Name }}"

                cd .github
                cat /dev/null > version

                echo 'V1' >> version

                git add version
                git diff-index --quiet HEAD || git commit -m 'Updating the file version'
                git push origin "${{ env.PR_Branch_Name }}"
            
2 Answers

Try adding a name to your workflow job:

jobs:
  ValidateFlow:
    name: ValidateFlow

Try manually setting status with this Github Actions snippet:

# We must set the commit status manually
      # Reference: https://github.com/bahmutov/eleventy-example/blob/main/.github/workflows/ci.yml#L27
      - name: Staging Tests ✅
        if: ${{ success() }}
        # set the merge commit status check
        # using GitHub REST API
        # see https://docs.github.com/en/rest/reference/repos#create-a-commit-status
        run: |
          curl --request POST \
          --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
          --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
          --header 'content-type: application/json' \
          --data '{
            "context": "Staging Tests",
            "state": "success",
            "description": "Staging tests passed",
            "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
          }'
      - name: Staging Tests 
        if: ${{ failure() }}
        # set the merge commit status check
        # using GitHub REST API
        # see https://docs.github.com/en/rest/reference/repos#create-a-commit-status
        run: |
          curl --request POST \
          --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
          --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
          --header 'content-type: application/json' \
          --data '{
            "context": "Staging Tests",
            "state": "failure",
            "description": "Staging tests failed",
            "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
          }'
Related