CI Injection to Code Base

The Problem

// 1mg.com
<a href="https://www.facebook.com/1mgOfficial/" target="_blank">
  Facebook Page
</a>
// 1mg.com
<a href="https://www.facebook.com/1mgOfficial/" target="_blank" rel="noopener">
  Facebook Page
</a>
  • rel="noopener" prevents the new page from being able to access the window.opener property and ensures it runs in a separate process.
  • rel="noreferrer" attribute has the same effect but also prevents the Referer header from being sent to the new page.

Solution?

Git Hooks

scripts/git-hooks/pre-commit

STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep "js$")
if [[ "$STAGED_FILES" = "" ]]; then
  printf "ESLint is not required.\n\n"
  exit 0
fi


printf "Running lint"

for FILE in $STAGED_FILES
do
  ./node_modules/eslint/bin/eslint.js --fix "$FILE"
  if [[ "$?" == 0 ]]; then
      echo "Lint passed: $FILE"
  else
      FAILED_FILES="$FAILED_FILES\n$FILE"
      PASS=false
  fi
done

if ! ($PASS); then
  printf "ESLint Failed:$FAILED_FILES \n\n\n"
  exit 1
else
  printf "ESLint Passed!\n"
fi

nevercode.io

  • Fast feedback loop.
  • Increase transparency and visibility
  • Avoid “integration hell”
  • Detect and fix issues early
  • Improve quality and testability

Continuous Integration

scripts/jenkins/WatchDog-automation.sh

 1. Update Branch
 2. Run npm install
 3. Run build
 4. Fetch commit file changes via GitHub API
 5. Run Lint on the given files.
 6. If Lint fails, exit with failure
 7. Fetch PR data via GitHub API
 8. Else run Lint on files in the PR.
 9. If Fails, exit with failure
10. If there are too many deletions, exit with failure
11. Exit with success

fin.

Continuous Integration Injection to Code Base

By Prabhanshu Attri

Continuous Integration Injection to Code Base

Talk at 1MG. Problem: Unnecessary and non-standardized code changes make their way to production due to many factors. Currently, we are solely dependant on the reviewer to ensure the code quality, which is a very inefficient process. A code reviewer may miss a lot of checks and unstandardized practices crawl into the existing codebase. Solution: By using Jenkins as CI Server an automated process is built to verify that the code quality is ensured and not compromised at the hands of the reviewer. Benefits: A step towards seamless continuous integration and error detection. This can reduce production issues and enforce industry level coding standards. This can be extended further towards an automated deployment. Short term benefits: Bit by bit code improvement by individual developers, leading to the progressive implementation of coding guidelines. Less prone to huge blunders such as more than 10,000 lines of code deletions. Long term benefits: Cultivating a habit of following standard guidelines will improve areas like replacing console errors with sentry/raven logging system-wide. Code stability and improvements as a whole and following on common standard across all teams.

  • 1,007