-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from adobe/ci
CI using github actions
- Loading branch information
Showing
6 changed files
with
267 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) | ||
}) |