Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Setting points via other actions #52

Open
eric-wieser opened this issue May 28, 2022 · 0 comments
Open

Setting points via other actions #52

eric-wieser opened this issue May 28, 2022 · 0 comments

Comments

@eric-wieser
Copy link

eric-wieser commented May 28, 2022

This is not a feature request, merely a comment to document what seems like undocumented API.

I found I was able to set the "points" manually (instead of actually using education/autograding) via the following script:

      - uses: actions/github-script@v6
        with:
          script: |
            // derived from https://github.com/education/autograding/blob/1d058ce58864938499105ab5cd1c941651ce7e27/src/output.ts
            // Fetch the workflow run
            const workflowRunResponse = await github.rest.actions.getWorkflowRun({
              owner: context.repo.owner,
              repo: context.repo.repo,
              run_id: context.runId,
            })
            const checkSuiteUrl = workflowRunResponse.data.check_suite_url
            const checkSuiteId = parseInt(checkSuiteUrl.match(/[0-9]+$/)[0], 10)
            const checkRunsResponse = await github.rest.checks.listForSuite({
              owner: context.repo.owner,
              repo: context.repo.repo,
              check_name: 'Autograding',
              check_suite_id: checkSuiteId,
            })
            const checkRun = checkRunsResponse.data.total_count === 1 && checkRunsResponse.data.check_runs[0]
            if (!checkRun) return;
            // Update the checkrun, we'll assign the title, summary and text even though we expect
            // the title and summary to be overwritten by GitHub Actions (they are required in this call)
            // We'll also store the total in an annotation to future-proof
            const text = "Points 11/10";
            await github.rest.checks.update({
              owner: context.repo.owner,
              repo: context.repo.repo,
              check_run_id: checkRun.id,
              output: {
                title: 'Autograding',
                summary: text,
                text: text,
                annotations: [
                  {
                    // Using the `.github` path is what GitHub Actions does
                    path: '.github',
                    start_line: 1,
                    end_line: 1,
                    annotation_level: 'notice',
                    message: text,
                    title: 'Autograding complete',
                  },
                ],
              },
            })

Note this makes it possible to accumulate points in other ways, such as using them to indicate the (non-negative integer) result of an optimization problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant