From e48e335ac3f913c8fba293ecb67d94071e3405d4 Mon Sep 17 00:00:00 2001 From: Ryan Ling Date: Tue, 26 Oct 2021 09:16:05 +1100 Subject: [PATCH 1/2] Migrate to Changesets It's looking like our config will require numerous breaking changes to get to ESLint v8 compatibility (#62). If we stuck with semantic-release we'd either need to get creative with branching, have one mega PR or release a bunch of intermediary major versions that add little value. Instead, switch to Changesets. This is used in a number of our OSS repos and makes it easier to bundle multiple changes into a release. We support previewing the release notes with and without a `GITHUB_TOKEN` via `yarn version`. --- .changeset/README.md | 8 + .changeset/changelog.js | 162 ++++++++++++++++++ .changeset/config.json | 10 ++ .../{test-and-release.yml => release.yml} | 26 +-- .github/workflows/test.yml | 26 +++ package.json | 30 +--- 6 files changed, 226 insertions(+), 36 deletions(-) create mode 100644 .changeset/README.md create mode 100644 .changeset/changelog.js create mode 100644 .changeset/config.json rename .github/workflows/{test-and-release.yml => release.yml} (61%) create mode 100644 .github/workflows/test.yml diff --git a/.changeset/README.md b/.changeset/README.md new file mode 100644 index 0000000..e5b6d8d --- /dev/null +++ b/.changeset/README.md @@ -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) diff --git a/.changeset/changelog.js b/.changeset/changelog.js new file mode 100644 index 0000000..eb9eaff --- /dev/null +++ b/.changeset/changelog.js @@ -0,0 +1,162 @@ +const { + 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; +} diff --git a/.changeset/config.json b/.changeset/config.json new file mode 100644 index 0000000..b81bf6d --- /dev/null +++ b/.changeset/config.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://unpkg.com/@changesets/config@1.6.1/schema.json", + "changelog": ["./changelog.js", { "repo": "seek-oss/eslint-config-seek" }], + "commit": false, + "linked": [], + "access": "public", + "baseBranch": "master", + "updateInternalDependencies": "patch", + "ignore": [] +} diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/release.yml similarity index 61% rename from .github/workflows/test-and-release.yml rename to .github/workflows/release.yml index 9f43c9b..7f0038e 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/release.yml @@ -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 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 }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..dc8849b --- /dev/null +++ b/.github/workflows/test.yml @@ -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 diff --git a/package.json b/package.json index 16dab21..0fd7277 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" - } } } From 36fe856d489f4607c664cc7316c1c9da57a82a73 Mon Sep 17 00:00:00 2001 From: Ryan Ling Date: Tue, 26 Oct 2021 09:43:10 +1100 Subject: [PATCH 2/2] Drop CSS Modules and Flow plugins --- .changeset/cuddly-ears-hide.md | 9 +++++++++ .changeset/wild-suits-float.md | 9 +++++++++ .eslintrc.js | 10 ++-------- package.json | 2 -- 4 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 .changeset/cuddly-ears-hide.md create mode 100644 .changeset/wild-suits-float.md diff --git a/.changeset/cuddly-ears-hide.md b/.changeset/cuddly-ears-hide.md new file mode 100644 index 0000000..482fff3 --- /dev/null +++ b/.changeset/cuddly-ears-hide.md @@ -0,0 +1,9 @@ +--- +'eslint-config-seek': major +--- + +Remove support for Flow + +SEEK has aligned on [TypeScript](https://www.typescriptlang.org/) for static type checking. [Flow](https://flow.org/) support was similarly removed in [sku 11](https://github.com/seek-oss/sku/releases/tag/v11.0.0). + +Affected projects should migrate to TypeScript. diff --git a/.changeset/wild-suits-float.md b/.changeset/wild-suits-float.md new file mode 100644 index 0000000..6f101da --- /dev/null +++ b/.changeset/wild-suits-float.md @@ -0,0 +1,9 @@ +--- +'eslint-config-seek': major +--- + +Remove support for CSS Modules + +[eslint-plugin-css-modules](https://github.com/atfzl/eslint-plugin-css-modules) is unmaintained, and SEEK has since moved on to [vanilla-extract](https://vanilla-extract.style/). + +Affected projects should migrate to vanilla-extract. diff --git a/.eslintrc.js b/.eslintrc.js index 9e3e23e..7c37a7c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -100,12 +100,8 @@ const baseConfig = { version: '>16', }, }, - plugins: ['react', 'react-hooks', 'css-modules'], - extends: [ - 'plugin:css-modules/recommended', - 'plugin:react/recommended', - 'prettier', - ], + plugins: ['react', 'react-hooks'], + extends: ['plugin:react/recommended', 'prettier'], rules: { ...baseRules, ...reactRules, @@ -159,7 +155,6 @@ const baseConfig = { es6: true, }, extends: [ - 'plugin:flowtype/recommended', 'plugin:import/errors', 'plugin:import/warnings', 'plugin:import/typescript', @@ -171,7 +166,6 @@ const baseConfig = { }, }, }, - plugins: ['flowtype'], rules: { 'no-use-before-define': [ERROR, { functions: false }], 'no-unused-expressions': ERROR, diff --git a/package.json b/package.json index 0fd7277..05cbe9f 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,7 @@ "babel-eslint": "^10.1.0", "eslint-config-prettier": "^6.11.0", "eslint-import-resolver-node": "^0.3.3", - "eslint-plugin-css-modules": "^2.11.0", "eslint-plugin-cypress": "^2.11.1", - "eslint-plugin-flowtype": "^5.1.3", "eslint-plugin-import": "^2.21.2", "eslint-plugin-jest": "^25.2.2", "eslint-plugin-react": "^7.20.0",