-
Notifications
You must be signed in to change notification settings - Fork 0
238 lines (222 loc) · 8.97 KB
/
onlabel_lintingPlus.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# Workflow triggered when we have a new release candidate
# This action is adapted from https://github.com/t4d-gmbh/stubbed_versioning
name: On Label Linting and extra checks
on:
pull_request:
types: [ labeled ]
env:
LINT_LABEL_CHECK: 'linting::check'
LINT_LABEL_SUCCESS: 'linting::passed'
LINT_LABEL_FAILURE: 'linting::failed'
URL_LABEL_CHECK: 'URL::check'
URL_LABEL_SUCCESS: 'URL::passed'
URL_LABEL_FAILURE: 'URL::failed'
BUILD_LOC: "./build"
permissions:
packages: read
contents: write
pull-requests: write
repository-projects: write
jobs:
set_target:
# NOTE: Would be nice to not copy it here, however, since env is not accessible
# we would need a prev. job to set it up, which will succeed, leading the
# workflow to be shown as succeeded not skipped
if: ${{ ( github.event.label.name == 'linting::check' ) || ( github.event.label.name == 'URL::check' ) }}
runs-on: ubuntu-latest
outputs:
lint_label: ${{ steps.set_label.outputs.lint_label }}
url_label: ${{ steps.set_label.outputs.url_label }}
steps:
- id: set_label
run: |
echo "lint_label=${{ env.LINT_LABEL_CHECK }}" >> "$GITHUB_OUTPUT"
echo "url_label=${{ env.URL_LABEL_CHECK }}" >> "$GITHUB_OUTPUT"
check_label_exist:
needs:
- set_target
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
permissions:
pull-requests: write
contents: write
strategy:
fail-fast: false
matrix:
# NOTE: would be nicer to not re-define them here, however env is not
# evaluated > would need to go thour the output of a previous job
label:
- 'linting::check'
- 'linting::passed'
- 'linting::failed'
- 'URL::check'
- 'URL::passed'
- 'URL::failed'
steps:
- name: Assert labels ${{ matrix.label }} is defined
run: |
gh label create ${{ matrix.label }} --repo ${{ env.OWNER }}/${{ env.REPO }}
continue-on-error: true # make sure the next steps run also on failure
lint_project:
if: ${{ ( github.event.label.name == needs.set_target.outputs.lint_label ) }}
needs:
- set_target
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- name: Install lintr
run: install.packages("lintr")
shell: Rscript {0}
- name: Lint root directory
run: lintr::lint_dir(linters=lintr::with_defaults(line_length_linter=NULL, infix_spaces_linter=NULL, trailing_whitespace_linter=NULL))
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
report_lint:
if: ${{ ( success() || failure() ) }}
needs:
- lint_project
- check_label_exist
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
repository-projects: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
steps:
- uses: actions/checkout@v4
- name: Report the linting status by label
run: |
gh pr edit ${{ env.EVENT }} --remove-label ${{ env.LINT_LABEL_CHECK }} --repo ${{ env.OWNER }}/${{ env.REPO }}
if [ ${{ needs.lint_project.result }} == "success" ]; then
gh pr edit ${{ env.EVENT }} --remove-label ${{ env.LINT_LABEL_FAILURE }} --repo ${{ env.OWNER }}/${{ env.REPO }}
gh pr edit ${{ env.EVENT }} --add-label ${{ env.LINT_LABEL_SUCCESS }} --repo ${{ env.OWNER }}/${{ env.REPO }}
echo "### ${{ github.event.label.url }} passed! :rocket:" >> $GITHUB_STEP_SUMMARY
exit 0
elif [ ${{ needs.lint_project.result }} == "failure" ]; then
gh pr edit ${{ env.EVENT }} --remove-label ${{ env.LINT_LABEL_SUCCESS }} --repo ${{ env.OWNER }}/${{ env.REPO }}
gh pr edit ${{ env.EVENT }} --add-label ${{ env.LINT_LABEL_FAILURE }} --repo ${{ env.OWNER }}/${{ env.REPO }}
echo "### ${{ github.event.label.url }} failed!" >> $GITHUB_STEP_SUMMARY
exit 1
else
gh pr edit ${{ env.EVENT }} --add-label ${{ env.LINT_LABEL_CHECK }} --repo ${{ env.OWNER }}/${{ env.REPO }}
echo "On demand task outcome was ${{ needs.lint_project.outcome }}"
fi
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EVENT: ${{ github.event.number }} # This is either the issue or pr
URL_check:
runs-on: ubuntu-latest
if: ${{ (github.event.label.name == needs.set_target.outputs.url_label ) }}
needs:
- set_target
name: Run URL checks
# runs-on: ubuntu-latest
container:
image: ${{ vars.CONTAINER_SOURCE || 'ghcr.io/furrer-lab/r-containers' }}/${{ vars.CONTAINER_RELEASE || 'debian/gcc/release' }}/abn:${{ vars.CONTAINER_VERSION || 'latest' }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Disable renv
run: |
renv::deactivate()
shell: Rscript {0}
- name: Check for broken urls and redirects
run: |
library(urlchecker)
uc=url_check("./")
print(uc)
# uc=url_check("./");print(uc);print(uc$Status); if(any(uc$Status=="Error") || any(uc$Status=="403")) {q("no", status=1, FALSE)}
shell: Rscript {0}
report_URL_check:
needs:
- URL_check
- check_label_exist
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
repository-projects: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
steps:
- uses: actions/checkout@v4
- name: Check if on demand tasks succeeded
#TODO: Properly establish what has failead and what not
run: |
gh pr edit ${{ env.EVENT }} --remove-label ${{ env.URL_LABEL_CHECK }} --repo ${{ env.OWNER }}/${{ env.REPO }}
if [ ${{ needs.URL_check.result }} == "success" ]; then
gh pr edit ${{ env.EVENT }} --remove-label ${{ env.URL_LABEL_FAILURE }} --repo ${{ env.OWNER }}/${{ env.REPO }}
gh pr edit ${{ env.EVENT }} --add-label ${{ env.URL_LABEL_SUCCESS }} --repo ${{ env.OWNER }}/${{ env.REPO }}
echo "### ${{ github.event.label.url }} passed! :rocket:" >> $GITHUB_STEP_SUMMARY
exit 0
elif [ ${{ needs.URL_check.result }} == "failure" ]; then
gh pr edit ${{ env.EVENT }} --remove-label ${{ env.URL_LABEL_SUCCESS }} --repo ${{ env.OWNER }}/${{ env.REPO }}
gh pr edit ${{ env.EVENT }} --add-label ${{ env.URL_LABEL_FAILURE }} --repo ${{ env.OWNER }}/${{ env.REPO }}
echo "### ${{ github.event.label.url }} failed!" >> $GITHUB_STEP_SUMMARY
exit 1
else
gh pr edit ${{ env.EVENT }} --add-label ${{ env.URL_LABEL_CHECK }} --repo ${{ env.OWNER }}/${{ env.REPO }}
echo "On demand task outcome was ${{ needs.URL_check.outcome }}"
fi
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EVENT: ${{ github.event.number }} # This is either the issue or pr
record_passed_label:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
permissions:
contents: write
pull-requests: write
repository-projects: write
outputs:
passed: ${{ steps.passed.outputs.PASSED}}
steps:
- name: Check if the pull request is labeled with ${{ env.URL_LABEL_SUCCESS }} # 2
id: passed
run: |
if $( gh pr view ${{ env.EVENT }} --repo ${{ env.OWNER }}/${{ env.REPO }} --json "labels" --jq ".[].[].name" | grep --quiet ${{ env.URL_LABEL_SUCCESS }}); then
echo "PASSED=true" >> $GITHUB_OUTPUT
else
echo "PASSED=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EVENT: ${{ github.event.number }} # This is either the issue or pr
URL_passed:
if: ${{ always() }}
needs:
- URL_check
- record_passed_label
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
steps:
- name: Assert that either checks passed on the label is present
run: |
if [[ ${{ needs.URL_check.result }} == 'success' || ${{ needs.record_passed_label.outputs.passed }} == 'true' ]]; then
echo 'URL status ok';
else exit 1; fi
# NOTE: Currently for the linting there is not check that passes if the label linting::passed is present