Skip to content

Commit

Permalink
Merge pull request #167 from adobe/ci
Browse files Browse the repository at this point in the history
CI using github actions
  • Loading branch information
Himavanth authored Mar 6, 2020
2 parents 7da4e0f + 98ed6ba commit ede3330
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 1 deletion.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ USAGE
* [`@adobe/aio-cli-plugin-app app:add:action`](#adobeaio-cli-plugin-app-appaddaction)
* [`@adobe/aio-cli-plugin-app app:add:auth`](#adobeaio-cli-plugin-app-appaddauth)
* [`@adobe/aio-cli-plugin-app app:add:web-assets`](#adobeaio-cli-plugin-app-appaddweb-assets)
* [`@adobe/aio-cli-plugin-app app:add:ci`](#adobeaio-cli-plugin-app-appaddci)
* [`@adobe/aio-cli-plugin-app app:create [PATH]`](#adobeaio-cli-plugin-app-appcreate-path)
* [`@adobe/aio-cli-plugin-app app:delete`](#adobeaio-cli-plugin-app-appdelete)
* [`@adobe/aio-cli-plugin-app app:delete:action [ACTION-NAME]`](#adobeaio-cli-plugin-app-appdeleteaction-action-name)
* [`@adobe/aio-cli-plugin-app app:delete:web-assets`](#adobeaio-cli-plugin-app-appdeleteweb-assets)
* [`@adobe/aio-cli-plugin-app app:delete:ci`](#adobeaio-cli-plugin-app-appdeleteci)
* [`@adobe/aio-cli-plugin-app app:deploy`](#adobeaio-cli-plugin-app-appdeploy)
* [`@adobe/aio-cli-plugin-app app:init [PATH]`](#adobeaio-cli-plugin-app-appinit-path)
* [`@adobe/aio-cli-plugin-app app:logs`](#adobeaio-cli-plugin-app-applogs)
Expand Down Expand Up @@ -127,6 +129,21 @@ OPTIONS

_See code: [src/commands/app/add/web-assets.js](https://github.com/adobe/aio-cli-plugin-app/blob/1.2.3/src/commands/app/add/web-assets.js)_

## `@adobe/aio-cli-plugin-app app:add:ci`

Add CI files (github action workflows under .github folder). Note that you would need to manually create github secrets that are used in the workflow files.

```
USAGE
$ @adobe/aio-cli-plugin-app app:add:ci
OPTIONS
-v, --verbose Verbose output
--version Show version
```

_See code: [src/commands/app/add/ci.js](https://github.com/adobe/aio-cli-plugin-app/blob/1.2.3/src/commands/app/add/ci.js)_

## `@adobe/aio-cli-plugin-app app:create [PATH]`

Create a new Adobe I/O App with default parameters
Expand Down Expand Up @@ -196,6 +213,22 @@ OPTIONS

_See code: [src/commands/app/delete/web-assets.js](https://github.com/adobe/aio-cli-plugin-app/blob/1.2.3/src/commands/app/delete/web-assets.js)_

## `@adobe/aio-cli-plugin-app app:delete:ci`

Delete CI files

```
USAGE
$ @adobe/aio-cli-plugin-app app:delete:ci
OPTIONS
-v, --verbose Verbose output
-y, --yes Skip questions, and use all default values
--version Show version
```

_See code: [src/commands/app/delete/ci.js](https://github.com/adobe/aio-cli-plugin-app/blob/1.2.3/src/commands/app/delete/ci.js)_

## `@adobe/aio-cli-plugin-app app:deploy`

Build and deploy an Adobe I/O App
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@adobe/aio-app-scripts": "^0.11.0",
"@adobe/aio-lib-core-config": ">=1.2.8",
"@adobe/generator-aio-app": "^0.5.4",
"@adobe/generator-aio-app": "^0.5.5",
"@oclif/command": "^1.5.11",
"@oclif/config": "^1.12.9",
"chalk": "^3.0.0",
Expand Down
39 changes: 39 additions & 0 deletions src/commands/app/add/ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

const BaseCommand = require('../../../BaseCommand')
const yeoman = require('yeoman-environment')
const debug = require('debug')('aio-cli-plugin-app:init')

class AddCICommand extends BaseCommand {
async run () {
const { args, flags } = this.parse(AddCICommand)

debug(`adding component ${args.component} to the project, using flags: `, flags)

const generator = '@adobe/generator-aio-app/generators/add-ci'
const env = yeoman.createEnv()
env.register(require.resolve(generator), 'gen')
const res = await env.run('gen')
return res
}
}

AddCICommand.description = `Add CI files
`

AddCICommand.flags = {
...BaseCommand.flags
}

AddCICommand.args = []

module.exports = AddCICommand
49 changes: 49 additions & 0 deletions src/commands/app/delete/ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

const BaseCommand = require('../../../BaseCommand')
const yeoman = require('yeoman-environment')
const debug = require('debug')('aio-cli-plugin-app:init')
const { flags } = require('@oclif/command')

class DeleteCICommand extends BaseCommand {
async run () {
const { flags } = this.parse(DeleteCICommand)

debug('deleting CI files from the project, using flags: ', flags)

const generator = '@adobe/generator-aio-app/generators/delete-ci'

const env = yeoman.createEnv()
env.register(require.resolve(generator), 'gen')
const res = await env.run('gen', {
'skip-prompt': flags.yes
})

return res
}
}

DeleteCICommand.description = `Delete existing CI files
`

DeleteCICommand.flags = {
yes: flags.boolean({
description: 'Skip questions, and use all default values',
default: false,
char: 'y'
}),
...BaseCommand.flags
}

DeleteCICommand.args = []

module.exports = DeleteCICommand
66 changes: 66 additions & 0 deletions test/commands/app/add/ci.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const fs = require('fs-extra')

const TheCommand = require('../../../../src/commands/app/add/ci')
const BaseCommand = require('../../../../src/BaseCommand')

jest.mock('fs-extra')

jest.mock('yeoman-environment')
const yeoman = require('yeoman-environment')

const mockRegister = jest.fn()
const mockRun = jest.fn()
yeoman.createEnv.mockReturnValue({
register: mockRegister,
run: mockRun
})

beforeEach(() => {
mockRegister.mockReset()
mockRun.mockReset()
yeoman.createEnv.mockClear()
fs.ensureDirSync.mockClear()
})

describe('Command Prototype', () => {
test('exports', async () => {
expect(typeof TheCommand).toEqual('function')
expect(TheCommand.prototype instanceof BaseCommand).toBeTruthy()
expect(typeof TheCommand.flags).toBe('object')
})
})

describe('bad flags', () => {
test('unknown', async () => {
await expect(TheCommand.run(['--wtf'])).rejects.toThrow('Unexpected argument')
})
})

describe('template module cannot be registered', () => {
test('unknown error', async () => {
mockRegister.mockImplementation(() => { throw new Error('some error') })
await expect(TheCommand.run([])).rejects.toThrow('some error')
})
})

describe('no flags', () => {
test('should pass', async () => {
await TheCommand.run([])

expect(yeoman.createEnv).toHaveBeenCalled()
expect(mockRegister).toHaveBeenCalledTimes(1)
const genName = mockRegister.mock.calls[0][1]
expect(mockRun).toHaveBeenCalledWith(genName)
})
})
79 changes: 79 additions & 0 deletions test/commands/app/delete/ci.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright 2019 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const fs = require('fs-extra')

const TheCommand = require('../../../../src/commands/app/delete/ci')
const BaseCommand = require('../../../../src/BaseCommand')

jest.mock('fs-extra')

jest.mock('yeoman-environment')
const yeoman = require('yeoman-environment')

const mockRegister = jest.fn()
const mockRun = jest.fn()
yeoman.createEnv.mockReturnValue({
register: mockRegister,
run: mockRun
})

beforeEach(() => {
mockRegister.mockReset()
mockRun.mockReset()
yeoman.createEnv.mockClear()
fs.ensureDirSync.mockClear()
})

describe('Command Prototype', () => {
test('exports', async () => {
expect(typeof TheCommand).toEqual('function')
expect(TheCommand.prototype instanceof BaseCommand).toBeTruthy()
expect(typeof TheCommand.flags).toBe('object')
})
})

describe('bad flags', () => {
test('unknown', async () => {
await expect(TheCommand.run(['--wtf'])).rejects.toThrow('Unexpected argument')
})
})

describe('template module cannot be registered', () => {
test('unknown error', async () => {
mockRegister.mockImplementation(() => { throw new Error('some error') })
await expect(TheCommand.run([])).rejects.toThrow('some error')
})
})

describe('good flags', () => {
test('--yes', async () => {
await TheCommand.run(['--yes'])

expect(yeoman.createEnv).toHaveBeenCalled()
expect(mockRegister).toHaveBeenCalledTimes(1)
const genName = mockRegister.mock.calls[0][1]
expect(mockRun).toHaveBeenCalledWith(genName, {
'skip-prompt': true
})
})

test('no flags', async () => {
await TheCommand.run([])

expect(yeoman.createEnv).toHaveBeenCalled()
expect(mockRegister).toHaveBeenCalledTimes(1)
const genName = mockRegister.mock.calls[0][1]
expect(mockRun).toHaveBeenCalledWith(genName, {
'skip-prompt': false
})
})
})

0 comments on commit ede3330

Please sign in to comment.