name: CommitStatusEnd
description: 'Adds a commit status at the end of the test run based on success, failure, or cancelled'
inputs:
  name:
    description: "Name of the check"
    required: true
  git_ref:
    description: "The git commit, tag, or branch to check out. Requires a corresponding Karpenter snapshot release"
    required: true
runs:
  using: "composite"
  steps:
    - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
      if: job.status == 'success'
      env:
        NAME: ${{ inputs.name }}
        SHA: ${{ inputs.git_ref }}
        REPO: ${{ github.repository }}
        RUN_ID: ${{ github.run_id }}
      with:
        script: |
          github.rest.repos.createCommitStatus({
            owner: context.repo.owner,
            repo: context.repo.repo,
            context: process.env.NAME,
            sha: process.env.SHA,
            state: "success",
            target_url: `https://github.com/${process.env.REPO}/actions/runs/${process.env.RUN_ID}`,
          });
    - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
      if: job.status == 'failure' || job.status == 'cancelled'
      env:
        NAME: ${{ inputs.name }}
        SHA: ${{ inputs.git_ref }}
        REPO: ${{ github.repository }}
        RUN_ID: ${{ github.run_id }}
      with:
        script: |
          github.rest.repos.createCommitStatus({
            owner: context.repo.owner,
            repo: context.repo.repo,
            context: process.env.NAME,
            sha: process.env.SHA,
            state: "failure",
            target_url: `https://github.com/${process.env.REPO}/actions/runs/${process.env.RUN_ID}`,
          });
