Skip to content

Commit

Permalink
feat: initial modular cli
Browse files Browse the repository at this point in the history
  • Loading branch information
maxjeffos committed Feb 4, 2021
1 parent 86f4609 commit 9c7b3df
Show file tree
Hide file tree
Showing 22 changed files with 374 additions and 55 deletions.
154 changes: 129 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ defaults: &defaults
node_version:
type: string
default: ''
use_npm7:
type: boolean
default: true
working_directory: ~/snyk

windows_defaults: &windows_defaults
Expand All @@ -20,12 +23,15 @@ commands:
install_deps:
description: Install dependencies
steps:
- run:
name: Use snyk-main npmjs user
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
- run:
name: Install dependencies
command: npm install
update_local_npmrc_linux:
description: Update local .npmrc file (Linux)
steps:
- run:
name: Update local .npmrc file (Linux)
command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
build_ts:
description: Build js files from ts
steps:
Expand Down Expand Up @@ -81,19 +87,19 @@ commands:
- run:
name: Installing sbt
command: sdk install sbt 1.3.12
install_node_npm:
description: Install correct Node version
install_node_windows:
description: Install the given Node version on Windows using Chocolatey
parameters:
node_version:
type: string
default: ''
steps:
- run:
name: Install correct version of Node
command: nvm install << parameters.node_version >>
- run:
name: Use correct version of Node
command: nvm use << parameters.node_version >>
name: Install Node with Chocolatey
command: |
$current_node_version = node --version
nvm uninstall $current_node_version
choco install nodejs --version=<< parameters.node_version >>
install_shellspec:
description: Install Shellspec
steps:
Expand All @@ -115,6 +121,20 @@ commands:
- run:
name: Run CLI help text builder
command: npm run generate-help
install_github_cli:
description: Install GitHub CLI (gh)
steps:
- run:
name: Install GitHub CLI (gh)
command: |
mkdir gh-download
curl -Lo ./gh-download/gh_1.3.1_linux_amd64.tar.gz https://github.com/cli/cli/releases/download/v1.3.1/gh_1.3.1_linux_amd64.tar.gz
tar -xf ./gh-download/gh_1.3.1_linux_amd64.tar.gz --directory gh-download
chmod a+x gh-download/gh_1.3.1_linux_amd64/bin/gh
mkdir -p /home/circleci/bin
mv gh-download/gh_1.3.1_linux_amd64/bin/gh /home/circleci/bin
which gh
gh --version
jobs:
regression-test:
Expand All @@ -127,6 +147,12 @@ jobs:
version: 19.03.13
# docker_layer_caching: true
- install_shellspec
- run:
name: Install npm@7
command: |
sudo npm install -g npm@7
- show_node_version
- update_local_npmrc_linux
- install_deps
- build_ts
- generate_help
Expand All @@ -144,7 +170,7 @@ jobs:
command: rm -rf node_modules/
- run:
name: Install only production dependencies
command: npm install
command: npx npm@6 install # kludge because npm@7 will invoke the lifecycle scripts (thus running prepare -> tsc) even if we use --ignore-scripts
environment:
NODE_ENV: production
- run:
Expand Down Expand Up @@ -172,19 +198,31 @@ jobs:
- install_gradle_windows
- install_maven_windows
- install_sbt_windows
- install_node_npm:
- show_node_version
- install_node_windows:
node_version: << parameters.node_version >>
- show_node_version
- checkout
- attach_workspace:
at: ~/snyk
- install_deps
- when:
condition: << parameters.use_npm7 >>
steps:
- run: npm install -g npm@7
- show_node_version
- run:
name: Update local .npmrc file (Windows)
command: echo "//registry.npmjs.org/:_authToken=$env:NPM_TOKEN" >> .npmrc
- run:
name: Install dependencies (Windows)
command: npm install --ignore-scripts # ignore-scripts required because of postinstall script in snyk-resolve-deps package
- build_ts
- run:
name: npm version
command: npm --version
- run:
name: Run auth
shell: bash.exe
command: npm run snyk-auth-windows
- run:
name: Run tests
Expand All @@ -204,6 +242,12 @@ jobs:
- checkout
- attach_workspace:
at: ~/snyk
- when:
condition: << parameters.use_npm7 >>
steps:
- run: sudo npm install -g npm@7
- show_node_version
- update_local_npmrc_linux
- install_deps
- build_ts
- run:
Expand All @@ -226,13 +270,71 @@ jobs:
- setup_remote_docker:
version: 19.03.13
# docker_layer_caching: true

- install_github_cli
- run:
name: Install npm@7
command: |
sudo npm install -g npm@7
- show_node_version
- run:
name: Setup Lerna
command: sudo npm install -g lerna
- update_local_npmrc_linux
- install_deps
- generate_help
- run: sudo npm i -g semantic-release @semantic-release/exec pkg
- run: sudo apt-get install -y osslsigncode
- run:
name: Publish to GitHub
command: semantic-release
name: Update package versions
command: ./release-scripts/update-versions.sh

- run:
name: Make git ignore changes relating to version updates and to .npmrc
command: |
git update-index --skip-worktree -- ./lerna.json
git update-index --skip-worktree -- ./package.json
git update-index --skip-worktree -- ./packages/snyk-protect/package.json
git update-index --skip-worktree -- ./.npmrc
- run:
name: Lerna Publish
command: |
lerna publish minor --yes --no-push --no-git-tag-version
- run:
name: Install osslsigncode
command: sudo apt-get install -y osslsigncode
- run:
name: Create Binaries
command: |
./release-scripts/make-binaries.sh
ls -la ./binary-releases
- store_artifacts:
path: ./binary-releases

- run:
name: Create a GitHub release
command: |
latest_version=$(cat lerna.json | jq .version -r)
new_tag="v${latest_version}"
gh release create ${new_tag} --title "${new_tag}" -n "Release notes not implemented yet" --prerelease
- run:
name: Add Assets to GitHub Release
command: |
gh_latest_release_tag=$(gh api repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/releases/latest | jq .tag_name -r)
echo "gh_latest_release_tag: ${gh_latest_release_tag}"
gh release upload $gh_latest_release_tag \
binary-releases/snyk-alpine \
binary-releases/snyk-linux \
binary-releases/snyk-macos \
binary-releases/snyk-win.exe \
binary-releases/docker-mac-signed-bundle.tar.gz \
binary-releases/snyk-alpine.sha256 \
binary-releases/snyk-linux.sha256 \
binary-releases/snyk-macos.sha256 \
binary-releases/snyk-win.exe.sha256 \
binary-releases/docker-mac-signed-bundle.tar.gz.sha256
workflows:
version: 2
Expand All @@ -241,15 +343,15 @@ workflows:
- regression-test:
name: Regression Test
context: nodejs-install
node_version: '8'
node_version: '12.16.2'
filters:
branches:
ignore:
- master
- test-windows:
name: Windows Tests for Node v12 support
context: nodejs-install
node_version: '12.0.0'
node_version: '12.16.2'
requires:
- Regression Test
filters:
Expand All @@ -259,7 +361,7 @@ workflows:
- test-windows:
name: Windows Tests for Node v14 support
context: nodejs-install
node_version: '14'
node_version: '14.15.4'
requires:
- Regression Test
filters:
Expand All @@ -269,7 +371,7 @@ workflows:
- test-windows:
name: Windows Tests for Node v10 support
context: nodejs-install
node_version: '10.21.0'
node_version: '10.23.1'
requires:
- Regression Test
filters:
Expand All @@ -280,6 +382,7 @@ workflows:
name: Windows Tests for Node v8 support
context: nodejs-install
node_version: '8.17.0'
use_npm7: false
requires:
- Regression Test
filters:
Expand All @@ -299,7 +402,7 @@ workflows:
- test-unix:
name: Unix Tests for Node v14 support
context: nodejs-install
node_version: '14'
node_version: '14.15.4'
requires:
- Regression Test
filters:
Expand All @@ -309,7 +412,7 @@ workflows:
- test-unix:
name: Unix Tests for Node v10 support
context: nodejs-install
node_version: '10'
node_version: '10.23.1'
requires:
- Regression Test
filters:
Expand All @@ -319,7 +422,8 @@ workflows:
- test-unix:
name: Unix Tests for Node v8 support
context: nodejs-install
node_version: '8'
node_version: '8.17.0'
use_npm7: false
requires:
- Regression Test
filters:
Expand All @@ -330,7 +434,7 @@ workflows:
- release:
name: Release
context: nodejs-app-release
node_version: '14'
node_version: '14.15.4'
filters:
branches:
only:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ key.pem
help/commands-md
help/commands-txt
help/commands-man
**/tsconfig.tsbuildinfo

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
package-lock=false
@snyk:registry=https://registry.npmjs.org
10 changes: 10 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"packages": [
".",
"packages/*"
],
"npmClient": "npm",
"useWorkspaces": true,
"version": "1.0.0-monorepo",
"independent": false
}
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "snyk",
"version": "1.0.0-monorepo",
"description": "snyk library and cli utility",
"main": "dist/lib/index.js",
"files": [
Expand All @@ -22,14 +23,18 @@
"engines": {
"node": ">=8"
},
"workspaces": [
".",
"packages/*"
],
"scripts": {
"build": "tsc",
"build": "tsc --build",
"build-watch": "tsc -w",
"find-circular": "npm run build && madge --circular ./dist",
"format": "prettier --write '{src,test,scripts}/**/*.{js,ts}'",
"prepare": "npm run build",
"generate-help": "./help/generator/generate-docs.sh",
"test:common": "npm run check-tests && npm run lint && node --require ts-node/register src/cli test --org=snyk",
"test:common": "npm run check-tests && npm run lint",
"test:acceptance": "tap test/acceptance/**/*.test.* test/acceptance/*.test.* -Rspec --timeout=300 --node-arg=-r --node-arg=ts-node/register",
"test:acceptance-windows": "tap test/acceptance/**/*.test.* -Rspec --timeout=300 --node-arg=-r --node-arg=ts-node/register",
"test:system": "tap test/system/*.test.* -Rspec --timeout=300 --node-arg=-r --node-arg=ts-node/register",
Expand All @@ -42,7 +47,7 @@
"lint:formatting": "prettier --check '{src,test,scripts}/**/*.{js,ts}'",
"check-tests": "! grep 'test\\.only' test/*.test.js -n",
"snyk-auth": "node --require ts-node/register src/cli auth $SNYK_API_KEY",
"snyk-auth-windows": "node --require ts-node/register src/cli auth %SNYK_API_KEY%"
"snyk-auth-windows": "bash ./scripts/auth-snyk-win.sh"
},
"keywords": [
"security",
Expand Down Expand Up @@ -93,7 +98,7 @@
"snyk-policy": "1.14.1",
"snyk-python-plugin": "1.19.2",
"snyk-resolve": "1.0.1",
"snyk-resolve-deps": "4.4.0",
"snyk-resolve-deps": "4.7.2",
"snyk-sbt-plugin": "2.11.0",
"snyk-tree": "^1.0.0",
"snyk-try-require": "1.3.1",
Expand Down Expand Up @@ -150,5 +155,9 @@
"help/**/*.txt",
"dist/STANDALONE"
]
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
}
}
3 changes: 3 additions & 0 deletions packages/snyk-protect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @snyk/snyk-protect

Experimental package for future use of Snyk protect functionality.
Loading

0 comments on commit 9c7b3df

Please sign in to comment.