Skip to content

Commit

Permalink
feat(PPDSC-2162): codemods setup package (#222)
Browse files Browse the repository at this point in the history
* feat(PPDSC-2162): init codemod scripts

* feat(PPDSC-2162): make it cli

* feat(PPDSC-2162): adjust CI

* feat(PPDSC-2162): add version sync script

* feat(PPDSC-2162): update package.json

* feat(PPDSC-2162): add extra arguments

* feat(PPDSC-2162): add tests and update readme

* feat(PPDSC-2162): add failing test

* feat(PPDSC-2162): run unit tests in CI

* feat(PPDSC-2162): remove fake unit test

* feat(PPDSC-2162): test prettier

* feat(PPDSC-2162): test prettier

* feat(PPDSC-2162): fix prettier

* feat(PPDSC-2162): rename to codemod

* feat(PPDSC-2162): update readme

* feat(PPDSC-2162): add public access to npm

* feat(PPDSC-2162): make access public to npm

* feat(PPDSC-2162): address comments

* feat(PPDSC-2162): address comments

* feat(PPDSC-2162): branch circleci config

* feat(PPDSC-2162): fix typo

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): add makefile

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): fix circleci

* feat(PPDSC-2162): circle-ci

* feat(PPDSC-2162): reverse config

* feat(PPDSC-2162): adjust pipeline

* feat(PPDSC-2162): adjust pipeline

* feat(PPDSC-2162): adjust pipeline

* Bumping to version v10.0.0 - [skip ci]

* feat(PPDSC-2162): fix package.json version

* feat(PPDSC-2162): bump version of codemode package

* feat(PPDSC-2162): remove fixed version

* feat(PPDSC-2162): cleanup

* feat(PPDSC-2162): change cache

* feat(PPDSC-2162): add codemod jobs to main

* feat(PPDSC-2162): fix circle

* feat(PPDSC-2162): update CI for codemods

* feat(PPDSC-2162): fix yml file

* feat(PPDSC-2162): fix yml file 2

* feat(PPDSC-2162): fix yml file 3

* feat(PPDSC-2162): fix yml file 4

* feat(PPDSC-2162): fix yml file 5

* feat(PPDSC-2162): fix yml file 6

* feat(PPDSC-2162): fix yml file 7

* feat(PPDSC-2162): fix yml file 8

* feat(PPDSC-2162): fix yml file 9

* feat(PPDSC-2162): fix yml file 10

* feat(PPDSC-2162): fix yml file 11

* feat(PPDSC-2162): update deps

* feat(PPDSC-2162): update deps

* feat(PPDSC-2162): clean

* feat(PPDSC-2162): ci pull_request_codemod

* feat(PPDSC-2162): ci main_codemod

* feat(PPDSC-2162): bumping codemod version to v1.2.3 - [skip ci]

* feat(PPDSC-2162): add release codemod jobs

* feat(PPDSC-2162): fix config

* feat(PPDSC-2162): adjust ci

* feat(PPDSC-2162): update to slack/notify

* feat(PPDSC-2162): rename a job

* feat(PPDSC-2162): move everything to lib folder

* feat(PPDSC-2162): fix ci cache

* feat(PPDSC-2162): fix ci cache

* feat(PPDSC-2162): update author in package json

* feat(PPDSC-2162): fix version in package json

* feat(PPDSC-2162): add author

* feat(PPDSC-2162): revert in ci

* feat(PPDSC-2162): clean

* feat(PPDSC-2162): add popover export
  • Loading branch information
mutebg authored Jul 13, 2022
1 parent 2d35315 commit ec0c2e8
Show file tree
Hide file tree
Showing 21 changed files with 5,020 additions and 4 deletions.
235 changes: 232 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,125 @@ jobs:
- slack/notify:
<<: *slack_notify

# ========== CODEMOD TASKS ==========

install_deps_codemod:
executor: node
steps:
- checkout
- restore_cache:
keys:
- yarn-build-v1-codemod-{{ checksum "lib/codemod/yarn.lock" }}
- yarn-build-v1-codemod-
- run:
name: Codemode Dependencies Install
command: cd lib/codemod && make install
- save_cache:
key: yarn-build-v1-codemod-{{ checksum "lib/codemod/yarn.lock" }}
paths:
- ~/.cache
- persist_to_workspace:
root: ./
paths:
- lib/codemod/node_modules/*
- slack/notify:
<<: *slack_notify

lint_codemod:
executor: node
steps:
- checkout
- attach_workspace:
at: ~/project
- run:
name: Lint Codemod
command: cd lib/codemod && make lint
- slack/notify:
<<: *slack_notify

test_unit_codemod:
executor: node
steps:
- checkout
- attach_workspace:
at: ~/project
- run:
name: Unit Testing Codemod
command: cd lib/codemod && make unit_test
environment:
JEST_JUNIT_OUTPUT_DIR: ./reports/codemod-junit/
- store_test_results:
path: ./reports/codemod-junit/
- store_artifacts:
path: ./reports/codemod-junit
- slack/notify:
<<: *slack_notify

publish_npm_codemod:
parameters:
publish_dev:
type: boolean
default: false
executor: node
steps:
- checkout
- attach_workspace:
at: ~/project
- run:
name: Add NPM login credentionals
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
- run:
name: Set github identity
command: cd lib/codemod && make set_git_identity
- when:
condition: << parameters.publish_dev >>
steps:
- run:
name: Publish codemod to NPM
command: cd lib/codemod && make publish_npm_dev
- unless:
condition: << parameters.publish_dev >>
steps:
- run:
name: Publish codemod to NPM
command: cd lib/codemod && make publish_npm;
- slack/notify:
<<: *slack_notify

bump_version_codemod:
executor: node
parameters:
version:
type: string
steps:
- checkout
- run:
name: Set github identity
command: cd lib/codemod && make set_git_identity
- run:
name: Bump version
command: cd lib/codemod && make bump_version NEW_VERSION=<< parameters.version >>
- slack/notify:
<<: *slack_notify

delete_trigger_release_tag_codemod:
executor: node
parameters:
version:
type: string
steps:
- checkout
- run:
name: Set github identity
command: cd lib/codemod && make set_git_identity
- run:
name: Delete trigger-release-codemod@ tag
command: cd lib/codemod && make delete_trigger_release_tag VERSION=<< parameters.version >>

merge_checker:
executor: node
steps:
- run: echo "Merge checker"

# ========== FILTERS START ==========

Expand All @@ -985,10 +1102,25 @@ only_on_version_tag: &only_on_version_tag
branches:
ignore: /.*/

only_on_trigger_release_tag_codemod: &only_on_trigger_release_tag_codemod
filters:
tags:
# The pattern must match the tag created in the github release interface. E.g: "[email protected]"
only: /^trigger-release-codemod@([0-9])(\.([0-9])){2}$/
branches:
ignore: /.*/

only_on_version_tag_codemod: &only_on_version_tag_codemod
filters:
tags:
# The pattern must match the tag created and pushed by bump_version_codemod make script. E.g: "codemod-v5.0.1"
only: /^codemod-v([0-9])(\.([0-9])){2}$/
branches:
ignore: /.*/

# ========== FILTERS END ==========

workflows:

pull_request:
when:
matches:
Expand Down Expand Up @@ -1140,9 +1272,44 @@ workflows:
requires:
- deploy_to_s3

pull_request_codemod:
when:
matches:
# Supporting Pr branches starting with feat/, docs/, fix/, chore/, style/, refactor/, perf/, test/, etc.
pattern: '^build\/.*|chore\/.*|ci\/.*|docs\/.*|feat\/.*|fix\/.*|improvement\/.*|perf\/.*|refactor\/.*|revert.*\/.*|style\/.*|test\/.*|^dependabot\/.*'
value: << pipeline.git.branch >>
jobs:
- install_deps_codemod

- test_unit_codemod:
requires:
- install_deps_codemod

- lint_codemod:
requires:
- install_deps_codemod

- approve_publish_npm_pr_codemod:
type: approval
requires:
- test_unit_codemod
- lint_codemod

- merge_checker:
requires:
- test_unit_codemod
- lint_codemod

- publish_npm_codemod:
name: publish_npm_pr_codemod
context: ncu-product-platforms-context
publish_dev: true
requires:
- approve_publish_npm_pr_codemod

main:
when:
equal: [ main, << pipeline.git.branch >> ]
equal: [main, << pipeline.git.branch >>]
jobs:
- init_aws:
context: ncu-product-platforms-context
Expand Down Expand Up @@ -1294,13 +1461,47 @@ workflows:
- eks_flux_deploy_dev_to_prod
# end

main_codemod:
when:
equal: [main, << pipeline.git.branch >>]
jobs:
- install_deps_codemod

- test_unit_codemod:
requires:
- install_deps_codemod

- lint_codemod:
requires:
- install_deps_codemod

- approve_publish_npm_pr_codemod:
type: approval
requires:
- test_unit_codemod
- lint_codemod

- publish_npm_codemod:
name: publish_npm_pr_codemod
context: ncu-product-platforms-context
publish_dev: true
requires:
- approve_publish_npm_pr_codemod

on_trigger_release_tag:
jobs:
- bump_version:
<<: *only_on_trigger_release_tag
context: ncu-product-platforms-context
version: $(echo << pipeline.git.tag >> | cut -f2 -d "@")

on_trigger_release_tag_codemod:
jobs:
- bump_version_codemod:
<<: *only_on_trigger_release_tag_codemod
context: ncu-product-platforms-context
version: $(echo << pipeline.git.tag >> | cut -f2 -d "@")

on_release_version_tag:
# Workflow's jobs triggered by the bump_version make script, which creates and pushes a new version tag e.g: "v5.0.1".
jobs:
Expand Down Expand Up @@ -1438,4 +1639,32 @@ workflows:
environment: prod
requires:
- eks_flux_deploy_prod
#

on_release_version_tag_codemod:
# Workflow's jobs triggered by the bump_version_codemod make script, which creates and pushes a new version tag e.g: "codemod-v5.0.1".
jobs:
- delete_trigger_release_tag_codemod:
<<: *only_on_version_tag_codemod
context: ncu-product-platforms-context
version: $(echo << pipeline.git.tag >> | cut -f2 -d "v")

- install_deps_codemod:
<<: *only_on_version_tag_codemod

- test_unit_codemod:
<<: *only_on_version_tag_codemod
requires:
- install_deps_codemod

- lint_codemod:
<<: *only_on_version_tag_codemod
requires:
- install_deps_codemod

- publish_npm_codemod:
<<: *only_on_version_tag_codemod
context: ncu-product-platforms-context
publish_dev: false
requires:
- test_unit_codemod
- lint_codemod
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public
site/static
site/next-env.d.ts
src/icons/filled/material
src/icons/outlined/material
src/icons/outlined/material
lib/codemod
3 changes: 3 additions & 0 deletions lib/codemod/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
lcov-report
43 changes: 43 additions & 0 deletions lib/codemod/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: ['airbnb-typescript', 'plugin:prettier/recommended', 'prettier'],
parserOptions: {
project: 'tsconfig.eslint.json',
},
plugins: ['cup', 'header', 'prettier', 'import'],
env: {
jest: true,
},
globals: {
page: true,
browser: true,
context: true,
window: true,
},
rules: {
'no-undef': 'off',
// The latest eslint package will flag type imports and cannot be fixed by setting devDependencies to true.
// There is an open pr for this: https://github.com/import-js/eslint-plugin-import/issues/1618
// This rule has been disabled in individual files instead
'import/no-extraneous-dependencies': [
'error',
{optionalDependencies: false, devDependencies: true},
],
'react/jsx-filename-extension': 'off',
'import/prefer-default-export': 'off',
'arrow-body-style': ['error', 'as-needed'],
'@typescript-eslint/no-explicit-any': 'error',
'import/no-unresolved': ['error', {ignore: ['csstype']}],
'prettier/prettier': [
'error',
{
singleQuote: true,
trailingComma: 'all',
bracketSpacing: false,
arrowParens: 'avoid',
},
],
'no-plusplus': ['error', {allowForLoopAfterthoughts: true}],
},
};
1 change: 1 addition & 0 deletions lib/codemod/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
6 changes: 6 additions & 0 deletions lib/codemod/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": false,
"arrowParens": "avoid"
}
34 changes: 34 additions & 0 deletions lib/codemod/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
SHORT_GIT_HASH := $(shell echo ${CIRCLE_SHA1} | cut -c -9)

install:
yarn install --frozen-lockfile;

lint:
yarn lint

unit_test:
yarn test:ci

publish_npm:
yarn publish --no-git-tag-version --access public;

publish_npm_dev:
yarn publish --no-git-tag-version --new-version 0.0.0-${SHORT_GIT_HASH} --tag unstable --access public;

set_git_identity:
git config --global user.email "[email protected]"
git config --global user.name "Product Platforms Service"

bump_version:
git checkout main
git pull
yarn config set version-git-message "Bumping Codemod version to v%s - [skip ci]"
yarn config set version-tag-prefix "codemod-v"
echo "Updating package.json and creating a tag for `${NEW_VERSION}`"
yarn version --new-version ${NEW_VERSION}
git push
git push origin codemod-v${NEW_VERSION}

delete_trigger_release_tag:
git checkout main
git push origin --delete trigger-release-codemod@${VERSION}
Loading

0 comments on commit ec0c2e8

Please sign in to comment.