Skip to content

Commit 28b8832

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 28b8832

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
prepare:
12+
runs-on: ubuntu-latest
13+
if: contains(github.event.milestone.description, 'Release')
14+
steps:
15+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
16+
- name: Determine changed files
17+
id: changed-files
18+
run: |
19+
changedFiles=$(git diff --name-only --diff-filter=ACMR ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep acknowledgements.md$)
20+
echo "Changed files: ${changedFiles}"
21+
echo "files=${changedFiles}" >> "$GITHUB_OUTPUT"
22+
- name: Check modified acknowledgements files
23+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
24+
id: collect-contributors
25+
with:
26+
script: |
27+
const fs = require('fs')
28+
const files = '${{ steps.changed-files.outputs.files }}'.trim().split(/\r?\n/)
29+
const nameIdRegex = /\[(?<name>[^\]]+)\]\(https:\/\/github\.com\/(?<id>[^\)]+)\)/g
30+
const contributorNames = new Map()
31+
for (file of files) {
32+
let lines = fs.readFileSync(file, {encoding: 'utf8'}).split(/\r?\n/)
33+
for (line of lines) {
34+
for (match of line.matchAll(nameIdRegex)) {
35+
computeIfAbsent(contributorNames, match.groups.id, () => new Set()).add(match.groups.name)
36+
}
37+
}
38+
}
39+
let boolean hasMultipleNames = false
40+
for (const [profile, names] of contributorNames) {
41+
if (names.size > 1) {
42+
core.error('Multiple names found for profile '" + profile + "': ' + Array.from(names).join(', '))
43+
hasMultipleNames = true
44+
}
45+
}
46+
if (hasMultipleNames) {
47+
throw new Error('No selected name for profile: ' + profile)
48+
}
49+
50+
function computeIfAbsent(map, key, valueSupplier) {
51+
let value = map.get(key)
52+
if (!value) {
53+
value = valueSupplier()
54+
map.set(key, value)
55+
}
56+
return value
57+
}

.github/workflows/generateAcknowledgements.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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, match.groups.name)
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)