forked from eclipse-platform/www.eclipse.org-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (50 loc) · 1.94 KB
/
checkAcknowledgements.yml
File metadata and controls
53 lines (50 loc) · 1.94 KB
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
name: Check acknowledgements consistency
on:
pull_request:
paths:
- news/*/acknowledgements.md
permissions:
contents: read
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Determine changed files
id: changed-files
run: |
changedFiles=$(git diff --name-only --diff-filter=ACMR ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep acknowledgements.md$ | xargs)
echo "Changed files: ${changedFiles}"
echo "files=${changedFiles}" >> "$GITHUB_OUTPUT"
- name: Check modified acknowledgements files
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
id: collect-contributors
with:
script: |
const fs = require('fs')
const files = '${{ steps.changed-files.outputs.files }}'.trim().split(/\s+/)
const nameIdRegex = /\[(?<name>[^\]]+)\]\(https:\/\/github\.com\/(?<id>[^\)/]+)\)/g
for (file of files) {
let lines = fs.readFileSync(file, {encoding: 'utf8'}).split(/\r?\n/)
const contributorNames = new Map()
for (line of lines) {
for (match of line.matchAll(nameIdRegex)) {
computeIfAbsent(contributorNames, match.groups.id, () => new Set()).add(match.groups.name)
}
}
for (const [profile, names] of contributorNames) {
if (names.size > 1) {
core.setFailed("Multiple names found for profile '" + profile + "': " + Array.from(names).join(', '))
}
}
}
function computeIfAbsent(map, key, valueSupplier) {
let value = map.get(key)
if (!value) {
value = valueSupplier()
map.set(key, value)
}
return value
}