From 703ba7c2de8b653fa244b3051804d725b35d8221 Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Tue, 7 Jun 2022 16:20:17 -0500 Subject: [PATCH 1/6] Add script to lint changesets --- .github/workflows/changesets_linter.yml | 12 +++++++ scripts/lint-changesets.mjs | 44 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 .github/workflows/changesets_linter.yml create mode 100644 scripts/lint-changesets.mjs diff --git a/.github/workflows/changesets_linter.yml b/.github/workflows/changesets_linter.yml new file mode 100644 index 0000000000..cec63bf4cd --- /dev/null +++ b/.github/workflows/changesets_linter.yml @@ -0,0 +1,12 @@ +on: + pull_request: + +name: Changelog Linter +jobs: + lint: + name: Lint Changelog + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Lint changesets + run: node scripts/lint-changesets.mjs diff --git a/scripts/lint-changesets.mjs b/scripts/lint-changesets.mjs new file mode 100644 index 0000000000..f21aeb5f6a --- /dev/null +++ b/scripts/lint-changesets.mjs @@ -0,0 +1,44 @@ +import fs from 'fs'; + +function lint() { + // Get the list of ignored packages from .changeset/config.json + const config = JSON.parse(fs.readFileSync('.changeset/config.json', 'utf8')); + const ignoredPackages = config.ignore; + + // Iterate through all the .md files in the .changeset directory + var changesetFiles = fs.readdirSync('.changeset'); + changesetFiles.forEach(function (file) { + if (file.indexOf('.md') < 0) return; + + var filePath = '.changeset/' + file; + var fileContents = fs.readFileSync(filePath, 'utf8'); + + // Check to see if any of the ignored packages exist in the frontmatter + const frontmatter = fileContents.match(/^---\n([\s\S]*?)\n---/m); + if (!frontmatter) return; + + let foundPackage; + + if ( + (foundPackage = ignoredPackages.find((ignoredPackage) => + frontmatter[1].includes(ignoredPackage) + )) + ) { + throw new Error( + `The changeset ${filePath} contains an ignored package: ${foundPackage}. ` + + `Please remove it from the changeset. If it is the only package in the changeset, ` + + `remove the changeset entirely.` + ); + } + }); + + console.log('No ignored packages found in changesets.'); +} + +try { + lint(); +} catch (e) { + console.error(e.message); + // eslint-disable-next-line no-process-exit + process.exit(1); +} From 0993d960ef9497dd393cbb59cc9f1a2d9042993d Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Tue, 7 Jun 2022 16:28:24 -0500 Subject: [PATCH 2/6] Add note about avoiding headings as first line of changesets, and a linter for that --- .github/contributing.md | 5 +++++ scripts/lint-changesets.mjs | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/.github/contributing.md b/.github/contributing.md index 29e1cd5cc8..c934e3c4c0 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -93,6 +93,11 @@ yarn changeset add Follow the prompts to select which package(s) are affected by your change, and whether the change is a major, minor or patch change. This will create a file in the `.changesets` directory of the repo. This change should be committed and included with your PR. +Considerations: + +- You can use markdown in your changeset to include code examples, headings, and more. However, **please use plain text for the first line of your changeset**. The formatting of the GitHub release notes does not support headings as the first line of the changeset. +- When selecting packages for the changesets, only select packages which are published. Do not include private packages, as it will cause the build to fail. _Hopefully these are removed from the list of options in a [future Changesets release](https://github.com/changesets/changesets/issues/436)_. + > **Important**: Until our official release, we will only release `minor` and `patch` updates. This means that breaking changes will be included in minor releases. Once we officially launch Hydrogen, we'll switch to `1.0.0` and follow a normal semantic release pattern. ## Contributing Examples diff --git a/scripts/lint-changesets.mjs b/scripts/lint-changesets.mjs index f21aeb5f6a..fbe63494c6 100644 --- a/scripts/lint-changesets.mjs +++ b/scripts/lint-changesets.mjs @@ -19,6 +19,10 @@ function lint() { let foundPackage; + /** + * We have to manually lint for this due to an issue with changesets: + * @see https://github.com/changesets/changesets/issues/436 + */ if ( (foundPackage = ignoredPackages.find((ignoredPackage) => frontmatter[1].includes(ignoredPackage) @@ -30,6 +34,22 @@ function lint() { `remove the changeset entirely.` ); } + + /** + * Ensure the first line of the changeset is NOT a markdown header: + */ + const fileContentsWithoutFrontmatter = fileContents + .replace(/^---\n([\s\S]*?)\n---/m, '') + .trim(); + + if (fileContentsWithoutFrontmatter.startsWith('#')) { + throw new Error( + `The first line of changeset ${filePath} begins with a header: \n\n${ + fileContentsWithoutFrontmatter.split('\n')[0] + }\n\n` + + `Changesets must begin with plain text. You may use markdown headers later in the body if desired.` + ); + } }); console.log('No ignored packages found in changesets.'); From 3ca6a1646c31ca79d772673831716485c0ae12f4 Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Tue, 7 Jun 2022 16:35:06 -0500 Subject: [PATCH 3/6] Add more specific actionable stuff --- scripts/lint-changesets.mjs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/lint-changesets.mjs b/scripts/lint-changesets.mjs index fbe63494c6..78e76e6070 100644 --- a/scripts/lint-changesets.mjs +++ b/scripts/lint-changesets.mjs @@ -35,6 +35,8 @@ function lint() { ); } + console.log(`✅ No ignored packages found in changeset ${filePath}.`); + /** * Ensure the first line of the changeset is NOT a markdown header: */ @@ -47,18 +49,21 @@ function lint() { `The first line of changeset ${filePath} begins with a header: \n\n${ fileContentsWithoutFrontmatter.split('\n')[0] }\n\n` + - `Changesets must begin with plain text. You may use markdown headers later in the body if desired.` + `Changesets must begin with plain text. Please replace the header in the first line with a plain string. ` + + `You may use markdown headers later in the body if desired.` ); } - }); - console.log('No ignored packages found in changesets.'); + console.log( + `✅ First line begins with plain text in changeset ${filePath}.` + ); + }); } try { lint(); } catch (e) { - console.error(e.message); + console.error(`❌ ${e.message}`); // eslint-disable-next-line no-process-exit process.exit(1); } From 2ce630170cf0b5733acb8986b9b260bd517652a9 Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Tue, 7 Jun 2022 16:37:17 -0500 Subject: [PATCH 4/6] Try removing emoji --- scripts/lint-changesets.mjs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/lint-changesets.mjs b/scripts/lint-changesets.mjs index 78e76e6070..409845793e 100644 --- a/scripts/lint-changesets.mjs +++ b/scripts/lint-changesets.mjs @@ -35,7 +35,7 @@ function lint() { ); } - console.log(`✅ No ignored packages found in changeset ${filePath}.`); + console.log(`No ignored packages found in changeset ${filePath}.`); /** * Ensure the first line of the changeset is NOT a markdown header: @@ -54,16 +54,14 @@ function lint() { ); } - console.log( - `✅ First line begins with plain text in changeset ${filePath}.` - ); + console.log(`First line begins with plain text in changeset ${filePath}.`); }); } try { lint(); } catch (e) { - console.error(`❌ ${e.message}`); + console.error(e.message); // eslint-disable-next-line no-process-exit process.exit(1); } From 342064c4a5c7c684477750a68a9eb18084060e74 Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Tue, 7 Jun 2022 16:38:14 -0500 Subject: [PATCH 5/6] Revert "Try removing emoji" This reverts commit 2ce630170cf0b5733acb8986b9b260bd517652a9. --- scripts/lint-changesets.mjs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/lint-changesets.mjs b/scripts/lint-changesets.mjs index 409845793e..78e76e6070 100644 --- a/scripts/lint-changesets.mjs +++ b/scripts/lint-changesets.mjs @@ -35,7 +35,7 @@ function lint() { ); } - console.log(`No ignored packages found in changeset ${filePath}.`); + console.log(`✅ No ignored packages found in changeset ${filePath}.`); /** * Ensure the first line of the changeset is NOT a markdown header: @@ -54,14 +54,16 @@ function lint() { ); } - console.log(`First line begins with plain text in changeset ${filePath}.`); + console.log( + `✅ First line begins with plain text in changeset ${filePath}.` + ); }); } try { lint(); } catch (e) { - console.error(e.message); + console.error(`❌ ${e.message}`); // eslint-disable-next-line no-process-exit process.exit(1); } From 35fca23436e6d75b4c161cc3f0f34ecaad0e0836 Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Tue, 7 Jun 2022 16:38:46 -0500 Subject: [PATCH 6/6] Add final success message --- scripts/lint-changesets.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/lint-changesets.mjs b/scripts/lint-changesets.mjs index 78e76e6070..b7a591759e 100644 --- a/scripts/lint-changesets.mjs +++ b/scripts/lint-changesets.mjs @@ -62,6 +62,7 @@ function lint() { try { lint(); + console.log(`✅ No changeset issues detected.`); } catch (e) { console.error(`❌ ${e.message}`); // eslint-disable-next-line no-process-exit