Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 41 additions & 13 deletions .github/actions/check-pr/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions .github/actions/merge-and-write-changelogs/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions build-packages/changeset-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable jsdoc/require-jsdoc */
export const messageTypes = [
{
name: 'compat',
title: 'Compatibility Notes',
alternatives: ['compatibility', 'compatibility note', 'compat']
},
{
name: 'feat',
title: 'New Features',
alternatives: ['new', 'new functionality', 'feat']
},
{
name: 'fix',
title: 'Fixed Issues',
alternatives: ['bug', 'bug fix', 'fixed issue', 'fix', 'fix issue']
},
{
name: 'known-issue',
title: 'Known Issues',
alternatives: ['known issue']
},
{
name: 'impr',
title: 'Improvements',
alternatives: ['improvement', 'improv']
},
{
name: 'dep',
title: 'Updated Dependencies',
alternatives: ['dependency', 'dependency update']
}
];

export type MessageType = (typeof messageTypes)[number];
2 changes: 1 addition & 1 deletion build-packages/check-pr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "module",
"scripts": {
"compile": "tsc -p tsconfig.json",
"postcompile": "ncc build lib/index.js --out ../../.github/actions/check-pr/",
"postcompile": "ncc build lib/check-pr/index.js --out ../../.github/actions/check-pr/",
"test": "pnpm run test:unit",
"test:unit": "NODE_OPTIONS=--experimental-vm-modules pnpm exec jest",
"lint": "eslint --ignore-pattern '!index.ts' && prettier --check **/*.ts",
Expand Down
1 change: 1 addition & 0 deletions build-packages/check-pr/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"strict": true,
"skipLibCheck": true,
"isolatedModules": true,
"rootDir": "..",
"outDir": "./lib",
"tsBuildInfoFile": "./lib/.tsbuildinfo"
},
Expand Down
22 changes: 20 additions & 2 deletions build-packages/check-pr/validators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,32 @@ describe('check-pr', () => {
it('should fail if change type is wrong', async () => {
const fileContents = [
"'@sap-cloud-sdk/generator': major",
'[Fix] Something is fixed.'
'[Something] Something is fixed.'
];
validateChangesets('chore!', '', true, fileContents);
expect(setFailed).toHaveBeenCalledWith(
"All change types must match one of the allowed change types '[Known Issue]' or '[Compatibility Note]' or '[New Functionality]' or '[Improvement]' or '[Fixed Issue]'."
"All change types must be one of: 'compat', 'feat', 'fix', 'known-issue', 'impr', 'dep' (or their aliases)."
);
});

it('should pass if shorthand change type is provided', async () => {
const fileContents = [
"'@sap-cloud-sdk/generator': major",
'[fix] Something is fixed.'
];
validateChangesets('chore!', '', true, fileContents);
expect(setFailed).not.toHaveBeenCalled();
});

it('should pass if compat shorthand change type is provided', async () => {
const fileContents = [
"'@sap-cloud-sdk/generator': major",
'[compat] Something changed.'
];
validateChangesets('chore!', '', true, fileContents);
expect(setFailed).not.toHaveBeenCalled();
});

it('should pass if correct change type is provided', async () => {
const fileContents = [
"'@sap-cloud-sdk/generator': major",
Expand Down
17 changes: 6 additions & 11 deletions build-packages/check-pr/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { getInput, setFailed, info } from '@actions/core';
import { messageTypes } from '../changeset-types.js';

const validCommitTypes = ['feat', 'fix', 'chore'];
const allAllowedChangeTypes = new Set(
messageTypes.flatMap(({ name, alternatives }) => [name, ...alternatives])
);

// Expected format: preamble(topic)!: Title text
export async function validateTitle(title: string | undefined): Promise<void> {
Expand Down Expand Up @@ -115,13 +119,6 @@ export function validateChangesets(
fileContents: string[]
): void {
const allowedBumps = getAllowedBumps(commitType, isBreaking);
const allowedChangeTypes = [
'Known Issue',
'Compatibility Note',
'New Functionality',
'Improvement',
'Fixed Issue'
];

if (!hasMatchingChangeset(allowedBumps, fileContents)) {
return setFailed(
Expand All @@ -141,14 +138,12 @@ export function validateChangesets(
}

const allChangeTypesMatch = changeTypes.every(type =>
allowedChangeTypes.includes(type)
allAllowedChangeTypes.has(type.toLowerCase())
);

if (!allChangeTypesMatch) {
return setFailed(
`All change types must match one of the allowed change types ${allowedChangeTypes
.map(type => `'[${type}]'`)
.join(' or ')}.`
`All change types must be one of: ${messageTypes.map(({ name }) => `'${name}'`).join(', ')} (or their aliases).`
);
}

Expand Down
31 changes: 1 addition & 30 deletions build-packages/merge-and-write-changelogs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,7 @@ import { readFile, writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { setFailed, info } from '@actions/core';
import { getPackages } from '@manypkg/get-packages';

const messageTypes = [
{
name: 'compat',
title: 'Compatibility Notes',
alternatives: ['compatibility', 'compatibility note', 'compat']
},
{
name: 'feat',
title: 'New Features',
alternatives: ['new', 'new functionality', 'feat']
},
{
name: 'fix',
title: 'Fixed Issues',
alternatives: ['bug', 'bug fix', 'fixed issue', 'fix', 'fix issue']
},
{
name: 'impr',
title: 'Improvements',
alternatives: ['improvement', 'improv']
},
{
name: 'dep',
title: 'Updated Dependencies',
alternatives: ['dependency', 'dependency update']
}
];

type MessageType = (typeof messageTypes)[number];
import { messageTypes, type MessageType } from '../changeset-types.js';

interface Change {
packageNames: string[];
Expand Down
3 changes: 3 additions & 0 deletions build-packages/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Loading