diff --git a/README.md b/README.md index 012d3b24d..ee675d3a6 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,8 @@ yarn create nuxt-app - [jsconfig.json](https://code.visualstudio.com/docs/languages/jsconfig) - [Semantic PR](https://probot.github.io/apps/semantic-pull-requests/) - [Dependabot (for GitHub only)](https://dependabot.com/) +1. Continous Integration + - [GitHub Actions](https://github.com/features/actions) ## CLI Options diff --git a/packages/cna-template/template/dependabot.yml b/packages/cna-template/template/dependabot.yml index 3f18b0f44..a6ecab247 100644 --- a/packages/cna-template/template/dependabot.yml +++ b/packages/cna-template/template/dependabot.yml @@ -1,18 +1,34 @@ version: 2 updates: +# Fetch and update latest `npm` packages - package-ecosystem: npm - directory: "/" + directory: '/' schedule: interval: daily time: '00:00' - open-pull-requests-limit: 99 + open-pull-requests-limit: 10 reviewers: - <%= gitUsername %> assignees: - <%= gitUsername %> - labels: - - dependencies commit-message: prefix: fix prefix-development: chore include: scope +<%_ if (ci === 'github-actions') { _%> +# Fetch and update latest `github-actions` pkgs +- package-ecosystem: github-actions + directory: '/' + schedule: + interval: daily + time: '00:00' + open-pull-requests-limit: 10 + reviewers: + - <%= gitUsername %> + assignees: + - <%= gitUsername %> + commit-message: + prefix: fix + prefix-development: chore + include: scope +<%_ } _%> diff --git a/packages/cna-template/template/frameworks/github-actions/.github/workflows/ci.yml b/packages/cna-template/template/frameworks/github-actions/.github/workflows/ci.yml new file mode 100644 index 000000000..3bb90169d --- /dev/null +++ b/packages/cna-template/template/frameworks/github-actions/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: ci + +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + +jobs: + ci: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + node: [14] + + steps: + - name: Checkout ๐Ÿ›Ž + uses: actions/checkout@master + + - name: Setup node env ๐Ÿ— + uses: actions/setup-node@v2.1.2 + with: + node-version: ${{ matrix.node }} + + <%_ if (pm === 'yarn') { _%> + - name: Get yarn cache directory path ๐Ÿ›  + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Cache node_modules ๐Ÿ“ฆ + uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + <%_ } _%> + <%_ if (pm === 'npm') { _%> + - name: Cache node_modules ๐Ÿ“ฆ + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + <%_ } _%> + + - name: Install dependencies ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป + run: <%= pmRun === 'yarn' ? 'yarn' : 'npm ci' %> + + <%_ if (linter.length > 0) { _%> + - name: Run linter ๐Ÿ‘€ + run: <%= pmRun %> lint + <%_ } _%> + + <%_ if (test !== 'none') { _%> + - name: Run tests ๐Ÿงช + run: <%= pmRun %> test + <%_ } _%> diff --git a/packages/create-nuxt-app/lib/prompts.js b/packages/create-nuxt-app/lib/prompts.js index dee3c5111..4dccde57e 100644 --- a/packages/create-nuxt-app/lib/prompts.js +++ b/packages/create-nuxt-app/lib/prompts.js @@ -116,7 +116,18 @@ module.exports = [ default: [] }, { - when: answers => answers.devTools.includes('dependabot'), + when: ({ test, linter }) => test !== 'none' || linter.length > 0, + name: 'ci', + message: 'Continuous integration:', + type: 'list', + choices: [ + { name: 'None', value: 'none' }, + { name: 'GitHub Actions (GitHub only)', value: 'github-actions' } + ], + default: 'none' + }, + { + when: ({ devTools, ci }) => devTools.includes('dependabot') || ci !== 'none', name: 'gitUsername', message: 'What is your GitHub username?', default: '{gitUser.name}', diff --git a/packages/create-nuxt-app/lib/saofile.js b/packages/create-nuxt-app/lib/saofile.js index 17c18d705..af2f176db 100644 --- a/packages/create-nuxt-app/lib/saofile.js +++ b/packages/create-nuxt-app/lib/saofile.js @@ -76,6 +76,14 @@ module.exports = { }) } + if (this.answers.ci && this.answers.ci !== 'none') { + actions.push({ + type: 'add', + files: '**', + templateDir: join(frameworksDir, this.answers.ci) + }) + } + actions.push({ type: 'add', files: '*', diff --git a/packages/create-nuxt-app/test/snapshots/index.test.js.md b/packages/create-nuxt-app/test/snapshots/index.test.js.md index b3de7159b..f7c7e64be 100644 --- a/packages/create-nuxt-app/test/snapshots/index.test.js.md +++ b/packages/create-nuxt-app/test/snapshots/index.test.js.md @@ -4,6 +4,170 @@ The actual snapshot is saved in `index.test.js.snap`. Generated by [AVA](https://avajs.dev). +## verify ci: GitHub Actions (GitHub only) + +> Generated files + + [ + '.editorconfig', + '.gitignore', + 'README.md', + 'assets/README.md', + 'components/Logo.vue', + 'components/README.md', + 'layouts/README.md', + 'layouts/default.vue', + 'middleware/README.md', + 'nuxt.config.js', + 'package.json', + 'pages/README.md', + 'pages/index.vue', + 'plugins/README.md', + 'static/README.md', + 'static/favicon.ico', + 'store/README.md', + ] + +> package.json + + { + dependencies: { + 'core-js': '^3.6.5', + nuxt: '^2.14.6', + }, + devDependencies: {}, + private: true, + scripts: { + build: 'nuxt build', + dev: 'nuxt', + generate: 'nuxt generate', + start: 'nuxt start', + }, + } + +> Generated nuxt.config.js + + `export default {โŠ + // Global page headers (https://go.nuxtjs.dev/config-head)โŠ + head: {โŠ + title: 'output',โŠ + meta: [โŠ + { charset: 'utf-8' },โŠ + { name: 'viewport', content: 'width=device-width, initial-scale=1' },โŠ + { hid: 'description', name: 'description', content: '' }โŠ + ],โŠ + link: [โŠ + { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }โŠ + ]โŠ + },โŠ + โŠ + // Global CSS (https://go.nuxtjs.dev/config-css)โŠ + css: [โŠ + ],โŠ + โŠ + // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)โŠ + plugins: [โŠ + ],โŠ + โŠ + // Auto import components (https://go.nuxtjs.dev/config-components)โŠ + components: true,โŠ + โŠ + // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)โŠ + buildModules: [โŠ + ],โŠ + โŠ + // Modules (https://go.nuxtjs.dev/config-modules)โŠ + modules: [โŠ + ],โŠ + โŠ + // Build Configuration (https://go.nuxtjs.dev/config-build)โŠ + build: {โŠ + }โŠ + }โŠ + ` + +## verify ci: None + +> Generated files + + [ + '.editorconfig', + '.gitignore', + 'README.md', + 'assets/README.md', + 'components/Logo.vue', + 'components/README.md', + 'layouts/README.md', + 'layouts/default.vue', + 'middleware/README.md', + 'nuxt.config.js', + 'package.json', + 'pages/README.md', + 'pages/index.vue', + 'plugins/README.md', + 'static/README.md', + 'static/favicon.ico', + 'store/README.md', + ] + +> package.json + + { + dependencies: { + 'core-js': '^3.6.5', + nuxt: '^2.14.6', + }, + devDependencies: {}, + private: true, + scripts: { + build: 'nuxt build', + dev: 'nuxt', + generate: 'nuxt generate', + start: 'nuxt start', + }, + } + +> Generated nuxt.config.js + + `export default {โŠ + // Global page headers (https://go.nuxtjs.dev/config-head)โŠ + head: {โŠ + title: 'output',โŠ + meta: [โŠ + { charset: 'utf-8' },โŠ + { name: 'viewport', content: 'width=device-width, initial-scale=1' },โŠ + { hid: 'description', name: 'description', content: '' }โŠ + ],โŠ + link: [โŠ + { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }โŠ + ]โŠ + },โŠ + โŠ + // Global CSS (https://go.nuxtjs.dev/config-css)โŠ + css: [โŠ + ],โŠ + โŠ + // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)โŠ + plugins: [โŠ + ],โŠ + โŠ + // Auto import components (https://go.nuxtjs.dev/config-components)โŠ + components: true,โŠ + โŠ + // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)โŠ + buildModules: [โŠ + ],โŠ + โŠ + // Modules (https://go.nuxtjs.dev/config-modules)โŠ + modules: [โŠ + ],โŠ + โŠ + // Build Configuration (https://go.nuxtjs.dev/config-build)โŠ + build: {โŠ + }โŠ + }โŠ + ` + ## verify default answers > Generated files diff --git a/packages/create-nuxt-app/test/snapshots/index.test.js.snap b/packages/create-nuxt-app/test/snapshots/index.test.js.snap index 7ccb6219d..306e9ee56 100644 Binary files a/packages/create-nuxt-app/test/snapshots/index.test.js.snap and b/packages/create-nuxt-app/test/snapshots/index.test.js.snap differ