Skip to content
Merged
6 changes: 6 additions & 0 deletions scripts/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
5 changes: 4 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"build": "tsc",
"createReleaseIssue": "yarn build && node dist/scripts/release/create-release-issue.js",
"processRelease": "yarn build && node dist/scripts/release/process-release.js",
"setHostsOptions": "yarn build && node dist/scripts/pre-gen/setHostsOptions.js"
"setHostsOptions": "yarn build && node dist/scripts/pre-gen/setHostsOptions.js",
"test": "jest"
},
"devDependencies": {
"@octokit/rest": "18.12.0",
Expand All @@ -14,8 +15,10 @@
"@types/semver": "7.3.9",
"dotenv": "16.0.0",
"execa": "5.1.1",
"jest": "27.4.7",
"js-yaml": "4.1.0",
"semver": "7.3.5",
"ts-jest": "27.1.3",
"typescript": "4.5.4"
}
}
63 changes: 63 additions & 0 deletions scripts/release/__tests__/common.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { getMarkdownSection } from '../common';

describe('getMarkdownSection', () => {
it('gets the section correctly', () => {
const text = `
# hello

hi

# world

hey
`;
expect(getMarkdownSection(text, '# hello')).toMatchInlineSnapshot(`
"# hello

hi
"
`);
});

it('gets the sub headings', () => {
const text = `
# hi

# hello

## sub-heading

hello

# this shouldn't be included

right?
`;

expect(getMarkdownSection(text, '# hello')).toMatchInlineSnapshot(`
"# hello

## sub-heading

hello
"
`);
});

it('gets the whole text till the end', () => {
const text = `
# hi

# hello

this is a test
`;

expect(getMarkdownSection(text, '# hello')).toMatchInlineSnapshot(`
"# hello

this is a test
"
`);
});
});
16 changes: 16 additions & 0 deletions scripts/release/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,19 @@ export const LANGS = [
)
),
];

export function getMarkdownSection(markdown: string, title: string): string {
const levelIndicator = title.split(' ')[0]; // e.g. `##`
const lines = markdown
.slice(markdown.indexOf(title))
.split('\n')
.map((line) => line.trim());
let endIndex = lines.length;
for (let i = 1; i < lines.length; i++) {
if (lines[i].startsWith(`${levelIndicator} `)) {
endIndex = i;
break;
}
}
return lines.slice(0, endIndex).join('\n');
}
15 changes: 1 addition & 14 deletions scripts/release/process-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,11 @@ import execa from 'execa';

import openapitools from '../../openapitools.json';

import { MAIN_BRANCH, OWNER, REPO, run } from './common';
import { MAIN_BRANCH, OWNER, REPO, run, getMarkdownSection } from './common';
import TEXT from './text';

dotenv.config();

function getMarkdownSection(markdown: string, title: string): string {
const levelIndicator = title.split(' ')[0]; // e.g. `##`
const lines = markdown.slice(markdown.indexOf(title)).split('\n');
let endIndex = lines.length;
for (let i = 1; i < lines.length; i++) {
if (lines[i].startsWith(`${levelIndicator} `)) {
endIndex = i;
break;
}
}
return lines.slice(0, endIndex).join('\n');
}

if (!process.env.GITHUB_TOKEN) {
throw new Error('Environment variable `GITHUB_TOKEN` does not exist.');
}
Expand Down
1 change: 1 addition & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../base.tsconfig.json",
"compilerOptions": {
"typeRoots": ["../node_modules/@types"],
"types": ["node", "jest"],
"outDir": "dist"
},
"include": ["pre-gen/setHostsOptions.ts", "release/*"],
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9987,8 +9987,10 @@ __metadata:
"@types/semver": 7.3.9
dotenv: 16.0.0
execa: 5.1.1
jest: 27.4.7
js-yaml: 4.1.0
semver: 7.3.5
ts-jest: 27.1.3
typescript: 4.5.4
languageName: unknown
linkType: soft
Expand Down