Skip to content

Commit 301c795

Browse files
committed
prettier
1 parent ad7f2f3 commit 301c795

File tree

5 files changed

+149
-115
lines changed

5 files changed

+149
-115
lines changed

actions/trickle-down-changelog/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# Trickle Down Changelog GH Action
2+
23
This action will open PRs in downstream release branches with changes from the changelog.
34
For example:
5+
46
- If you update the current GA branch with changes, you will also need to update beta branch and main branches.
57
- This action will open PRs in beta and main branches with the changes from the changelog.
68

79
## Inputs
10+
811
### `token`
12+
913
**Required** The GitHub token to use for authentication.
1014

1115
## Usage
16+
1217
```yaml
1318
jobs:
1419
trickle-down-changelog:
@@ -23,6 +28,7 @@ jobs:
2328
```
2429

2530
## Build
31+
2632
This action uses `ncc` to build the modules inside the javascript file, so no need to install any dependencies, **make sure to build before merging**.
2733

2834
run `npm run build` to build the action. The build artifacts will be stored in the `dist/` directory.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: 'Trickle down changelog action'
22
description: 'Create PRs for changelog changes'
33
inputs:
4-
token:
5-
description: 'GitHub token'
6-
required: true
4+
token:
5+
description: 'GitHub token'
6+
required: true
77

88
runs:
9-
using: 'node20'
10-
main: 'dist/index.js'
9+
using: 'node20'
10+
main: 'dist/index.js'

actions/trickle-down-changelog/dist/index.js

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,76 +23,93 @@ __nccwpck_require__.r(__webpack_exports__);
2323

2424

2525

26-
const octokit = _actions_github__WEBPACK_IMPORTED_MODULE_1__.getOctokit(_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput("token"));
26+
const octokit = _actions_github__WEBPACK_IMPORTED_MODULE_1__.getOctokit(_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('token'));
2727
const simpleSemverRegex = /\d+\.\d+\.\d+(-.*)?/;
28-
const internalBotEmail = "internal@elementor.com";
28+
const internalBotEmail = 'internal@elementor.com';
2929
async function main() {
30-
const currentRef = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.ref.replace("refs/heads/", "");
30+
const currentRef = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.ref.replace('refs/heads/', '');
3131

3232
// we only care about merges to beta/ga branches
33-
if (!semver__WEBPACK_IMPORTED_MODULE_2__.parse(currentRef) && !semver__WEBPACK_IMPORTED_MODULE_2__.parse(currentRef + ".0"))
34-
return;
33+
if (!semver__WEBPACK_IMPORTED_MODULE_2__.parse(currentRef) && !semver__WEBPACK_IMPORTED_MODULE_2__.parse(currentRef + '.0')) return;
3534

36-
const commitInfo = await octokit.request("GET /repos/{owner}/{repo}/commits/{sha}", {
37-
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
38-
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
39-
sha: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.sha,
40-
});
35+
const commitInfo = await octokit.request(
36+
'GET /repos/{owner}/{repo}/commits/{sha}',
37+
{
38+
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
39+
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
40+
sha: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.sha,
41+
},
42+
);
4143

4244
// if pr opened with the internal bot, no need to continue
43-
if (commitInfo.data.commit.author.email === internalBotEmail)
44-
return;
45-
46-
const diff = await octokit.request("GET /repos/{owner}/{repo}/commits/{sha}", {
47-
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
48-
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
49-
sha: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.sha,
50-
headers: {
51-
accept: "application/vnd.github.diff"
52-
}
53-
});
45+
if (commitInfo.data.commit.author.email === internalBotEmail) return;
46+
47+
const diff = await octokit.request(
48+
'GET /repos/{owner}/{repo}/commits/{sha}',
49+
{
50+
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
51+
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
52+
sha: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.sha,
53+
headers: {
54+
accept: 'application/vnd.github.diff',
55+
},
56+
},
57+
);
5458
const changedVersions = getVersions(diff);
5559
const oldest = getOldestVersionFromChanged(changedVersions);
5660

57-
const branches = await octokit.request("GET /repos/{owner}/{repo}/branches", {
58-
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
59-
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
60-
});
61+
const branches = await octokit.request(
62+
'GET /repos/{owner}/{repo}/branches',
63+
{
64+
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
65+
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
66+
},
67+
);
6168

6269
const gitBranches = branches.data.filter((branch) => {
63-
const toSemver = semver__WEBPACK_IMPORTED_MODULE_2__.parse(branch.name + ".0");
70+
const toSemver = semver__WEBPACK_IMPORTED_MODULE_2__.parse(branch.name + '.0');
6471
return toSemver && semver__WEBPACK_IMPORTED_MODULE_2__.gt(toSemver.version, oldest);
6572
});
6673
const branchesToPRTo = gitBranches.map((branch) => branch.name);
6774

6875
// always need to pr to main
69-
branchesToPRTo.push("main");
76+
branchesToPRTo.push('main');
7077

71-
console.log(`branches to pr: ${branchesToPRTo}`)
72-
const changelog = await fs_promises__WEBPACK_IMPORTED_MODULE_4__.readFile("changelog.txt");
78+
console.log(`branches to pr: ${branchesToPRTo}`);
79+
const changelog = await fs_promises__WEBPACK_IMPORTED_MODULE_4__.readFile('changelog.txt');
7380
let readmeContent = undefined;
74-
if (_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo === "elementor") {
75-
readmeContent = await fs_promises__WEBPACK_IMPORTED_MODULE_4__.readFile("readme.txt");
81+
if (_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo === 'elementor') {
82+
readmeContent = await fs_promises__WEBPACK_IMPORTED_MODULE_4__.readFile('readme.txt');
7683
}
7784

78-
for (const branch of branchesToPRTo){
79-
await createPRWithChangesOnChangelog(currentRef, branch, changelog, readmeContent);
85+
for (const branch of branchesToPRTo) {
86+
await createPRWithChangesOnChangelog(
87+
currentRef,
88+
branch,
89+
changelog,
90+
readmeContent,
91+
);
8092
}
8193
}
8294

83-
async function createPRWithChangesOnChangelog(sourceBranch, targetBranch, changelogContent, readmeContent = undefined) {
95+
async function createPRWithChangesOnChangelog(
96+
sourceBranch,
97+
targetBranch,
98+
changelogContent,
99+
readmeContent = undefined,
100+
) {
84101
const PRBranchName = `changelog-${sourceBranch}-to-${targetBranch}`;
85102
const PRMessage = `Internal: Changelog v${sourceBranch} to ${targetBranch} (automatic)`;
86-
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(`git fetch --all`)
103+
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(`git fetch --all`);
87104
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(`git checkout ${targetBranch}`);
88105
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(`git pull`);
89106
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(`git config user.name "elementor internal"`);
90107
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(`git config user.email ${internalBotEmail}`);
91108
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(`git reset --hard origin/${targetBranch}`);
92109
if (readmeContent) {
93-
await fs_promises__WEBPACK_IMPORTED_MODULE_4__.writeFile("readme.txt", readmeContent)
110+
await fs_promises__WEBPACK_IMPORTED_MODULE_4__.writeFile('readme.txt', readmeContent);
94111
}
95-
await fs_promises__WEBPACK_IMPORTED_MODULE_4__.writeFile("changelog.txt", changelogContent);
112+
await fs_promises__WEBPACK_IMPORTED_MODULE_4__.writeFile('changelog.txt', changelogContent);
96113
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(`git checkout -b ${PRBranchName}`);
97114
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(`git add changelog.txt readme.txt`);
98115
await _actions_exec__WEBPACK_IMPORTED_MODULE_3__.exec(`git commit -m "${PRMessage}"`);
@@ -103,31 +120,28 @@ async function createPRWithChangesOnChangelog(sourceBranch, targetBranch, change
103120
title: PRMessage,
104121
head: PRBranchName,
105122
base: targetBranch,
106-
})
123+
});
107124
}
108125

109126
function getOldestVersionFromChanged(changedVersions) {
110127
let min = changedVersions[0];
111-
for (const version of changedVersions){
128+
for (const version of changedVersions) {
112129
if (semver__WEBPACK_IMPORTED_MODULE_2__.lt(version, min)) {
113130
min = version;
114131
}
115132
}
116133
return min;
117134
}
118135

119-
120136
function getVersions(diff) {
121-
const parsedDiff = diff.data.split("\n");
137+
const parsedDiff = diff.data.split('\n');
122138
const changedVersions = [];
123139
let match;
124140
for (const line of parsedDiff) {
125-
if (!line.startsWith("+"))
126-
continue;
127-
if (line.startsWith("+#")) {
141+
if (!line.startsWith('+')) continue;
142+
if (line.startsWith('+#')) {
128143
match = simpleSemverRegex.exec(line);
129-
if (match.length > 0)
130-
changedVersions.push(match[0]);
144+
if (match.length > 0) changedVersions.push(match[0]);
131145
}
132146
}
133147
return changedVersions;

actions/trickle-down-changelog/index.js

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,96 @@
1-
import * as core from "@actions/core";
2-
import * as github from "@actions/github";
1+
import * as core from '@actions/core';
2+
import * as github from '@actions/github';
33
import * as semver from 'semver';
4-
import * as exec from "@actions/exec"
5-
import * as fs from "fs/promises";
4+
import * as exec from '@actions/exec';
5+
import * as fs from 'fs/promises';
66

7-
const octokit = github.getOctokit(core.getInput("token"));
7+
const octokit = github.getOctokit(core.getInput('token'));
88
const simpleSemverRegex = /\d+\.\d+\.\d+(-.*)?/;
9-
const internalBotEmail = "internal@elementor.com";
9+
const internalBotEmail = 'internal@elementor.com';
1010
async function main() {
11-
const currentRef = github.context.ref.replace("refs/heads/", "");
11+
const currentRef = github.context.ref.replace('refs/heads/', '');
1212

1313
// we only care about merges to beta/ga branches
14-
if (!semver.parse(currentRef) && !semver.parse(currentRef + ".0"))
15-
return;
14+
if (!semver.parse(currentRef) && !semver.parse(currentRef + '.0')) return;
1615

17-
const commitInfo = await octokit.request("GET /repos/{owner}/{repo}/commits/{sha}", {
18-
owner: github.context.repo.owner,
19-
repo: github.context.repo.repo,
20-
sha: github.context.sha,
21-
});
16+
const commitInfo = await octokit.request(
17+
'GET /repos/{owner}/{repo}/commits/{sha}',
18+
{
19+
owner: github.context.repo.owner,
20+
repo: github.context.repo.repo,
21+
sha: github.context.sha,
22+
},
23+
);
2224

2325
// if pr opened with the internal bot, no need to continue
24-
if (commitInfo.data.commit.author.email === internalBotEmail)
25-
return;
26+
if (commitInfo.data.commit.author.email === internalBotEmail) return;
2627

27-
const diff = await octokit.request("GET /repos/{owner}/{repo}/commits/{sha}", {
28-
owner: github.context.repo.owner,
29-
repo: github.context.repo.repo,
30-
sha: github.context.sha,
31-
headers: {
32-
accept: "application/vnd.github.diff"
33-
}
34-
});
28+
const diff = await octokit.request(
29+
'GET /repos/{owner}/{repo}/commits/{sha}',
30+
{
31+
owner: github.context.repo.owner,
32+
repo: github.context.repo.repo,
33+
sha: github.context.sha,
34+
headers: {
35+
accept: 'application/vnd.github.diff',
36+
},
37+
},
38+
);
3539
const changedVersions = getVersions(diff);
3640
const oldest = getOldestVersionFromChanged(changedVersions);
3741

38-
const branches = await octokit.request("GET /repos/{owner}/{repo}/branches", {
39-
owner: github.context.repo.owner,
40-
repo: github.context.repo.repo,
41-
});
42+
const branches = await octokit.request(
43+
'GET /repos/{owner}/{repo}/branches',
44+
{
45+
owner: github.context.repo.owner,
46+
repo: github.context.repo.repo,
47+
},
48+
);
4249

4350
const gitBranches = branches.data.filter((branch) => {
44-
const toSemver = semver.parse(branch.name + ".0");
51+
const toSemver = semver.parse(branch.name + '.0');
4552
return toSemver && semver.gt(toSemver.version, oldest);
4653
});
4754
const branchesToPRTo = gitBranches.map((branch) => branch.name);
4855

4956
// always need to pr to main
50-
branchesToPRTo.push("main");
57+
branchesToPRTo.push('main');
5158

52-
console.log(`branches to pr: ${branchesToPRTo}`)
53-
const changelog = await fs.readFile("changelog.txt");
59+
console.log(`branches to pr: ${branchesToPRTo}`);
60+
const changelog = await fs.readFile('changelog.txt');
5461
let readmeContent = undefined;
55-
if (github.context.repo.repo === "elementor") {
56-
readmeContent = await fs.readFile("readme.txt");
62+
if (github.context.repo.repo === 'elementor') {
63+
readmeContent = await fs.readFile('readme.txt');
5764
}
5865

59-
for (const branch of branchesToPRTo){
60-
await createPRWithChangesOnChangelog(currentRef, branch, changelog, readmeContent);
66+
for (const branch of branchesToPRTo) {
67+
await createPRWithChangesOnChangelog(
68+
currentRef,
69+
branch,
70+
changelog,
71+
readmeContent,
72+
);
6173
}
6274
}
6375

64-
async function createPRWithChangesOnChangelog(sourceBranch, targetBranch, changelogContent, readmeContent = undefined) {
76+
async function createPRWithChangesOnChangelog(
77+
sourceBranch,
78+
targetBranch,
79+
changelogContent,
80+
readmeContent = undefined,
81+
) {
6582
const PRBranchName = `changelog-${sourceBranch}-to-${targetBranch}`;
6683
const PRMessage = `Internal: Changelog v${sourceBranch} to ${targetBranch} (automatic)`;
67-
await exec.exec(`git fetch --all`)
84+
await exec.exec(`git fetch --all`);
6885
await exec.exec(`git checkout ${targetBranch}`);
6986
await exec.exec(`git pull`);
7087
await exec.exec(`git config user.name "elementor internal"`);
7188
await exec.exec(`git config user.email ${internalBotEmail}`);
7289
await exec.exec(`git reset --hard origin/${targetBranch}`);
7390
if (readmeContent) {
74-
await fs.writeFile("readme.txt", readmeContent)
91+
await fs.writeFile('readme.txt', readmeContent);
7592
}
76-
await fs.writeFile("changelog.txt", changelogContent);
93+
await fs.writeFile('changelog.txt', changelogContent);
7794
await exec.exec(`git checkout -b ${PRBranchName}`);
7895
await exec.exec(`git add changelog.txt readme.txt`);
7996
await exec.exec(`git commit -m "${PRMessage}"`);
@@ -84,31 +101,28 @@ async function createPRWithChangesOnChangelog(sourceBranch, targetBranch, change
84101
title: PRMessage,
85102
head: PRBranchName,
86103
base: targetBranch,
87-
})
104+
});
88105
}
89106

90107
function getOldestVersionFromChanged(changedVersions) {
91108
let min = changedVersions[0];
92-
for (const version of changedVersions){
109+
for (const version of changedVersions) {
93110
if (semver.lt(version, min)) {
94111
min = version;
95112
}
96113
}
97114
return min;
98115
}
99116

100-
101117
function getVersions(diff) {
102-
const parsedDiff = diff.data.split("\n");
118+
const parsedDiff = diff.data.split('\n');
103119
const changedVersions = [];
104120
let match;
105121
for (const line of parsedDiff) {
106-
if (!line.startsWith("+"))
107-
continue;
108-
if (line.startsWith("+#")) {
122+
if (!line.startsWith('+')) continue;
123+
if (line.startsWith('+#')) {
109124
match = simpleSemverRegex.exec(line);
110-
if (match.length > 0)
111-
changedVersions.push(match[0]);
125+
if (match.length > 0) changedVersions.push(match[0]);
112126
}
113127
}
114128
return changedVersions;

0 commit comments

Comments
 (0)