Browse Source

Merge branch 'install-action'

Michael Bromley 6 years ago
parent
commit
58e7f712ed

+ 3 - 2
.github/workflows/build_and_test.yml

@@ -23,11 +23,12 @@ jobs:
       uses: actions/setup-node@v1
       with:
         node-version: ${{ matrix.node-version }}
-    - name: install, build, and test
+    - name: Install & build
       run: |
         yarn install
         yarn bootstrap
         yarn lerna run build
-        yarn test:all
       env:
         CI: true
+    - name: Test
+      run: yarn test:all

+ 43 - 0
.github/workflows/publish_and_install.yml

@@ -0,0 +1,43 @@
+name: Publish & Install
+
+on:
+  push:
+    branches:
+    - master
+  pull_request:
+    branches:
+    - master
+jobs:
+  publish_install:
+
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v1
+    - name: Use Node.js 12.x
+      uses: actions/setup-node@v1
+      with:
+        node-version: 12.x
+    - name: Install & bootstrap
+      run: |
+        yarn install
+        yarn bootstrap
+      env:
+        CI: true
+    - name: Install Verdaccio
+      run: |
+        npm install -g verdaccio
+        mkdir -p $HOME/.config/verdaccio
+        cp -v ./.github/workflows/verdaccio/config.yaml $HOME/.config/verdaccio/config.yaml
+        verdaccio --config $HOME/.config/verdaccio/config.yaml &
+    - name: Publish to Verdaccio
+      run: |
+        npm set //registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}
+        npm set //localhost:4873/:_authToken=${{ secrets.VERDACCIO_AUTH_TOKEN }}
+        npm set registry=http://localhost:4873/
+        yarn lerna publish prepatch --preid ci --no-push --no-git-tag-version --no-commit-hooks --yes --dist-tag ci --registry http://localhost:4873/
+    - name: Install via @vendure/create
+      run: |
+        mkdir -p $HOME/install
+        cd $HOME/install
+        npm dist-tag ls @vendure/create
+        npx @vendure/create@ci test-app --ci

+ 68 - 0
.github/workflows/verdaccio/config.yaml

@@ -0,0 +1,68 @@
+#
+# This is the default config file. It allows all users to do anything,
+# so don't use it on production systems.
+#
+# Look here for more config file examples:
+# https://github.com/verdaccio/verdaccio/tree/master/conf
+#
+
+# path to a directory with all packages
+storage: ./storage
+# path to a directory with plugins to include
+plugins: ./plugins
+
+web:
+  # WebUI is enabled as default, if you want disable it, just uncomment this line
+  enable: false
+  title: Verdaccio
+
+auth:
+  htpasswd:
+    file: ./htpasswd
+    # Maximum amount of users allowed to register, defaults to "+inf".
+    # You can set this to -1 to disable registration.
+    #max_users: 1000
+
+# a list of other known repositories we can talk to
+uplinks:
+  npmjs:
+    url: https://registry.npmjs.org/
+
+packages:
+  '@*/*':
+    # scoped packages
+    access: $anonymous
+    publish: $anonymous
+    proxy: npmjs
+
+  '**':
+    # allow all users (including non-authenticated users) to read and
+    # publish all packages
+    #
+    # you can specify usernames/groupnames (depending on your auth plugin)
+    # and three keywords: "$all", "$anonymous", "$authenticated"
+    access: $anonymous
+
+    # allow all known users to publish packages
+    # (anyone can register by default, remember?)
+    publish: $anonymous
+
+    # if package is not available locally, proxy requests to 'npmjs' registry
+    proxy: npmjs
+
+# You can specify HTTP/1.1 server keep alive timeout in seconds for incomming connections.
+# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
+# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enought.
+server:
+  keepAliveTimeout: 60
+
+# To use `npm audit` uncomment the following section
+middlewares:
+  audit:
+    enabled: true
+
+# log settings
+logs:
+  - {type: stdout, format: pretty, level: debug}
+  #- {type: file, path: verdaccio.log, level: info}
+

+ 3 - 1
README.md

@@ -2,7 +2,9 @@
 
 A headless [GraphQL](https://graphql.org/) ecommerce framework built on [Node.js](https://nodejs.org) with [Nest](https://nestjs.com/) with [TypeScript](http://www.typescriptlang.org/).
 
-[![Build Status](https://github.com/vendure-ecommerce/vendure/workflows/Build%20&%20Test/badge.svg)](https://github.com/vendure-ecommerce/vendure/actions) [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lernajs.io/)
+[![Build Status](https://github.com/vendure-ecommerce/vendure/workflows/Build%20&%20Test/badge.svg)](https://github.com/vendure-ecommerce/vendure/actions) 
+[![Build Status](https://github.com/vendure-ecommerce/vendure/workflows/Publish%20&%20Install/badge.svg)](https://github.com/vendure-ecommerce/vendure/actions) 
+[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lernajs.io/)
 
 ### [www.vendure.io](https://www.vendure.io/)
 

+ 12 - 11
packages/create/src/create-vendure-app.ts

@@ -8,7 +8,7 @@ import os from 'os';
 import path from 'path';
 import { Observable } from 'rxjs';
 
-import { gatherUserResponses } from './gather-user-responses';
+import { gatherCiUserResponses, gatherUserResponses } from './gather-user-responses';
 import {
     checkDbConnection,
     checkNodeVersion,
@@ -47,11 +47,17 @@ program
         'silent',
     )
     .option('--use-npm', 'Uses npm rather than Yarn as the default package manager')
+    .option('--ci', 'Runs without prompts for use in CI scenarios')
     .parse(process.argv);
 
-createApp(projectName, program.useNpm, program.logLevel || 'silent');
+createApp(projectName, program.useNpm, program.logLevel || 'silent', program.ci);
 
-async function createApp(name: string | undefined, useNpm: boolean, logLevel: CliLogLevel) {
+async function createApp(
+    name: string | undefined,
+    useNpm: boolean,
+    logLevel: CliLogLevel,
+    isCi: boolean = false,
+) {
     if (!runPreChecks(name, useNpm)) {
         return;
     }
@@ -63,14 +69,9 @@ async function createApp(name: string | undefined, useNpm: boolean, logLevel: Cl
 
     const root = path.resolve(name);
     const appName = path.basename(root);
-    const {
-        dbType,
-        usingTs,
-        configSource,
-        indexSource,
-        indexWorkerSource,
-        populateProducts,
-    } = await gatherUserResponses(root);
+    const { dbType, usingTs, configSource, indexSource, indexWorkerSource, populateProducts } = isCi
+        ? await gatherCiUserResponses(root)
+        : await gatherUserResponses(root);
 
     const useYarn = useNpm ? false : shouldUseYarn();
     const originalDirectory = process.cwd();

+ 29 - 1
packages/create/src/gather-user-responses.ts

@@ -105,10 +105,38 @@ export async function gatherUserResponses(root: string): Promise<UserResponses>
     };
 }
 
+/**
+ * Returns mock "user response" without prompting, for use in CI
+ */
+export async function gatherCiUserResponses(root: string): Promise<UserResponses> {
+    const ciAnswers = {
+        dbType: 'sqlite' as const,
+        dbHost: '',
+        dbPort: '',
+        dbName: 'vendure',
+        dbUserName: '',
+        dbPassword: '',
+        language: 'ts',
+        populateProducts: true,
+    };
+    const { indexSource, indexWorkerSource, configSource } = await generateSources(root, ciAnswers);
+    return {
+        indexSource,
+        indexWorkerSource,
+        configSource,
+        usingTs: ciAnswers.language === 'ts',
+        dbType: ciAnswers.dbType,
+        populateProducts: ciAnswers.populateProducts,
+    };
+}
+
 /**
  * Create the server index, worker and config source code based on the options specified by the CLI prompts.
  */
-async function generateSources(root: string, answers: any): Promise<{ indexSource: string; indexWorkerSource: string; configSource: string; }> {
+async function generateSources(
+    root: string,
+    answers: any,
+): Promise<{ indexSource: string; indexWorkerSource: string; configSource: string }> {
     const assetPath = (fileName: string) => path.join(__dirname, '../assets', fileName);
 
     const templateContext = {

+ 8 - 1
scripts/publish-to-verdaccio.sh

@@ -1,7 +1,14 @@
 #!/bin/bash
 
 # A shell script which publishes all packages to a local Verdaccio registry for testing / local dev purposes
-VERDACCIO=http://localhost:4873/
+
+if [[ -z "${VERDACCIO_URL}" ]]; then
+  VERDACCIO=http://localhost:4873/
+else
+  VERDACCIO="${VERDACCIO_URL}"
+fi
+
+echo "Publishing to Verdaccio @ $VERDACCIO"
 
 cd ../packages/admin-ui-plugin && npm publish -reg $VERDACCIO &&\
 cd ../admin-ui && npm publish -reg $VERDACCIO &&\