-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(betterer): Remove betterer, re-add Danger (#8111)
ci(betterer): Remove betterer, readd Danger
- Loading branch information
Showing
9 changed files
with
720 additions
and
2,373 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
CHANGELOG.yml merge=union | ||
.betterer.results merge=betterer | ||
|
||
src/__generated__/*.graphql.ts linguist-generated=true | ||
src/__generated__/*.queryMap.json linguist-generated=true | ||
.betterer.results linguist-generated=true |
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export default { | ||
"*": ["yarn secrets:check:staged", "yarn betterer:all && git add .betterer.results"], | ||
"*": ["yarn secrets:check:staged"], | ||
"*.@(ts|tsx)": ["yarn lint", "yarn prettier-write"], | ||
"*.@(json|md)": ["yarn prettier-write"], | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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,113 @@ | ||
import * as fs from "fs" | ||
import { danger, fail, warn } from "danger" | ||
// TypeScript thinks we're in React Native, | ||
// so the node API gives us errors: | ||
|
||
/** | ||
* Helpers | ||
*/ | ||
const typescriptOnly = (file: string) => file.includes(".ts") | ||
const filesOnly = (file: string) => fs.existsSync(file) && fs.lstatSync(file).isFile() | ||
|
||
// Modified or Created can be treated the same a lot of the time | ||
const getCreatedFileNames = (createdFiles: string[]) => createdFiles.filter(filesOnly) | ||
|
||
const testOnlyFilter = (filename: string) => filename.includes(".tests") && typescriptOnly(filename) | ||
|
||
/** | ||
* Danger Rules | ||
*/ | ||
// We are trying to migrate away from moment towards luxon | ||
const preventUsingMoment = () => { | ||
const newMomentImports = getCreatedFileNames(danger.git.created_files).filter((filename) => { | ||
const content = fs.readFileSync(filename).toString() | ||
return content.includes('from "moment"') || content.includes('from "moment-timezone"') | ||
}) | ||
if (newMomentImports.length > 0) { | ||
warn(`We are trying to migrate away from moment towards \`luxon\`, but found moment imports in the following new files: | ||
${newMomentImports.map((filename) => `- \`${filename}\``).join("\n")} | ||
See [docs](https://moment.github.io/luxon/api-docs/index.html). | ||
`) | ||
} | ||
} | ||
|
||
// We are trying to migrate away from test-renderer towards @testing-library/react-native | ||
const preventUsingTestRenderer = () => { | ||
const newTRImports = getCreatedFileNames(danger.git.created_files) | ||
.filter(testOnlyFilter) | ||
.filter((filename) => { | ||
const content = fs.readFileSync(filename).toString() | ||
return ( | ||
content.includes('from "app/utils/tests/renderWithWrappers"') && | ||
(content.includes("renderWithWrappersLEGACY ") || | ||
content.includes("renderWithWrappersLEGACY,")) | ||
) | ||
}) | ||
if (newTRImports.length > 0) { | ||
warn(`We are trying to migrate away from \`react-test-renderer\` towards \`@testing-library/react-native\`, but found Test-Renderer imports in the following new unit test files: | ||
${newTRImports.map((filename) => `- \`${filename}\``).join("\n")} | ||
See [\`Pill.tests.tsx\`](https://github.com/artsy/eigen/blob/2f32d462bb3b4ce358c8a14e3ed09b42523de8bd/src/palette/elements/Pill/__tests__/Pill-tests.tsx) as an example, or [the docs](https://callstack.github.io/react-native-testing-library/docs/api-queries). | ||
`) | ||
} | ||
} | ||
|
||
// Validates that we've not accidentally let in a testing | ||
// shortcut to simplify dev work | ||
const verifyRemainingDevWork = () => { | ||
const modified = danger.git.modified_files | ||
const editedFiles = modified.concat(danger.git.created_files) | ||
const testFiles = editedFiles.filter((f) => f?.includes("Tests") && f.match(/\.(swift|m)$/)) | ||
|
||
const testingShortcuts = ["fdescribe(", "describe.only(", "fit(", "fit(", "it.only("] | ||
for (const file of testFiles) { | ||
const content = fs.readFileSync(file).toString() | ||
for (const shortcut of testingShortcuts) { | ||
if (content.includes(shortcut)) { | ||
fail(`Found a testing shortcut in ${file}`) | ||
} | ||
} | ||
} | ||
|
||
// A shortcut to say "I know what I'm doing thanks" | ||
const knownDevTools = danger.github.pr.body?.includes("#known") ?? false | ||
|
||
// These files are ones we really don't want changes to, except in really occasional | ||
// cases, so offer a way out. | ||
const devOnlyFiles = ["Artsy.xcodeproj/xcshareddata/xcschemes/Artsy.xcscheme"] | ||
for (const file of devOnlyFiles) { | ||
if (modified.includes(file) && !knownDevTools) { | ||
fail( | ||
"Developer Specific file shouldn't be changed, you can skip by adding #known to the PR body and re-running CI" | ||
) | ||
} | ||
} | ||
} | ||
|
||
// Force the usage of WebPs | ||
const IMAGE_EXTENSIONS_TO_AVOID = ["png", "jpg", "jpeg"] | ||
const IMAGE_EXTENSIONS = [...IMAGE_EXTENSIONS_TO_AVOID, "webp"] | ||
|
||
export const useWebPs = (fileNames: string[]) => { | ||
const hasNonWebImages = Boolean( | ||
fileNames | ||
.map((fileName) => fileName.split(".").pop() || "") | ||
.filter((fileExtension) => { | ||
return IMAGE_EXTENSIONS.includes(fileExtension) | ||
}) | ||
.find((imageFileExtension) => IMAGE_EXTENSIONS_TO_AVOID.includes(imageFileExtension)) | ||
) | ||
|
||
if (hasNonWebImages) { | ||
warn( | ||
"❌ **It seems like you added some non WebP images to Eigen, please convert them to WebPs using `source images/script.sh` script **" | ||
) | ||
} | ||
} | ||
;(async function () { | ||
// const newCreatedFileNames = getCreatedFileNames(danger.git.created_files) | ||
|
||
preventUsingMoment() | ||
preventUsingTestRenderer() | ||
verifyRemainingDevWork() | ||
// useWebPs(newCreatedFileNames) | ||
})() |
This file contains 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
Oops, something went wrong.