首页 > 解决方案 > Github 对有效的现有工作说“等待状态报告”

问题描述

我有一个 PR,我希望在合并到 master 之前完成某项检查。这是工作 https://github.com/hhimanshu/typescript-serverless-api-vercel/actions/runs/763599870

现在,在 PR 中,它的状态没有被报告。这里是公关

https://github.com/hhimanshu/typescript-serverless-api-vercel/pull/4

我查看了过去在https://github.community/t/expected-waiting-for-status-to-be-reported/18001提出的类似问题,但是,该问题中出现此问题的原因是

在大多数情况下,这是因为您从工作流中删除了作业或更改了作业(重命名),但没有更新分支规则。

但在我的情况下,作业名称相同,并且作业也没有被删除,因此该解决方案不适用。

我的分支保护规则将此工作设为“必需” 在此处输入图像描述

有人可以帮我理解我在这里做错了什么吗?

标签: githubgithub-actions

解决方案


我需要的是一种status使用 Github REST API 进行更新的方法。

# 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 }}"
          }'

之后,PR 在支票中显示链接。链接是https://github.com/hhimanshu/typescript-serverless-api-vercel/pull/4

我从https://github.com/bahmutov/eleventy-example/blob/main/.github/workflows/ci.yml#L27了解到这一点,同时使用https://glebbahmutov.com/blog/develop -预览测试/

在此之后,我看到状态正在按预期更新,并带有一个链接,可将我带到工作

在此处输入图像描述

我希望这对其他人也有帮助


推荐阅读