Skip to content

Commit

Permalink
ci(betterer): Remove betterer, re-add Danger (#8111)
Browse files Browse the repository at this point in the history
ci(betterer): Remove betterer, readd Danger
  • Loading branch information
damassi authored Jan 31, 2023
1 parent 2c9536e commit 71aaa78
Show file tree
Hide file tree
Showing 9 changed files with 720 additions and 2,373 deletions.
1,917 changes: 0 additions & 1,917 deletions .betterer.results

This file was deleted.

68 changes: 0 additions & 68 deletions .betterer.ts

This file was deleted.

12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,17 @@ jobs:
name: Update metaphysics
command: yarn update-metaphysics

check-code-improvements:
check-code:
executor:
name: node/default
tag: "16.18.0"
steps:
- checkout
- generate-checksums
- install-node-modules
- node/install-packages:
pkg-manager: yarn
- run:
name: Check code improvements
command: yarn ci:betterer-check
name: Danger
command: yarn danger ci --verbose

check-flags:
environment:
Expand Down Expand Up @@ -527,7 +527,7 @@ workflows:
- play_store_submission
- update-changelog

- check-code-improvements:
- check-code:
filters:
branches:
ignore:
Expand Down
2 changes: 0 additions & 2 deletions .gitattributes
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
2 changes: 1 addition & 1 deletion .lintstagedrc.mjs
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"],
}
61 changes: 0 additions & 61 deletions betterer-clean-reporter.ts

This file was deleted.

113 changes: 113 additions & 0 deletions dangerfile.ts
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)
})()
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,18 @@
"main": "index-common.js",
"scripts": {
"android": "react-native run-android",
"betterer": "betterer",
"betterer-clean": "betterer --reporter betterer-clean-reporter.ts",
"betterer:all": "yarn betterer-clean",
"betterer:update!": "yarn betterer-clean --update",
"betterer:original": "yarn betterer",
"betterer:show": "yarn betterer results",
"bundle-for-native-ci:ios": "node --expose-gc --max_old_space_size=8192 ./node_modules/react-native/local-cli/cli.js bundle --platform=ios --dev=false --entry-file=index.tests.ios.js --bundle-output dist/jsbundle.js --sourcemap-output dist/jsbundle.js.map --assets-dest dist",
"bundle:android": "NODE_OPTIONS=--max_old_space_size=8192 react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --sourcemap-output android/app/src/main/assets/index.android.bundle.map --assets-dest android/app/src/main/res",
"bundle:ios": "react-native bundle --platform=ios --dev=false --entry-file=index.ios.js --bundle-output dist/jsbundle.js --sourcemap-output dist/jsbundle.js.map --assets-dest dist",
"check-flags": "./scripts/check-flags/check-flags.js",
"ci": "yarn ci:type-check && yarn ci:lint && yarn prettier-project -l && rm -rf src/__generated__ && yarn relay && yarn ci:test",
"ci:betterer-check": "yarn betterer ci",
"ci:lint": "yarn lint --format json --out eslint-errors.json",
"ci:skip-native-if-possible": "node scripts/ci-skip-native-if-possible.js",
"ci:type-check": "tsc --pretty false | tee tsc_raw.log",
"clean": "yarn clean-ios; yarn clean-android",
"clean-android": "cd android; ./gradlew clean cleanBuildCache; cd -",
"clean-ios": "yarn rimraf ~/Library/Developer/Xcode/DerivedData",
"danger": "danger",
"deploy-beta": "./scripts/deploy-beta-both",
"doctor": "./scripts/doctor.js",
"flip_table": "./scripts/flip-table",
Expand Down Expand Up @@ -225,8 +219,6 @@
"@babel/preset-react": "7.18.6",
"@babel/preset-typescript": "7.18.6",
"@babel/runtime": "7.16.7",
"@betterer/cli": "5.4.0",
"@betterer/regexp": "5.4.0",
"@octokit/rest": "16.34.0",
"@omakase/cli": "0.0.10",
"@react-native-community/cli-platform-ios": "6.2.0",
Expand Down Expand Up @@ -278,6 +270,7 @@
"chalk": "2.4.2",
"check-dependencies": "1.1.0",
"concurrently": "7.0.0",
"danger": "11.2.3",
"dedent": "0.7.0",
"dotenv": "8.2.0",
"eslint": "8.32.0",
Expand Down
Loading

0 comments on commit 71aaa78

Please sign in to comment.