Skip to content

Commit

Permalink
Add support for GitHub Actions
Browse files Browse the repository at this point in the history
Closes #155.
  • Loading branch information
niksy committed Nov 6, 2020
1 parent b63b8ac commit 1a4a7f8
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
27 changes: 25 additions & 2 deletions generators/app/index.js
Expand Up @@ -140,6 +140,23 @@ module.exports = class extends Generator {
message: 'Do you have automated tests?',
default: true
},
{
type: 'list',
name: 'ciService',
message: 'What CI service do you want to test on?',
default: 'travis',
choices: [
{
name: 'Travis',
value: 'travis'
},
{
name: 'GitHub',
value: 'github'
}
],
when: (answers) => answers.automatedTests
},
{
type: 'list',
name: 'browserTestType',
Expand Down Expand Up @@ -378,7 +395,8 @@ module.exports = class extends Generator {
bundlingTool: answers.bundlingTool,
sourceMaps: answers.sourceMaps,
prettier: answers.prettier,
lowestIEVersion: lowestIEVersion
lowestIEVersion: lowestIEVersion,
ciService: answers.ciService
};

this.tpl = Object.assign({}, tpl, {
Expand Down Expand Up @@ -445,7 +463,11 @@ module.exports = class extends Generator {
}

if (answers.automatedTests) {
cp('travis.yml', '.travis.yml');
if (answers.ciService === 'travis') {
cp('travis.yml', '.travis.yml');
} else {
cp('github', '.github');
}
if (answers.browserModule) {
if (!answers.sassModule) {
cp(
Expand Down Expand Up @@ -475,6 +497,7 @@ module.exports = class extends Generator {
}
} else {
rm('.travis.yml');
rm('.github');
rm('test/index.js');
rm('test/automated');
rm('karma.conf.js');
Expand Down
4 changes: 2 additions & 2 deletions generators/app/templates/README.md
Expand Up @@ -129,8 +129,8 @@ MIT © [<%= humanName %>](<%= website %>)<% if ( automatedTests ) { %><% if ( pr
<!-- prettier-ignore-start --><% } %>
[ci]: https://travis-ci.com/<%= username %>/<%= cleanModuleName %>
[ci-img]: https://travis-ci.com/<%= username %>/<%= cleanModuleName %>.svg?branch=master<% } %><% if ( cloudBrowsers && ( (automatedTests && browserModule && !sassModule) || integrationTests ) ) { %>
[ci]: <% if ( ciService === 'travis' ) { %>https://travis-ci.com/<%= username %>/<%= cleanModuleName %><% } else { %>https://github.com/<%= username %>/<%= cleanModuleName %>/actions?query=workflow%3ACI<% } %>
[ci-img]: <% if ( ciService === 'travis' ) { %>https://travis-ci.com/<%= username %>/<%= cleanModuleName %>.svg?branch=master% } else { %>https://github.com/<%= username %>/<%= cleanModuleName %>/workflows/CI/badge.svg?branch=master<% } %><% } %><% if ( cloudBrowsers && ( (automatedTests && browserModule && !sassModule) || integrationTests ) ) { %>
[browserstack]: https://www.browserstack.com/
[browserstack-img]: https://www.browserstack.com/automate/badge.svg?badge_key=<badge_key><% } %><% if ( codeCoverageService ) { %>
[coverage]: https://coveralls.io/github/<%= username %>/<%= cleanModuleName %>?branch=master
Expand Down
21 changes: 21 additions & 0 deletions generators/app/templates/github/workflows/ci.yml
@@ -0,0 +1,21 @@
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [<%= nodeEngineVersion %>.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}<% if ( automatedTests && browserModule && !cloudBrowsers ) { %>
- run: export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start; sleep 3;<% } %>
- run: npm install
- run: npm test<% if ( codeCoverageService ) { %>
posttest:
needs: test
steps:
- run: npm run posttest:ci<% } %>
2 changes: 1 addition & 1 deletion generators/app/templates/karma.conf.js
Expand Up @@ -16,7 +16,7 @@ process.env.CHROME_BIN = puppeteer.executablePath();<% } %>
let config;

const isCI = typeof process.env.CI !== 'undefined' && process.env.CI !== 'false';
const isPR = typeof process.env.TRAVIS_PULL_REQUEST !== 'undefined' && process.env.TRAVIS_PULL_REQUEST !== 'false';
const isPR = <% if ( ciService === 'travis' ) { %>typeof process.env.TRAVIS_PULL_REQUEST !== 'undefined' && process.env.TRAVIS_PULL_REQUEST !== 'false'<% } else { %>typeof process.env.GITHUB_HEAD_REF !== 'undefined' && process.env.GITHUB_HEAD_REF !== ''<% } %>;
const local = !isCI || (isCI && isPR);

const port = 0;
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Expand Up @@ -201,6 +201,22 @@ describe('Automated tests', function () {
});
});

describe('Automated tests, different CI service', function () {
before(function () {
return helpers
.run(path.join(__dirname, '../generators/app'))
.withPrompts({
automatedTests: true,
ciService: 'github'
})
.toPromise();
});

it('should create necessary files', function () {
assert.file(['.github/workflows/ci.yml']);
});
});

describe('Automated tests, browser module', function () {
before(function () {
return helpers
Expand Down

0 comments on commit 1a4a7f8

Please sign in to comment.