Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
feat: modernize cli, add batch support
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Mar 6, 2019
1 parent dcfdc9d commit 3100b39
Show file tree
Hide file tree
Showing 19 changed files with 3,902 additions and 2,725 deletions.
21 changes: 13 additions & 8 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{
"presets": [
"stage-1",
["env", {
"targets": {
"node": "current"
[
"@babel/preset-env",
{
"targets": {
"node": "8"
}
}
}]
]
],
"plugins": [
["module-resolver", {
"root": ["./src"]
}]
[
"babel-plugin-module-resolver",
{
"root": ["./src"]
}
]
]
}
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/lib
node_modules
/lib/
node_modules/
57 changes: 0 additions & 57 deletions .eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"extends": ["smooth"]
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
/lib/
package.json
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"semi": false
}
15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: node_js

node_js:
- stable
dist: trusty
sudo: false
cache:
directories:
- node_modules
script:
- yarn test
- 8
- 10

cache: yarn

script: yarn ci
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2017 Olivier Tassinari & Greg Bergé
Copyright 2019 Olivier Tassinari & Greg Bergé

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
66 changes: 33 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,45 @@
"scripts": {
"dev:upload": "babel-node ./src/index upload __fixtures__",
"build": "NODE_ENV=production babel -d lib src",
"prepublish": "yarn build && pkgfiles",
"prettier": "find . -name \"*.js\" | grep -v -f .eslintignore | xargs prettier --write --no-semi --single-quote --trailing-comma all --print-width 100",
"prepublish": "yarn build",
"format": "prettier --write \"**/*.{js,md,json}\" ",
"lint": "eslint .",
"test": "yarn lint && yarn test:unit && yarn argos",
"test:unit": "jest --runInBand",
"test:watch": "yarn test:unit -- --watch",
"ci": "yarn lint && yarn test --ci && yarn argos",
"test": "jest --runInBand",
"argos": "yarn build && NODE_ENV=production ./bin/argos upload __fixtures__ --token $ARGOS_CLI_TOKEN || true"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-plugin-module-resolver": "^2.7.1",
"babel-preset-env": "^1.4.0",
"babel-preset-stage-1": "^6.24.1",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-find-rules": "^1.14.3",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-jsx-a11y": "^5.0.3",
"eslint-plugin-mocha": "^4.9.0",
"eslint-plugin-prettier": "^2.1.1",
"eslint-plugin-react": "^7.0.1",
"jest": "^20.0.4",
"pkgfiles": "^2.3.2",
"prettier": "^1.3.1",
"sinon": "^2.3.2"
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.4",
"@babel/node": "^7.2.2",
"@babel/preset-env": "^7.3.4",
"babel-eslint": "^10.0.1",
"babel-plugin-module-resolver": "^3.2.0",
"eslint": "^5.15.1",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-config-smooth": "^2.0.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-mocha": "^5.3.0",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-react-hooks": "^1.4.0",
"jest": "^24.1.0",
"prettier": "^1.16.4"
},
"dependencies": {
"chalk": "^1.1.3",
"commander": "^2.9.0",
"convict": "^3.0.0",
"form-data": "^2.1.4",
"glob": "^7.1.2",
"glob-promise": "^3.1.0",
"mz": "^2.6.0",
"node-fetch": "^1.7.0",
"raven": "^2.0.2",
"update-notifier": "^2.1.0"
"chalk": "^2.4.2",
"commander": "^2.19.0",
"convict": "^4.4.1",
"form-data": "^2.3.3",
"glob": "^7.1.3",
"glob-promise": "^3.4.0",
"mz": "^2.7.0",
"node-fetch": "^2.3.0",
"raven": "^2.6.4",
"update-notifier": "^2.5.0"
},
"jest": {
"roots": [
Expand Down
13 changes: 13 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,26 @@ const config = convict({
default: '',
env: 'ARGOS_TOKEN',
},
externalBuildId: {
doc: 'External build id (batch mode)',
format: String,
default: '',
env: 'ARGOS_EXTERNAL_BUILD_ID',
},
batchCount: {
doc: 'Batch count expected (batch mode)',
format: String,
default: '',
env: 'ARGOS_BATCH_COUNT',
},
})

const NODE_ENV = process.env.NODE_ENV || 'development'

if (NODE_ENV !== 'production') {
config.loadFile(path.join(__dirname, `../config/${NODE_ENV}.json`))
}

config.validate()

export default config
41 changes: 32 additions & 9 deletions src/getEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
function travis(env) {
let commit
let branch
const pullRequestNumber = env.TRAVIS_PULL_REQUEST !== 'false' ? env.TRAVIS_PULL_REQUEST : null
const pullRequestNumber =
env.TRAVIS_PULL_REQUEST !== 'false' ? env.TRAVIS_PULL_REQUEST : null

if (pullRequestNumber && env.TRAVIS_PULL_REQUEST_SHA) {
commit = env.TRAVIS_PULL_REQUEST_SHA
Expand Down Expand Up @@ -41,7 +42,7 @@ function circle(env) {
let pullRequestNumber = null

if (env.CI_PULL_REQUESTS && env.CI_PULL_REQUESTS !== '') {
pullRequestNumber = env.CI_PULL_REQUESTS.split('/').slice(-1)[0]
;[pullRequestNumber] = env.CI_PULL_REQUESTS.split('/').slice(-1)
}

return {
Expand Down Expand Up @@ -83,31 +84,53 @@ function semaphore(env) {
function buildkite(env) {
return {
ci: 'buildkite',
pullRequestNumber: env.BUILDKITE_PULL_REQUEST !== 'false' ? env.BUILDKITE_PULL_REQUEST : null,
pullRequestNumber:
env.BUILDKITE_PULL_REQUEST !== 'false'
? env.BUILDKITE_PULL_REQUEST
: null,
// Buildkite mixes SHAs and non-SHAs in BUILDKITE_COMMIT, so we return null if non-SHA.
commit: env.BUILDKITE_COMMIT !== 'HEAD' ? env.BUILDKITE_COMMIT : null,
branch: env.BUILDKITE_BRANCH,
}
}

function herokuCi(env) {
return {
ci: 'heroku',
commit: env.HEROKU_TEST_RUN_COMMIT_VERSION,
branch: env.HEROKU_TEST_RUN_BRANCH,
externalBuildId: `${env.HEROKU_TEST_RUN_ID}-${env.CI_NODE_INDEX}`,
batchCount: env.CI_NODE_TOTAL,
}
}

function getCi(env) {
if (env.TRAVIS_BUILD_ID) {
// https://docs.travis-ci.com/user/environment-variables/
return travis
} else if (env.JENKINS_URL && env.ghprbPullId) {
}
if (env.JENKINS_URL && env.ghprbPullId) {
// Pull Request Builder plugin.
return jenkins
} else if (env.CIRCLECI) {
}
if (env.CIRCLECI) {
return circle
} else if (env.CI_NAME && env.CI_NAME === 'codeship') {
}
if (env.CI_NAME && env.CI_NAME === 'codeship') {
return codeship
} else if (env.DRONE === 'true') {
}
if (env.DRONE === 'true') {
return drone
} else if (env.SEMAPHORE === 'true') {
}
if (env.SEMAPHORE === 'true') {
return semaphore
} else if (env.BUILDKITE === 'true') {
}
if (env.BUILDKITE === 'true') {
return buildkite
}
if (env.HEROKU_TEST_RUN_ID) {
return herokuCi
}

return () => ({
ci: null,
Expand Down
14 changes: 12 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ program
.option('-C, --commit <commit>', 'Git commit')
.option('-B, --branch <branch>', 'Git branch')
.option('-T, --token <token>', 'Repository token')
.option('--ignore <list>', 'List of glob files to ignore (ex: "**/*.png,**/diff.jpg")', list)
.option('--externalBuildId [string]', 'ID of the build (batch mode)')
.option(
'--batchCount [int]',
'Number of batches expected (batch mode)',
parseInt,
)
.option(
'--ignore <list>',
'List of glob files to ignore (ex: "**/*.png,**/diff.jpg")',
list,
)
.action(async (directory, command) => {
console.log(`=== argos-cli: uploading '${directory}' directory...\n`)

Expand Down Expand Up @@ -57,7 +67,7 @@ program
}

displaySuccess('Upload complete!')
console.log(chalk.green(`build created id: ${json.build.id}`))
console.log(chalk.green(`build id: ${json.build.id}`))
console.log(chalk.green(`build url: ${json.build.buildUrl}`))
})

Expand Down
14 changes: 11 additions & 3 deletions src/isDirectory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ import isDirectory from './isDirectory'

describe('isDirectory', () => {
it("should return true if it's a directory", async () => {
expect(await isDirectory(path.join(__dirname, '../__fixtures__/screenshots'))).toBe(true)
expect(
await isDirectory(path.join(__dirname, '../__fixtures__/screenshots/penelope.jpg')),
await isDirectory(path.join(__dirname, '../__fixtures__/screenshots')),
).toBe(true)
expect(
await isDirectory(
path.join(__dirname, '../__fixtures__/screenshots/penelope.jpg'),
),
).toBe(false)
expect(
await isDirectory(
path.join(__dirname, '../__fixtures__/not-a-directory'),
),
).toBe(false)
expect(await isDirectory(path.join(__dirname, '../__fixtures__/not-a-directory'))).toBe(false)
})
})
16 changes: 11 additions & 5 deletions src/isReadable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import isReadable from './isReadable'

describe('isReadable', () => {
it('should return true if it is readable', async () => {
expect(await isReadable(path.join(__dirname, '../__fixtures__/screenshots'))).toBe(true)
expect(await isReadable(path.join(__dirname, '../__fixtures__/screenshots/penelope.jpg'))).toBe(
true,
)
expect(await isReadable(path.join(__dirname, '../__fixtures__/not-a-directory'))).toBe(false)
expect(
await isReadable(path.join(__dirname, '../__fixtures__/screenshots')),
).toBe(true)
expect(
await isReadable(
path.join(__dirname, '../__fixtures__/screenshots/penelope.jpg'),
),
).toBe(true)
expect(
await isReadable(path.join(__dirname, '../__fixtures__/not-a-directory')),
).toBe(false)
})
})
Loading

0 comments on commit 3100b39

Please sign in to comment.