generated from JJ/plantilla-IV
-
Notifications
You must be signed in to change notification settings - Fork 31
230 lines (228 loc) · 10.4 KB
/
source-tests.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
name: "Tests sobre fuentes/API del repo del estudiante"
on:
pull_request_target:
paths:
- "proyectos/*.md"
permissions:
pull-requests: write
jobs:
ops-on-pr:
runs-on: ubuntu-latest
outputs:
user: ${{steps.pr_info.outputs.user}}
repo: ${{steps.pr_info.outputs.repo}}
checkout_repo: ${{steps.pr_info.outputs.checkout_repo}}
objetivo: ${{steps.pr_info.outputs.objetivo}}
rama: ${{steps.pr_info.outputs.rama}}
pr_milestone: ${{steps.pr_info.outputs.pr_milestone}}
pull_number: ${{steps.pr_info.outputs.pull_number}}
steps:
- id: pr_info
name: Comprueba y analiza
uses: JJ/grading-pr-info-gh-action@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ops-on-source:
runs-on: ubuntu-latest
outputs:
docker_user: ${{steps.source-tests.outputs.docker_user}}
needs: ops-on-pr
env:
user: ${{ needs.ops-on-pr.outputs.user }}
repo: ${{ needs.ops-on-pr.outputs.repo }}
checkout_repo: ${{ needs.ops-on-pr.outputs.checkout_repo }}
objetivo: ${{ needs.ops-on-pr.outputs.objetivo }}
rama: ${{ needs.ops-on-pr.outputs.rama }}
steps:
- name: Descarga fuente
uses: actions/checkout@v4
with:
repository: ${{env.checkout_repo}}
ref: ${{env.rama}}
- name: Tests sobre fuentes
id: source-tests
with:
fase: ${{env.objetivo}}
uses: JJ/grading-source-tests-gh-action@main
- name: Testea contenedor
if: ${{env.objetivo >= 5 }}
env:
CONTAINER: ${{ env.docker_user }}/${{ env.repo }}
run: docker run -t -v `pwd`:/app/test ${CONTAINER,,}
- name: Testea API
if: ${{env.objetivo >= 9 }}
env:
CONTAINER: ${{ env.docker_user }}/${{ env.repo }}
ORDEN: ${{env.ORDEN}}
run: docker run -t -v `pwd`:/app/test --entrypoint="" ${CONTAINER,,} sh -c "${ORDEN} build && ${ORDEN} install && ${ORDEN} test"
ops-using-API:
runs-on: ubuntu-latest
needs: ops-on-pr
env:
user: ${{ needs.ops-on-pr.outputs.user }}
repo: ${{ needs.ops-on-pr.outputs.repo }}
objetivo: ${{ needs.ops-on-pr.outputs.objetivo }}
pr_milestone: ${{ needs.ops-on-pr.outputs.pr_milestone }}
rama: ${{ needs.ops-on-pr.outputs.rama }}
steps:
- name: Descarga fuente
uses: actions/checkout@v4
- name: Comprueba que el PR está asignado a un milestone
uses: actions/github-script@v5
if: ${{env.objetivo >= 2}}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const {all_good, sorry } = require("./lib/mensajes.js")
const milestone = process.env.pr_milestone
if ( milestone === "" ) {
core.setFailed( sorry( "El PR tiene que estar asignado a un milestone") )
} else {
console.log( all_good(`PR asignado al milestone ${milestone}`))
}
- name: Comprueba hitos desde el 1
uses: actions/github-script@v5
if: ${{ env.objetivo >= 1 }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const {objetivo_msg, all_good, sorry } = require("./lib/mensajes.js")
const user = process.env.user
const repo = process.env.repo
const objetivo = process.env.objetivo
console.log( objetivo_msg(1) )
const milestones = await github.rest.issues.listMilestones( { owner: user, repo: repo } )
if ( ! milestones.data.length ) {
core.setFailed( sorry( "Tiene que haber por lo menos un milestone") )
}
const minMilestones = 2
if ( minMilestones && milestones.data.length < minMilestones ) {
core.setFailed( sorry("Tendría que haber más de " + minMilestones + " milestone(s)"));
}
var totalIssues = 0
var totalClosedIssues = 0
milestones.data.forEach( async function( milestone ) {
totalIssues += milestone.open_issues + milestone.closed_issues
totalClosedIssues += milestone.closed_issues
})
console.log( all_good("Hay " + totalIssues + " issues en tus milestones y " + totalClosedIssues + " cerrados "))
if ( ! totalIssues ) {
core.setFailed( sorry("No hay ningún issue en tus milestones"))
}
const non_paginated_issues =
await github.rest.issues.listForRepo.endpoint.merge( { owner: user, repo: repo, state: 'all' })
const issues = await github.paginate( non_paginated_issues )
const hus = issues.filter( issue => issue.title.match(/^\[HU/) )
if ( !hus.length ) {
core.setFailed( sorry("No hay historias de usuario, o el título no incluye «[HUxxx]»"))
}
let closed_issues;
if ( objetivo >= 2 ) {
console.log( objetivo_msg(2) )
const real_issues = issues.length - hus.length
if ( !real_issues ) {
core.setFailed( sorry("No hay issues fuera de las historias de usuario; los issues son imprescindibles para avanzar el código"))
} else {
console.log( all_good(`Hay ${real_issues} issues no-HU`))
}
closed_issues = issues.filter( issue => issue.state === "closed" )
closed_issues.forEach( async function( issue ) {
if ( ! issue.pull_request ) {
const query = `query($owner:String!, $name:String!, $issue:Int!) {
repository(name: $name , owner: $owner ) {
issue(number: $issue) {
timelineItems(itemTypes: CLOSED_EVENT, last: 1) {
nodes {
... on ClosedEvent {
closer {
__typename
}
}
}
}
}
}
}`;
const variables = {
owner: user,
name: repo,
issue: issue.number
}
const result = await github.graphql(query, variables)
if ( result.repository.issue.timelineItems.nodes[0].closer != null ) {
const closingEvent = result.repository.issue.timelineItems.nodes[0].closer.__typename
if ( (closingEvent == 'Commit') || (closingEvent == 'PullRequest') ) {
console.log(all_good("El issue " + issue.number + " se 🔒 con un " + closingEvent ))
} else {
core.setFailed( sorry("El issue " + issue.number + " no se cerró con un commit o PR"))
}
} else {
console.log( sorry(" El issue " + issue.number + " no está cerrado aunque aparece en la lista de tales " ))
}
}
})
}
- name: Comprueba el estado de CI
if: ${{env.objetivo >= 6 }}
uses: actions/github-script@v5
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const {objetivo_msg, all_good, sorry } = require("./lib/mensajes.js")
const { user, repo, rama } = process.env
console.log( objetivo_msg(6) )
console.log( "» Analizando repo " + repo + " del usuario 🔥" + user )
const all_checks_before_pag =
await github.rest.checks.listForRef.endpoint.merge(
{ owner: user,
repo: repo,
ref: rama,
})
console.log( "Checks before pag→ ", all_checks_before_pag)
const all_checks = await github.paginate( all_checks_before_pag)
console.log( "Checks → ", all_checks)
const checks_before_pag =
await github.rest.checks.listForRef.endpoint.merge(
{ owner: user,
repo: repo,
ref: rama,
status: 'completed'
})
const checks = await github.paginate( checks_before_pag)
console.log( "Checks → ", checks)
if ( checks.length < 1 ) {
core.setFailed( sorry("No hay suficientes sistemas de CI configurados"))
} else {
console.log( all_good("✅ Hay " + checks.length + " sistemas de CI configurados"))
}
const green_checks = checks.filter( check => check.conclusion === "success" )
if ( !green_checks.length ) {
core.setFailed(sorry("No hay al menos un CI que esté en verde"))
} else {
console.log( all_good("Hay " + green_checks.length + " que pasa(n) los tests correctamente" ))
}
console.log("CIs en verde ", green_checks );
const mandatory_checks_green = green_checks.filter( check => (check.app.slug === "travis-ci") || (check.app.slug === "github-actions") || (check.app.slug === "circleci-checks" ))
if ( mandatory_checks_green.length == 0 ) {
core.setFailed(sorry("No hay ninguno de los CIs autorizados funcionando con el último commit"))
} else {
console.log( all_good("Hay alguno de los autorizados funcionando" ))
}
random-revisor:
runs-on: ubuntu-latest
needs: [ops-on-pr, ops-on-source, ops-using-API]
if: needs.ops-on-pr.outputs.objetivo >= 1
env:
user: ${{ needs.ops-on-pr.outputs.user }}
repo: ${{ needs.ops-on-pr.outputs.repo }}
pull_number: ${{ needs.ops-on-pr.outputs.pull_number }}
this_pr_number: ${{github.event.number}}
COMMENT_TOKEN: ${{ secrets.COMMENT_TOKEN }}
objetivo: ${{ needs.ops-on-pr.outputs.objetivo }}
steps:
- name: Fuentes de este repo (para JSON)
uses: actions/checkout@v4
- name: Paquete no fatpackeado
run: sudo apt install liblwp-protocol-https-perl
- name: Revisores aleatorios
run: scripts/random-reviewer