Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .github/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/changesets_linter.yml
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions scripts/lint-changesets.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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;

/**
* 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)
))
) {
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.`
);
}

/**
* 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.');
}

try {
lint();
} catch (e) {
console.error(e.message);
// eslint-disable-next-line no-process-exit
process.exit(1);
}