-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
197 lines (180 loc) · 7.65 KB
/
action.yml
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: "action-coveritup"
author: "kevincobain2000"
description: "All in one code coverage solution, build times and custom metrics, comment on pull requests"
branding:
icon: 'activity'
color: 'red'
inputs:
pr_comment:
description: "If true, then comment on the Pull Request"
default: 'false'
type:
description: "Type of score"
types:
description: "Types to report on PR comment. If empty then it will report all types"
diff_types:
description: "Only types to report on PR comment after 1st comment. 1st comment will have all types"
metric:
description: "Metric of score"
command:
description: "Command that outputs int score or want to record the run time"
default: ''
record:
description: "score or time. In case of score the results is used as it is"
default: 'score'
destroy:
description: "Destroy all"
default: 'false'
token:
description: "Github token"
default: '${{ github.token }}'
theme:
description: "Theme of the comment"
default: 'light'
runs:
using: "composite"
steps:
### Start ###
### PREPARE ENVIRONMENT and VARIABLES ###
- uses: credfeto/[email protected]
if: ${{github.api_url == 'https://api.github.com'}}
id: visibility
- name: Do not allow private repos, unless explicitly specified
shell: bash
if: ${{ github.api_url == 'https://api.github.com' && steps.visibility.outputs.is_private == 'true' }}
run: |
echo "Private repos are not supported for Github"
exit 1
- name: Set the host
if: ${{env.COVERITUP_HOST == ''}}
shell: bash
run: echo COVERITUP_HOST="https://coveritup.app" >> "$GITHUB_ENV"
- name: Donot allow self-hosted, if user has forgotten to set the host
shell: bash
if: ${{github.api_url != 'https://api.github.com' && env.COVERITUP_HOST == 'https://coveritup.app'}}
run: |
echo "You must set the host to your own coveritup instance"
exit 1
# Branch names for publication and pull requests comments
- id: branch-name
if: ${{inputs.destroy != 'true'}}
uses: tj-actions/branch-names@v8
- name: Branch name
shell: bash
if: ${{steps.branch-name.outputs.current_branch != ''}}
run: echo BRANCH_OR_TAG_NAME=${{ steps.branch-name.outputs.current_branch }} >> $GITHUB_ENV
- name: Tag name
shell: bash
if: ${{steps.branch-name.outputs.current_branch == ''}}
run: echo BRANCH_OR_TAG_NAME=${{ github.ref }}|sed 's|refs/tags/||' >> $GITHUB_ENV
# Commit Hash
- name: Commit Hash
shell: bash
if: ${{github.event_name == 'pull_request'}}
run: echo COMMIT_HASH=${{ github.event.pull_request.head.sha }} >> $GITHUB_ENV
- name: Commit Hash
if: ${{github.event_name != 'pull_request'}}
shell: bash
run: echo COMMIT_HASH=${{ github.sha }} >> $GITHUB_ENV
# Find the pull request number
- name: pr-number-action
if: ${{github.event_name == 'pull_request'}}
id: pr-number-id
uses: kkak10/[email protected]
# All branch names for this repo seperated by spaces
- name: Extract all active branches
shell: bash
if: ${{inputs.pr_comment != 'true' &&inputs.destroy != 'true'}}
run: |
git config remote.origin.prune true && git fetch
echo ACTIVE_BRANCHES=`git branch -r | grep -v HEAD | sed 's/origin\///' | tr '\n' ' '` >> "$GITHUB_ENV"
### End ###
### PREPARE ENVIRONMENT and VARIABLES ###
### Start ###
### Execute Commands ###
- name: Set Score as it is
if: ${{inputs.record == 'score'}}
shell: bash
run: |
echo SCORE=`${{ inputs.command }}` >> "$GITHUB_ENV"
- name: Set Score for runtime
if: ${{inputs.record == 'runtime'}}
shell: bash
run: |
START=$SECONDS
eval ${{ inputs.command }}
echo SCORE=$(($SECONDS-START)) >> "$GITHUB_ENV"
### End ###
### Execute Commands ###
### Start ###
### PUBLISHING ###
# Will create a new type if not exists for metric.
# If type exists, then it will use the existing metric and ignore the metric passed
- name: Publish this output and update branches
if: ${{inputs.pr_comment != 'true' && inputs.destroy != 'true'}}
shell: bash
run: |
curl -Lk --fail \
-X POST \
-x "${{ env.COVERITUP_HTTP_PROXY }}" \
-H 'Content-Type: application/json' \
-H 'Authorization: ${{ inputs.token }}' \
-d '{
"org": "${{github.repository_owner}}",
"commit": "${{ env.COMMIT_HASH }}",
"repo": "${{ github.event.repository.name }}",
"type": "${{ inputs.type }}",
"metric": "${{ inputs.metric }}",
"score": "${{ env.SCORE }}",
"user": "${{ github.actor }}",
"branch": "${{ env.BRANCH_OR_TAG_NAME }}",
"pr_num": "${{ steps.pr-number-id.outputs.pr }}",
"branches": "${{ env.ACTIVE_BRANCHES }}"
}' \
"${{env.COVERITUP_HOST}}/upload"
# Prepare comment on PR if it is a pull req
- name: Prepare comment on PR if it is a pull req
if: ${{inputs.pr_comment == 'true' && github.event_name == 'pull_request' && steps.branch-name.outputs.base_ref_branch != ''}}
shell: bash
run: |
response=$(curl -Lk \
-X GET \
-x "${{ env.COVERITUP_HTTP_PROXY }}" \
-H 'Content-Type: application/json' \
-w "%{http_code}" \
"${{env.COVERITUP_HOST}}/pr?org=${{github.repository_owner}}&repo=${{ github.event.repository.name }}&types=${{ inputs.types }}&diff_types=${{ inputs.diff_types }}&theme=${{ inputs.theme }}&pr_num=${{ steps.pr-number-id.outputs.pr }}&branch=${{ env.BRANCH_OR_TAG_NAME }}&base_branch=${{ steps.branch-name.outputs.base_ref_branch }}" \
-o comment_body.txt)
echo "PR_HTTP_RESPONSE=$response" >> $GITHUB_ENV
# Comment on PR if it is a pull req and the status code is 201
# Won't work on forks https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#restrictions-on-repository-forks
- name: Comment on PR if it is a pull req
if: ${{inputs.pr_comment == 'true' && github.event_name == 'pull_request' && steps.branch-name.outputs.base_ref_branch != '' && env.PR_HTTP_RESPONSE == '201' && github.event.pull_request.head.repo.full_name == github.repository }}
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ steps.pr-number-id.outputs.pr }}
body-path: comment_body.txt
token: ${{ inputs.token }}
### END ###
### PUBLISHING ###
### Start ###
### Compliance ###
# Destroy everything or just by the type
# if type is empty then it will destroy everything
- name: Destroy everything that was ever published
if: ${{inputs.destroy == 'true'}}
shell: bash
run: |
curl -Lk --fail \
-X POST \
-x "${{ env.COVERITUP_HTTP_PROXY }}" \
-H 'Content-Type: application/json' \
-H 'Authorization: ${{ inputs.token }}' \
-d '{
"org": "${{github.repository_owner}}",
"repo": "${{ github.event.repository.name }}",
"type": "${{ inputs.type }}",
"commit": "${{ env.COMMIT_HASH }}"
}' \
"${{env.COVERITUP_HOST}}/destroy"
### End ###
### Compliance ###