Skip to content

Commit

Permalink
Merge pull request #2 from snyk-tech-services/feat/circle-setup
Browse files Browse the repository at this point in the history
Feat/circle setup
  • Loading branch information
lili2311 authored May 20, 2020
2 parents 147a90e + cb59fc8 commit 6ab7ed6
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 112 deletions.
164 changes: 68 additions & 96 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,101 +1,73 @@
version: 2.1
orbs:
snyk: snyk/[email protected]

snyk: snyk/[email protected]
jobs:
build-test-monitor:
docker:
# specify the version
- image: circleci/node:10.16.3

steps:
- checkout
- run:
name: "Install deps"
command: |
npm install
- run:
name: "Run Tests"
command: |
npm test
- snyk/scan:
fail-on-issues: true
monitor-on-build: true
token-variable: SNYK_TOKEN
- run: ./generate-binaries.sh
- persist_to_workspace:
root: .
paths:
- dist/*

build-test:
docker:
# specify the version
- image: circleci/node:10.16.3

steps:
- checkout
- run:
name: "Install deps"
command: |
npm install
- run:
name: "Run Tests"
command: |
npm test
- snyk/scan:
fail-on-issues: true
monitor-on-build: false
token-variable: SNYK_TOKEN

publish-github-release:
docker:
- image: gcr.io/snyk-technical-services/cicd-github
auth:
username: _json_key
password: $GCLOUD_GCR_SNYK_TS_READER
steps:
- checkout
- attach_workspace:
at: .
- run:
name: "Publish Release on GitHub"
command: |
VERSIONJUMP=$(git log --oneline -1 --pretty=%B | cat | grep -E 'minor|major|patch' | awk -F ':' '{print $1}')
VERSION=$(/workdir/nextver.sh "$VERSIONJUMP")
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${VERSION} dist/
build-test-monitor:
docker:
- image: circleci/node:latest
steps:
- checkout
- run: npm install semantic-release @semantic-release/exec pkg --save-dev
- run: npm install
- run: npm test
- snyk/scan:
fail-on-issues: true
monitor-on-build: true
token-variable: SNYK_TOKEN
- run: npx semantic-release
build-test:
docker:
- image: circleci/node:latest
steps:
- checkout
- run: npm install
- run: npm test
- snyk/scan:
fail-on-issues: true
monitor-on-build: false
token-variable: SNYK_TOKEN
- run: npx tsc
build-test-from-fork:
docker:
- image: circleci/node:latest
steps:
- checkout
- run: npm install
- run: npm test
- run: npx tsc
workflows:
version: 2.1
nightly:
triggers:
- schedule:
cron: "0 0 * * *"
filters:
branches:
only:
- master
jobs:
- build-test-monitor
build-test-monitor-publish:
jobs:
- build-test-monitor:
filters:
branches:
only:
- master
- publish-github-release:
requires:
- build-test-monitor
filters:
branches:
only:
- master
build-test:
jobs:
- build-test:
filters:
branches:
ignore:
- master
version: 2
nightly:
triggers:
- schedule:
cron: "0 0 * * *"
filters:
branches:
only:
- master
jobs:
- build-test-monitor:
context: SNYK

build-test-monitor:
jobs:
- build-test-monitor:
context: SNYK
filters:
branches:
only:
- master
build-test:
jobs:
- build-test:
context: SNYK
filters:
branches:
ignore:
- master
- /pull\/[0-9]+/
- build-test-from-fork:
filters:
branches:
only:
- /pull\/[0-9]+/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12
3 changes: 3 additions & 0 deletions .snyk
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ patch:
SNYK-JS-LODASH-450202:
- lodash:
patched: '2019-07-05T10:44:37.780Z'
SNYK-JS-LODASH-567746:
- lodash:
patched: '2020-05-20T15:08:23.395Z'
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
"lint:eslint": "eslint --cache '{lib,test}/**/*.ts'",
"test": "npm run lint && npm run build && npm run test:unit",
"test:unit": "jest",
"test:unit:debug": "DEBUG='snyk:api-import'",
"test:unit:debug": "DEBUG='snyk:api-import' jest",
"test:coverage": "npm run test:unit -- --coverage",
"test:watch": "tsc-watch --onSuccess 'npm run test:unit'",
"build": "tsc",
"build-watch": "tsc -w",
"prepare": "npm run build",
"prepare": "npm run snyk-protect && npm run build",
"snyk-test": "snyk test",
"pkg-binaries": "npx pkg . -t node12-linux-x64,node12-macos-x64,node12-win-x64 --out-path ./dist/binaries"
"pkg-binaries": "npx pkg . -t node12-linux-x64,node12-macos-x64,node12-win-x64 --out-path ./dist/binaries",
"snyk-protect": "snyk protect"
},
"types": "./dist/index.d.ts",
"repository": {
Expand All @@ -43,7 +44,8 @@
"sleep-promise": "8.0.1",
"snyk-config": "^3.0.0",
"source-map-support": "^0.5.16",
"tslib": "^1.10.0"
"tslib": "^1.10.0",
"snyk": "^1.211.0"
},
"devDependencies": {
"@types/debug": "4.1.5",
Expand All @@ -58,7 +60,6 @@
"jest": "^25.1.0",
"prettier": "^1.19.1",
"ts-jest": "^25.1.0",
"ts-node": "8.6.2",
"tsc-watch": "^4.1.0",
"typescript": "^3.7.5"
},
Expand All @@ -71,5 +72,6 @@
"branches": [
"master"
]
}
}
},
"snyk": true
}
9 changes: 8 additions & 1 deletion src/lib/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,19 @@ export async function importTarget(
},
},
);
if (res.statusCode && res.statusCode !== 201) {
debug('ERROR:', res.body);
throw new Error(
'Expected a 201 response, instead received: ' + JSON.stringify(res.body),
);
}
const locationUrl = res.headers['location'];
if (!locationUrl) {
throw new Error(
'No import location url returned. Please re-try the import.',
);
}
// TODO: log success?
// TODO: log success
debug(`Received locationUrl for ${target.name}: ${locationUrl}`);
return { pollingUrl: locationUrl };
} catch (error) {
Expand All @@ -59,6 +65,7 @@ export async function importTarget(
innerError?: string;
} = new Error('Could not complete API import');
err.innerError = error;
debug(`Could not complete API import: ${error}`);
throw err;
}
}
Expand Down
16 changes: 8 additions & 8 deletions test/lib/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { Status } from '../../src/lib/types';
// TODO: afterEach delete the new projects
test('Import & Poll a repo', async () => {
const { pollingUrl } = await importTarget(
'71a1561a-5a08-4d7e-80e4-699a12d73d4c',
'6f2644e2-ac86-4701-b0c3-0c8f07fa7fc3',
'f0125d9b-271a-4b50-ad23-80e12575a1bf',
'c4de291b-e083-4c43-a72c-113463e0d268',
{
name: 'shallow-goof-policy',
owner: 'snyk-fixtures',
Expand Down Expand Up @@ -42,26 +42,26 @@ test('Import & Poll a repo', async () => {
test('importTargets & pollImportUrls multiple repos', async () => {
const pollingUrls = await importTargets([
{
orgId: '71a1561a-5a08-4d7e-80e4-699a12d73d4c',
integrationId: '6f2644e2-ac86-4701-b0c3-0c8f07fa7fc3',
orgId: 'f0125d9b-271a-4b50-ad23-80e12575a1bf',
integrationId: 'c4de291b-e083-4c43-a72c-113463e0d268',
target: {
name: 'shallow-goof-policy',
owner: 'snyk-fixtures',
branch: 'master',
},
},
{
orgId: '71a1561a-5a08-4d7e-80e4-699a12d73d4c',
integrationId: '6f2644e2-ac86-4701-b0c3-0c8f07fa7fc3',
orgId: 'f0125d9b-271a-4b50-ad23-80e12575a1bf',
integrationId: 'c4de291b-e083-4c43-a72c-113463e0d268',
target: {
name: 'ruby-with-versions',
owner: 'snyk-fixtures',
branch: 'master',
},
},
{
orgId: '71a1561a-5a08-4d7e-80e4-699a12d73d4c',
integrationId: '6f2644e2-ac86-4701-b0c3-0c8f07fa7fc3',
orgId: 'f0125d9b-271a-4b50-ad23-80e12575a1bf',
integrationId: 'c4de291b-e083-4c43-a72c-113463e0d268',
target: {
name: 'composer-with-vulns',
owner: 'snyk-fixtures',
Expand Down

0 comments on commit 6ab7ed6

Please sign in to comment.