-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (62 loc) · 2.4 KB
/
R-CMD-check-status.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Workflow to update the status of a commit for the R-CMD-check workflow
# Necessary because remote PRs cannot update the status of the commit
on:
workflow_run:
workflows:
- rcc
types:
- requested
- completed
name: rcc-status
jobs:
rcc-status:
runs-on: ubuntu-latest
name: "Update commit status"
steps:
- name: "Update commit status"
# Only run if triggered by rcc workflow
if: github.event.workflow_run.name == 'rcc'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -x
if [ "${{ github.event.workflow_run.status }}" == "completed" ]; then
if [ "${{ github.event.workflow_run.conclusion }}" == "success" ]; then
state="success"
else
state="failure"
fi
# Read artifact ID
artifact_id=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts | jq -r '.artifacts[] | select(.name == "rcc-smoke-sha") | .id')
if [ -n "${artifact_id}" ]; then
# Download artifact
curl -L -o rcc-smoke-sha.zip \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/actions/artifacts/${artifact_id}/zip
# Unzip artifact
unzip rcc-smoke-sha.zip
# Read artifact
sha=$(cat rcc-smoke-sha.txt)
# Clean up
rm rcc-smoke-sha.zip rcc-smoke-sha.txt
fi
else
state="pending"
fi
if [ -z "${sha}" ]; then
sha=${{ github.event.workflow_run.head_sha }}
fi
html_url=${{ github.event.workflow_run.html_url }}
description=${{ github.event.workflow_run.name }}
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
repos/${{ github.repository }}/statuses/${sha} \
-f "state=${state}" -f "target_url=${html_url}" -f "description=${description}" -f "context=rcc"
shell: bash