Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Changesets #63

Merged
merged 1 commit into from
Oct 26, 2021
Merged
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
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
162 changes: 162 additions & 0 deletions .changeset/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
const {
mattcompiles marked this conversation as resolved.
Show resolved Hide resolved
getInfo,
getInfoFromPullRequest,
} = require('@changesets/get-github-info');

/**
* Adapted from `@changesets/cli`.
*
* {@link https://github.com/atlassian/changesets/blob/%40changesets/cli%402.17.0/packages/cli/src/changelog/index.ts}
*
* @type import('@changesets/types').ChangelogFunctions
*/
const defaultChangelogFunctions = {
getDependencyReleaseLine: async (changesets, dependenciesUpdated) => {
if (dependenciesUpdated.length === 0) return '';

const changesetLinks = changesets.map(
(changeset) => `- Updated dependencies [${changeset.commit}]`,
);

const updatedDependenciesList = dependenciesUpdated.map(
(dependency) => ` - ${dependency.name}@${dependency.newVersion}`,
);

return [...changesetLinks, ...updatedDependenciesList].join('\n');
},
getReleaseLine: async (changeset) => {
const [firstLine, ...futureLines] = changeset.summary
.split('\n')
.map((l) => l.trimRight());

const suffix = changeset.commit;

return `\n\n- ${firstLine}${suffix ? ` (${suffix})` : ''}\n${futureLines
.map((l) => ` ${l}`)
.join('\n')}`;
},
};

/**
* Adapted from `@changesets/changelog-github`.
*
* {@link https://github.com/atlassian/changesets/blob/%40changesets/changelog-github%400.4.1/packages/changelog-github/src/index.ts}
*
* @type import('@changesets/types').ChangelogFunctions
*/
const gitHubChangelogFunctions = {
getDependencyReleaseLine: async (
changesets,
dependenciesUpdated,
options,
) => {
if (!options.repo) {
throw new Error(
'Please provide a repo to this changelog generator like this:\n"changelog": ["./changelog.js", { "repo": "org/repo" }]',
);
}
if (dependenciesUpdated.length === 0) return '';

const changesetLink = `- Updated dependencies [${(
await Promise.all(
changesets.map(async (cs) => {
if (cs.commit) {
let { links } = await getInfo({
repo: options.repo,
commit: cs.commit,
});
return links.commit;
}
}),
)
)
.filter((_) => _)
.join(', ')}]:`;

const updatedDependenciesList = dependenciesUpdated.map(
(dependency) => ` - ${dependency.name}@${dependency.newVersion}`,
);

return [changesetLink, ...updatedDependenciesList].join('\n');
},
getReleaseLine: async (changeset, _type, options) => {
if (!options || !options.repo) {
throw new Error(
'Please provide a repo to this changelog generator like this:\n"changelog": ["./changelog.js", { "repo": "org/repo" }]',
);
}

/** @type number | undefined */
let prFromSummary;
/** @type string | undefined */
let commitFromSummary;

const replacedChangelog = changeset.summary
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
let num = Number(pr);
if (!isNaN(num)) prFromSummary = num;
return '';
})
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
commitFromSummary = commit;
return '';
})
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
usersFromSummary.push(user);
return '';
})
.trim();

const [firstLine, ...futureLines] = replacedChangelog
.split('\n')
.map((l) => l.trimRight());

const links = await (async () => {
if (prFromSummary !== undefined) {
let { links } = await getInfoFromPullRequest({
repo: options.repo,
pull: prFromSummary,
});
if (commitFromSummary) {
links = {
...links,
commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
};
}
return links;
}
const commitToFetchFrom = commitFromSummary || changeset.commit;
if (commitToFetchFrom) {
let { links } = await getInfo({
repo: options.repo,
commit: commitToFetchFrom,
});
return links;
}
return {
commit: null,
pull: null,
user: null,
};
})();

const suffix = links.pull ?? links.commit;

return [
`\n- ${firstLine}${suffix ? ` (${suffix})` : ''}`,
...futureLines.map((l) => ` ${l}`),
].join('\n');
},
};

if (process.env.GITHUB_TOKEN) {
module.exports = gitHubChangelogFunctions;
} else {
console.warn(
`Defaulting to Git-based versioning.
Enable GitHub-based versioning by setting the GITHUB_TOKEN environment variable.
This requires a GitHub personal access token with the \`public_repo\` scope: https://github.com/settings/tokens/new`,
);

module.exports = defaultChangelogFunctions;
}
10 changes: 10 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": ["./changelog.js", { "repo": "seek-oss/eslint-config-seek" }],
"commit": false,
"linked": [],
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
name: Test & Release
name: Release

on:
- pull_request
- push
push:
branches:
- beta
- master

jobs:
test-and-release:
name: Test & Release
release:
name: Release
runs-on: ubuntu-latest
env:
CI: true
steps:
- name: Check out repo
uses: actions/checkout@main
with:
lfs: true

- name: Set up Node.js 14.x
- name: Set up Node.js 16.x
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes LTS tomorrow 🙂

uses: actions/setup-node@main
with:
node-version: 14.x
node-version: 16.x

- name: Install dependencies
run: yarn --immutable

- name: Test
run: yarn test

- name: Release
run: yarn release
uses: changesets/action@master
with:
publish: yarn release
version: yarn version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.SEEK_OSS_CI_NPM_TOKEN }}
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test

on:
- pull_request
- push

jobs:
test:
name: Test
runs-on: ubuntu-latest
env:
CI: true
steps:
- name: Check out repo
uses: actions/checkout@main

- name: Set up Node.js 16.x
uses: actions/setup-node@main
with:
node-version: 16.x

- name: Install dependencies
run: yarn --immutable

- name: Test
run: yarn test
30 changes: 7 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
{
"name": "eslint-config-seek",
"version": "0.0.0-development",
"version": "7.0.9",
"description": "ESLint configuration used by SEEK",
"main": ".eslintrc.js",
"repository": {
"type": "git",
"url": "https://github.com/seek-oss/eslint-config-seek.git"
},
"author": "Seek",
"author": "SEEK",
"license": "MIT",
"bugs": {
"url": "https://github.com/seek-oss/eslint-config-seek/issues"
},
"scripts": {
"release": "changeset release",
"test": "eslint .",
"commit": "git-cz",
"release": "semantic-release"
},
"husky": {
"hooks": {
"commit-msg": "commitlint --edit --extends seek"
}
"version": "changeset version && prettier --write ."
},
"homepage": "https://github.com/seek-oss/eslint-config-seek#readme",
"dependencies": {
Expand All @@ -39,25 +34,14 @@
"find-root": "^1.1.0"
},
"devDependencies": {
"@commitlint/cli": "^8.2.0",
"commitizen": "^4.0.3",
"commitlint-config-seek": "^1.0.0",
"cz-conventional-changelog": "^3.0.2",
"@changesets/cli": "2.17.0",
"@changesets/get-github-info": "0.5.0",
"eslint": "^7.14.0",
"husky": "^3.1.0",
"semantic-release": "^15.13.31",
"prettier": "2.4.1",
"typescript": "^4.1.2"
},
"release": {
"success": false
},
"peerDependencies": {
"eslint": ">=6",
"typescript": ">=3.3"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}