Repository navigation
Add eslint & prettier #5
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
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
49674d5
Readme, package.json, changesets, and README
jaredly 8d8993d
Bring over our composite actions from Khan/perseus
jaredly 2ecc423
Add scripts to build & publish our github actions, to 'bare tags' in …
jaredly 2e88c2a
cs
jaredly 90912bc
cs
jaredly 9872ee4
move to utils
jaredly 83543dd
Add eslint & prettier
jaredly 569baa0
action
jaredly ba2bf81
separate run
jaredly b39f5e0
refactor out the tricky bit
jaredly feb1417
Merge branch 'publish' into lints
jaredly 753d6f7
fix
jaredly b36e072
lint
jaredly 45ad3b3
Merge branch 'main' into publish
jaredly a4eee22
fix
jaredly 3b4a112
ok
jaredly bcd4999
Merge branch 'main' into lints
jaredly 6497194
cs
jaredly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * This is a very stripped-down eslintrc, because @khanacademy/eslint-config | ||
| * assumes you're using react & flow (and requires a lot of dependencies along | ||
| * with it). | ||
| */ | ||
| const khan = require("@khanacademy/eslint-config"); | ||
|
|
||
| // Only keep the rules that have no prefix (so are included in eslint core) | ||
| // and the prettier rule. | ||
| const basicRules = {}; | ||
| Object.keys(khan.rules).forEach((key) => { | ||
| if (!key.includes("/") || key.startsWith("prettier/")) { | ||
| basicRules[key] = khan.rules[key]; | ||
| } | ||
| }); | ||
|
|
||
| module.exports = { | ||
| extends: ["eslint:recommended", "prettier"], | ||
| plugins: ["prettier"], | ||
| rules: basicRules, | ||
| env: { | ||
| node: true, | ||
| }, | ||
| parserOptions: { | ||
| sourceType: "module", | ||
| ecmaVersion: 2022, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| name: Node CI | ||
|
|
||
| on: | ||
| - pull_request | ||
|
|
||
| jobs: | ||
| check: | ||
| name: Lints | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - uses: Khan/actions@check-for-changeset-v0.0.0 | ||
| - uses: Khan/actions@shared-node-cache-v0.0.0 | ||
| - run: yarn lint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| release: | ||
| name: Release | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest] | ||
| node-version: [16.x] | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v2 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
|
|
||
| - name: Publish as git tags | ||
| run: node utils/run-publish.mjs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| module.exports = require("@khanacademy/eslint-config/.prettierrc.js"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,16 @@ | |
| "workspaces": [ | ||
| "actions/*" | ||
| ], | ||
| "scripts": { | ||
| "lint": "eslint --ext .js,.mjs .", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't realize you pass a comma separated list to |
||
| "fix": "yarn lint --fix" | ||
| }, | ||
| "devDependencies": { | ||
| "@changesets/cli": "^2.22.0" | ||
| "@changesets/cli": "^2.22.0", | ||
| "eslint": "^8.15.0", | ||
| "eslint-config-prettier": "^8.5.0", | ||
| "eslint-plugin-prettier": "^4.0.0", | ||
| "@khanacademy/eslint-config": "^0.1.0", | ||
| "prettier": "^2.6.2" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /** | ||
| * Building a package currently only consists of processing | ||
| * the action.yml to handle any references to other actions in | ||
| * this repo. | ||
| */ | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
|
|
||
| function copyDir(src, dest) { | ||
| const entries = fs.readdirSync(src, {withFileTypes: true}); | ||
| fs.mkdirSync(dest, {recursive: true}); | ||
|
|
||
| for (const entry of entries) { | ||
| const srcPath = path.join(src, entry.name); | ||
| const destPath = path.join(dest, entry.name); | ||
|
|
||
| if (entry.isDirectory()) { | ||
| copyDir(srcPath, destPath); | ||
| } else { | ||
| fs.copyFileSync(srcPath, destPath); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export const processActionYml = ( | ||
| name, | ||
| packageJsons, | ||
| actionYml, | ||
| monorepoName, | ||
| ) => { | ||
| const replacements = []; | ||
| Object.keys(packageJsons[name].dependencies).forEach((depName) => { | ||
| replacements.push({ | ||
| from: new RegExp(`\\buses: ${depName}\\b`, "g"), | ||
| to: `uses: ${monorepoName}#${depName}-v${packageJsons[depName].version}`, | ||
| }); | ||
| }); | ||
| replacements.forEach(({from, to}) => { | ||
| actionYml = actionYml.replace(from, to); | ||
| }); | ||
|
|
||
| return actionYml; | ||
| }; | ||
|
|
||
| export const buildPackage = (name, packageJsons, monorepoName) => { | ||
| const dist = `actions/${name}/dist`; | ||
| if (fs.existsSync(dist)) { | ||
| fs.rmSync(dist, {recursive: true}); | ||
| } | ||
| copyDir(`actions/${name}`, dist); | ||
| if (packageJsons[name].dependencies) { | ||
| const yml = `actions/${name}/dist/action.yml`; | ||
| const actionYml = fs.readFileSync(yml, "utf8"); | ||
| fs.writeFileSync( | ||
| yml, | ||
| processActionYml(name, packageJsons, actionYml, monorepoName), | ||
| ); | ||
| } | ||
| return dist; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * This file determines which actions need to be published, | ||
| * "builds" them, and "publishes" them as git tags on the current repo. | ||
| * Building currently consists of checking the `action.yml` | ||
| * for references to other actions in this repo and replacing them | ||
| * with the appropriate pinned references. | ||
| */ | ||
| import fs from "fs"; | ||
| import {execSync} from "child_process"; | ||
| import {buildPackage} from "./build.mjs"; | ||
|
|
||
| export const checkTag = (tag) => { | ||
| try { | ||
| execSync(`git show-ref --tags ${tag}`); | ||
| } catch (err) { | ||
| return false; | ||
| } | ||
| return true; | ||
| }; | ||
|
|
||
| export const publishDirectoryAsTag = (distPath, origin, tag, dryRun) => { | ||
| const cmds = [ | ||
| `git init .`, | ||
| `git add .`, | ||
| `git commit -m publish`, | ||
| `git remote add origin ${origin}`, | ||
| `git tag ${tag}`, | ||
| ]; | ||
| if (!dryRun) { | ||
| cmds.push(`git push origin ${tag}`); | ||
| } | ||
| cmds.forEach((cmd) => { | ||
| execSync(cmd, {cwd: distPath}); | ||
| }); | ||
| }; | ||
|
|
||
| export const collectPackageJsons = (packageNames) => { | ||
| const packageJsons = {}; | ||
| packageNames.forEach((name) => { | ||
| const pkg = JSON.parse( | ||
| fs.readFileSync(`actions/${name}/package.json`, "utf8"), | ||
| ); | ||
| packageJsons[pkg.name] = pkg; | ||
| }); | ||
| return packageJsons; | ||
| }; | ||
|
|
||
| export const publishAsNeeded = (packageNames, dryRun = false) => { | ||
| execSync(`git fetch --tags`); | ||
| const origin = execSync(`git remote get-url origin`, { | ||
| encoding: "utf8", | ||
| }).trim(); | ||
| const packageJsons = collectPackageJsons(packageNames); | ||
|
|
||
| packageNames.forEach((name) => { | ||
| const version = packageJsons[name].version; | ||
| const tag = `${name}-v${version}`; | ||
| if (!checkTag(tag)) { | ||
| const distPath = buildPackage(name, packageJsons, `Khan/actions`); | ||
| publishDirectoryAsTag(distPath, origin, tag, dryRun); | ||
| } | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** | ||
| * This script runs whenever a change lands to the 'main' branch, | ||
| * publishing any new versions of actions that are needed. | ||
| */ | ||
| import fs from "fs"; | ||
| import {publishAsNeeded} from "./publish.mjs"; | ||
|
|
||
| const [_, __, ...args] = process.argv; | ||
| const dryRun = args.includes("--dry-run"); | ||
| const packageNames = fs.readdirSync("actions"); | ||
| publishAsNeeded(packageNames, dryRun); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look at
khan/eslint-config-khanand see that everything's listed as a peer dep. I wonder if we should change that.