Skip to content

Commit 495af24

Browse files
committed
WIP
1 parent 51bc570 commit 495af24

File tree

6 files changed

+130
-0
lines changed

6 files changed

+130
-0
lines changed

.github/workflows/build.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,26 @@ jobs:
224224
message: |
225225
⚠️ This PR is opened against **master**. You probably want to open it against **develop**.
226226
227+
job_external_contributor:
228+
name: Mention external contributor in changelog
229+
needs: job_get_metadata
230+
runs-on: ubuntu-20.04
231+
if: |
232+
github.event_name == 'pull_request'
233+
&& github.event.pull_request.author_association != 'COLLABORATOR'
234+
&& github.event.pull_request.author_association != 'MEMBER'
235+
&& github.event.pull_request.author_association != 'OWNER'
236+
permissions:
237+
pull-requests: write
238+
steps:
239+
- uses: actions/checkout@v4
240+
- uses: ./dev-packages/external-contributor-gh-action
241+
with:
242+
name: ${{ github.event.pull_request.user.login }}
243+
- uses: parkerbxyz/suggest-changes@v1
244+
with:
245+
comment: 'Please commit the suggested changes from markdownlint.'
246+
227247
job_build:
228248
name: Build
229249
needs: [job_get_metadata, job_install_deps]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
extends: ['../../.eslintrc.js'],
3+
parserOptions: {
4+
sourceType: 'module',
5+
ecmaVersion: 'latest',
6+
},
7+
8+
overrides: [
9+
{
10+
files: ['*.mjs'],
11+
extends: ['@sentry-internal/sdk/src/base'],
12+
},
13+
],
14+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: 'external-contributor-gh-action'
2+
description: 'Add external contributors to CHANGELOG.md'
3+
inputs:
4+
name:
5+
required: true
6+
description: 'The name of the external contributor'
7+
runs:
8+
using: 'node20'
9+
main: 'index.mjs'
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { promises as fs } from 'node:fs';
2+
import path from 'node:path';
3+
import * as core from '@actions/core';
4+
5+
const UNRELEASED_HEADING = `## Unreleased
6+
7+
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
8+
`;
9+
10+
const contributorMessageRegex = /Work in this release was contributed by (.+)\. Thank you for your contribution!/;
11+
12+
async function run() {
13+
const { getInput } = core;
14+
15+
const name = getInput('name');
16+
17+
if (!name) {
18+
return;
19+
}
20+
21+
const cwd = process.cwd();
22+
const changelogFilePath = path.resolve(cwd, 'CHANGELOG.md');
23+
24+
const changelogStr = await fs.readFile(changelogFilePath, 'utf8');
25+
26+
// Find the unreleased section
27+
const start = changelogStr.indexOf(UNRELEASED_HEADING) + UNRELEASED_HEADING.length;
28+
const end = changelogStr.slice(start).indexOf('## ');
29+
30+
const inBetween = changelogStr.slice(start, start + end);
31+
32+
const existing = contributorMessageRegex.exec(inBetween);
33+
34+
// If the contributor message already exists, add the new contributor to the list
35+
if (existing) {
36+
const users = existing[1].split(/(?:,? and )|(?:, )/);
37+
if (!users.includes(name)) {
38+
users.push(name);
39+
}
40+
41+
const formatter = new Intl.ListFormat('en', {
42+
style: 'long',
43+
type: 'conjunction',
44+
});
45+
46+
const newContributors = formatter.format(users);
47+
const newChangelog = changelogStr.replace(
48+
contributorMessageRegex,
49+
`Work in this release was contributed by ${newContributors}. Thank you for your contribution!`,
50+
);
51+
52+
fs.writeFile(changelogFilePath, newChangelog);
53+
return;
54+
}
55+
56+
// If the contributor message does not exist, add it
57+
const newChangelog = changelogStr.replace(
58+
UNRELEASED_HEADING,
59+
`${UNRELEASED_HEADING}\nWork in this release was contributed by ${name}. Thank you for your contribution!\n`,
60+
);
61+
fs.writeFile(changelogFilePath, newChangelog);
62+
}
63+
64+
run();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@sentry-internal/external-contributor-gh-action",
3+
"description": "An internal Github Action to add external contributors to the CHANGELOG.md file.",
4+
"version": "8.8.0",
5+
"license": "MIT",
6+
"engines": {
7+
"node": ">=18"
8+
},
9+
"private": true,
10+
"main": "index.mjs",
11+
"type": "module",
12+
"scripts": {
13+
"lint": "eslint . --format stylish",
14+
"fix": "eslint . --format stylish --fix"
15+
},
16+
"dependencies": {
17+
"@actions/core": "1.10.1"
18+
},
19+
"volta": {
20+
"extends": "../../package.json"
21+
}
22+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"dev-packages/overhead-metrics",
8686
"dev-packages/test-utils",
8787
"dev-packages/size-limit-gh-action",
88+
"dev-packages/external-contributor-gh-action",
8889
"dev-packages/rollup-utils"
8990
],
9091
"devDependencies": {

0 commit comments

Comments
 (0)