-
Notifications
You must be signed in to change notification settings - Fork 13
232 lines (193 loc) · 9.32 KB
/
downstream-tests-on-comment.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
name: downstream-tests-on-comment
# This workflow is triggered by the comment '/test-downstream' inside a PR
# The workflow then:
# 1. modifies the original comment into:
# """
# /test-downstream
#
# Automatic edit:
# Running downstream tests for commit <commit>, follow the run [here](<link>).
# """
# 2. runs the unit test of all common modules with the last commit before that comment
# 3. replies in a comment with which modules/ OSes failed (successes are omitted).
on:
issue_comment:
types:
- created
jobs:
pr-info:
if: ${{ github.event.issue.pull_request && github.event.comment.body == '/test-downstream'}}
runs-on: ubuntu-latest
outputs:
commit: ${{ steps.get-commit.outputs.commit }}
steps:
- name: Get PR info
id: get-pr-info
uses: actions/github-script@v5
with:
script: |
const { owner, repo, number } = context.issue;
const pr = await github.rest.pulls.get({
owner,
repo,
pull_number: number,
});
// console.log(pr) // for debugging
return pr
- name: Print metadata and set PR SHA
id: get-commit
env:
pr_info: ${{ steps.get-pr-info.outputs.result }}
run: |
# this step is mainly there for debugging
base=$(echo ${pr_info} | jq '.data["base"]["label"]')
head=$(echo ${pr_info} | jq '.data["head"]["label"]')
commit=$(echo ${pr_info} | jq -r '.data["head"]["sha"]')
printf '%-15s: %s\n' \
repository ${{ github.event.repository.name }} \
base ${base} \
head ${head} \
commit ${commit} \
github.sha ${{ github.sha }} \
comment ${{ github.event.comment.html_url }} \
echo "::set-output name=commit::${commit}"
shell: bash
- name: Update initial comment
uses: actions/github-script@v5
with:
script: |
body = "${{ github.event.comment.body }}".concat("\n\nAutomatic edit:\nRunning downstream tests for commit ${{ steps.get-commit.outputs.commit }}, follow the run [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).");
console.log(body);
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ github.event.comment.id }},
body: body
});
unit-tests:
runs-on: ${{ matrix.os }}
# this might not be necessary, but it's more user friendly if the comment is edited first (otherwise pr-info and unit-tests run concurrently).
needs: pr-info
continue-on-error: true
name: ${{ matrix.os }} (${{ matrix.r }} (${{ matrix.module }})
strategy:
fail-fast: false
matrix:
r: [4.3.1]
os: [ubuntu-latest, macOS-latest, windows-latest]
# only common modules
module: [jasp-stats/jaspDescriptives, jasp-stats/jaspTTests, jasp-stats/jaspAnova, jasp-stats/jaspRegression, jasp-stats/jaspFrequencies, jasp-stats/jaspFactor]
# for debugging
# os: [ubuntu-latest]
# module: [jasp-stats/jaspDescriptives, jasp-stats/jaspTTests]
# # outputs is generated with the following R code. It does not matter if some outputs are unused.
# oses <- c("ubuntu-latest", "macOS-latest", "windows-latest")
# modules <- c("jasp-stats/jaspDescriptives", "jasp-stats/jaspTTests", "jasp-stats/jaspAnova", "jasp-stats/jaspRegression", "jasp-stats/jaspFrequencies", "jasp-stats/jaspFactor")
# base <- " %1$s-%2$s: ${{ steps.update-output.outputs.%1$s-%2$s }}"
# for (os in oses) for (module in modules)
# cat(sprintf(base, os, basename(module)), "\n")
outputs:
ubuntu-latest-jaspDescriptives: ${{ steps.update-output.outputs.ubuntu-latest-jaspDescriptives }}
ubuntu-latest-jaspTTests: ${{ steps.update-output.outputs.ubuntu-latest-jaspTTests }}
ubuntu-latest-jaspAnova: ${{ steps.update-output.outputs.ubuntu-latest-jaspAnova }}
ubuntu-latest-jaspRegression: ${{ steps.update-output.outputs.ubuntu-latest-jaspRegression }}
ubuntu-latest-jaspFrequencies: ${{ steps.update-output.outputs.ubuntu-latest-jaspFrequencies }}
ubuntu-latest-jaspFactor: ${{ steps.update-output.outputs.ubuntu-latest-jaspFactor }}
macOS-latest-jaspDescriptives: ${{ steps.update-output.outputs.macOS-latest-jaspDescriptives }}
macOS-latest-jaspTTests: ${{ steps.update-output.outputs.macOS-latest-jaspTTests }}
macOS-latest-jaspAnova: ${{ steps.update-output.outputs.macOS-latest-jaspAnova }}
macOS-latest-jaspRegression: ${{ steps.update-output.outputs.macOS-latest-jaspRegression }}
macOS-latest-jaspFrequencies: ${{ steps.update-output.outputs.macOS-latest-jaspFrequencies }}
macOS-latest-jaspFactor: ${{ steps.update-output.outputs.macOS-latest-jaspFactor }}
windows-latest-jaspDescriptives: ${{ steps.update-output.outputs.windows-latest-jaspDescriptives }}
windows-latest-jaspTTests: ${{ steps.update-output.outputs.windows-latest-jaspTTests }}
windows-latest-jaspAnova: ${{ steps.update-output.outputs.windows-latest-jaspAnova }}
windows-latest-jaspRegression: ${{ steps.update-output.outputs.windows-latest-jaspRegression }}
windows-latest-jaspFrequencies: ${{ steps.update-output.outputs.windows-latest-jaspFrequencies }}
windows-latest-jaspFactor: ${{ steps.update-output.outputs.windows-latest-jaspFactor }}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.pr-info.outputs.commit }}
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.r }}
- name: clone module ${{ matrix.module }}
run: git clone "https://github.com/${{ matrix.module }}.git"
shell: bash
- uses: jasp-stats/jasp-actions/setup-test-env@master
- name: Install igraph from source
if: ${{ matrix.os == 'ubuntu-latest' && matrix.module == 'jasp-stats/jaspFactor' }}
run: install.packages("igraph", type = "source", repos = "https://cloud.r-project.org")
shell: Rscript {0}
- name: Install ${{ github.event.repository.name }}
run: remotes::install_local(".")
shell: Rscript {0}
- name: Run unit tests
run: |
setwd(basename("${{ matrix.module }}"))
source("tests/testthat.R")
shell: Rscript {0}
# - name: fake unit tests for debugging
# run: |
# if [ ${{ matrix.module }} == 'jasp-stats/jaspDescriptives' ]; then
# exit 1
# fi
# shell: bash
- name: set error if tests fail
id: update-output
if: ${{ failure() }}
run: |
moduleName=$(basename ${{ matrix.module }})
nm="${{ matrix.os }}-${moduleName}"
echo "nm = $nm"
echo "::set-output name=${nm}::error"
shell: bash
report-results:
runs-on: ubuntu-latest
needs: [pr-info, unit-tests]
steps:
- name: Aggregate results & post comment output
id: aggregated-results
env:
NEEDS: ${{ toJSON(needs) }}
uses: actions/github-script@v5
with:
script: |
const { NEEDS } = process.env
console.log(`${NEEDS}`)
results=JSON.parse(NEEDS);
console.log(results)
outputs=results["unit-tests"]["outputs"];
for (const prop in outputs) { console.log(`${prop}: ${outputs[prop]}`);}
if (Object.keys(outputs).length === 0) {
console.log("All downstream tests succeeded")
body = "All downstream tests for commit ${{ needs.pr-info.outputs.commit }} succeeded! ✅"
} else {
console.log("Some unit tests failed")
obj = {}; // dict from module to os
for (const key in outputs) {
var [os, module] = key.split(/\-(?=[^\-]+$)/);
console.log(os, "|", module)
if (!(module in obj))
obj[module] = new Set();
obj[module].add(os);
}
body = "The following downstream tests for commit ${{ needs.pr-info.outputs.commit }} failed:\n| Module | windows-latest | macOS-latest | ubuntu-latest |\n| ---: | :---: | :---: | :---: |"
oses = ["windows-latest", "macOS-latest", "ubuntu-latest"];
for (const module in obj) {
str = "\n| ".concat(module, " | ", oses.map(os => obj[module].has(os) ? "❌" : "✅").join(" | "));
body = body.concat(str);
console.log(body)
}
}
body = body.concat("\n\nThe full log is available [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).")
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body,
});