Skip to content

Commit 1aa30f7

Browse files
committed
Consider already existing names in acknowledgements generation
This avoids repeated resolution of name-inconsistencies and preserves already applied name corrections.
1 parent 578d85a commit 1aa30f7

File tree

2 files changed

+75
-6
lines changed

2 files changed

+75
-6
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Check acknowledgements consistency
2+
on:
3+
pull_request:
4+
paths:
5+
- news/*/acknowledgements.md
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
validate:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
15+
with:
16+
fetch-depth: 0
17+
- name: Determine changed files
18+
id: changed-files
19+
run: |
20+
changedFiles=$(git diff --name-only --diff-filter=ACMR ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep acknowledgements.md$ | xargs)
21+
echo "Changed files: ${changedFiles}"
22+
echo "files=${changedFiles}" >> "$GITHUB_OUTPUT"
23+
- name: Check modified acknowledgements files
24+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
25+
id: collect-contributors
26+
with:
27+
script: |
28+
const fs = require('fs')
29+
const files = '${{ steps.changed-files.outputs.files }}'.trim().split(/\s+/)
30+
const nameIdRegex = /\[(?<name>[^\]]+)\]\(https:\/\/github\.com\/(?<id>[^\)/]+)\)/g
31+
for (file of files) {
32+
let lines = fs.readFileSync(file, {encoding: 'utf8'}).split(/\r?\n/)
33+
const contributorNames = new Map()
34+
for (line of lines) {
35+
for (match of line.matchAll(nameIdRegex)) {
36+
computeIfAbsent(contributorNames, match.groups.id, () => new Set()).add(match.groups.name)
37+
}
38+
}
39+
for (const [profile, names] of contributorNames) {
40+
if (names.size > 1) {
41+
core.setFailed("Multiple names found for profile '" + profile + "': " + Array.from(names).join(', '))
42+
}
43+
}
44+
}
45+
46+
function computeIfAbsent(map, key, valueSupplier) {
47+
let value = map.get(key)
48+
if (!value) {
49+
value = valueSupplier()
50+
map.set(key, value)
51+
}
52+
return value
53+
}

.github/workflows/generateAcknowledgements.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
profile = committerProfile
128128
}
129129
contributors.add(profile)
130-
computeIfAbsent(contributorNames, profile, () => new Set()).add(authorName)
130+
computeIfAbsent(contributorNames, profile, () => new Set()).add(authorName.trim())
131131
} else { // author is null for directly pushed commits, which happens e.g. for I-build submodule updates
132132
console.log("Skip commit of " + authorName)
133133
}
@@ -137,15 +137,34 @@ jobs:
137137
console.log('Processed commits: ' + commitCount)
138138
}
139139
140+
// ------------------------------------------------------
141+
// Read existing names
142+
// ------------------------------------------------------
143+
const fs = require('fs')
144+
const acknowledgementsFile = 'website/news/${{ inputs.eclipse-version }}/acknowledgements.md'
145+
let lines = fs.readFileSync(acknowledgementsFile, {encoding: 'utf8'}).split(/\r?\n/)
146+
147+
const nameIdRegex = /\[(?<name>[^\]]+)\]\(https:\/\/github\.com\/(?<id>[^\)/]+)\)/g
148+
const existingContributorNames = new Map()
149+
for (line of lines) {
150+
for (match of line.matchAll(nameIdRegex)) {
151+
existingContributorNames.set(match.groups.id.trim(), match.groups.name.trim())
152+
}
153+
}
140154
// ------------------------------------------------------
141155
// Select name if multiple have been found for one contributor
142156
// ------------------------------------------------------
143157
const selectedContributorNames = new Map()
144158
const nameInconsistencies = []
145159
for (const [profile, names] of contributorNames) {
146160
// Select longest name, assuming that's correct
147-
let selectedName = [...names].reduce((n1, n2) => n1.length > n2.length ? n1 : n2)
148-
if (names.size > 1) {
161+
let selectedName = [...names][0]
162+
const existingName = existingContributorNames.get(profile)
163+
if (existingName && (selectedName != existingName || names.size > 1)) {
164+
selectedName = existingName
165+
console.log("Reuse existing name '" + existingName + "' for " + profile + ", instead of encountered: " + Array.from(names).join(', '))
166+
} else if (names.size > 1) {
167+
selectedName = [...names].reduce((n1, n2) => n1.length > n2.length ? n1 : n2)
149168
console.log("Multiple names encountered for " + profile + ": " + Array.from(names).join(', '))
150169
nameInconsistencies.push("@" + profile + ": " + Array.from(names).map(n => n==selectedName ? ("**`" + n + "`**") : ("`" + n + "`")).join(', '))
151170
}
@@ -155,9 +174,6 @@ jobs:
155174
// ------------------------------------------------------
156175
// Insert the list of contributors into the template file
157176
// ------------------------------------------------------
158-
const fs = require('fs')
159-
const acknowledgementsFile = 'website/news/${{ inputs.eclipse-version }}/acknowledgements.md'
160-
let lines = fs.readFileSync(acknowledgementsFile, {encoding: 'utf8'}).split(/\r?\n/)
161177
let elementsInLine = 0
162178
for (const [organization, contributors] of orgaContributors) {
163179
console.log('Insert contributors of ' + organization)

0 commit comments

Comments
 (0)