DEV Community

Discussion on: GitHub actions: how to push a GitHub status in addition of GitHub checks

Collapse
 
twisterrob profile image
Róbert Papp • Edited

There's a simpler way with more control, because
1) it's JavaScript, not a text-substituted curl command.
2) it uses GitHub API with auth built in.
3) first party GitHub Action
4) using checks.create rather then status.create for more control (output)

      - name: "Create a check run"
        uses: actions/github-script@v6
        env:
          parameter_url: '${{ github.event.workflow_run.html_url }}'
        with:
          debug: ${{ secrets.ACTIONS_STEP_DEBUG || false }}
          script: |
            // any JavaScript code can go here, you can use Node JS APIs too.
            // Docs: https://docs.github.com/en/rest/checks/runs#create-a-check-run
            // Rest: https://octokit.github.io/rest.js/v18#checks-create
            await github.rest.checks.create({
              owner: context.repo.owner,
              repo: context.repo.repo,
              head_sha: context.sha,
              name: "my-check-name",
              status: "completed",
              // Careful, code injection can happen.
              conclusion: "${{ github.event.workflow_run.conclusion }}",
              // This is safe, not string interpolation.
              details_url: process.env.parameter_url,
              output: {
                title: "my check title",
                summary: "my *check* summary",
                text: "my text",
              },
            });
Enter fullscreen mode Exit fullscreen mode

and how it looks: