|
| 1 | +name: Post Check Run |
| 2 | + |
| 3 | +description: Posts a GitHub Check Run after uploading artifacts to S3 |
| 4 | + |
| 5 | +inputs: |
| 6 | + sha: |
| 7 | + description: SHA of the commit to check |
| 8 | + required: true |
| 9 | + repo: |
| 10 | + description: GitHub repository (owner/repo) |
| 11 | + required: true |
| 12 | + s3_location: |
| 13 | + description: S3 location for the artifacts |
| 14 | + required: true |
| 15 | + APPID: |
| 16 | + description: GitHub App ID |
| 17 | + required: true |
| 18 | + PVK: |
| 19 | + description: GitHub App private key |
| 20 | + required: true |
| 21 | + |
| 22 | +runs: |
| 23 | + using: "composite" |
| 24 | + steps: |
| 25 | + - name: Generate access token |
| 26 | + uses: actions/create-github-app-token@v2 |
| 27 | + id: app-token |
| 28 | + with: |
| 29 | + app-id: ${{ inputs.APPID }} |
| 30 | + private-key: ${{ inputs.PVK }} |
| 31 | + owner: ${{ github.repository_owner }} |
| 32 | + |
| 33 | + - name: Post check run |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + set -e |
| 37 | +
|
| 38 | + HEAD_SHA="${{ inputs.sha }}" |
| 39 | + ACCESS_TOKEN="${{ steps.app-token.outputs.token }}" |
| 40 | + s3_location="${{ inputs.s3_location }}" |
| 41 | + REPO="${{ inputs.repo }}" |
| 42 | +
|
| 43 | + echo "Creating check run for commit: $HEAD_SHA" |
| 44 | + CHECK_RUN_ID=$(curl -s -L -X POST \ |
| 45 | + -H "Accept: application/vnd.github+json" \ |
| 46 | + -H "Authorization: Bearer $ACCESS_TOKEN" \ |
| 47 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 48 | + https://api.github.com/repos/$REPO/check-runs \ |
| 49 | + -d '{ |
| 50 | + "name": "Artifacts uploaded to S3", |
| 51 | + "head_sha": "'"$HEAD_SHA"'", |
| 52 | + "status": "in_progress", |
| 53 | + "output": { |
| 54 | + "title": "Check S3 Location", |
| 55 | + "summary": "", |
| 56 | + "text": "'"$s3_location"'" |
| 57 | + } |
| 58 | + }' | jq -r '.id') |
| 59 | +
|
| 60 | + if [ -z "$CHECK_RUN_ID" ]; then |
| 61 | + echo "Failed to create check run. Exiting." |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | +
|
| 65 | + echo "Check run created with ID: $CHECK_RUN_ID" |
| 66 | +
|
| 67 | + echo "Updating check run to completed status..." |
| 68 | + curl -s -L -X PATCH \ |
| 69 | + -H "Accept: application/vnd.github+json" \ |
| 70 | + -H "Authorization: Bearer $ACCESS_TOKEN" \ |
| 71 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 72 | + https://api.github.com/repos/$REPO/check-runs/$CHECK_RUN_ID \ |
| 73 | + -d '{ |
| 74 | + "name": "Artifacts uploaded to S3", |
| 75 | + "head_sha": "'"$HEAD_SHA"'", |
| 76 | + "status": "completed", |
| 77 | + "conclusion": "success", |
| 78 | + "output": { |
| 79 | + "title": "Check S3 Location", |
| 80 | + "summary": "", |
| 81 | + "text": "'"$s3_location"'" |
| 82 | + } |
| 83 | + }' |
| 84 | +
|
| 85 | + echo "Check run updated successfully." |
0 commit comments