具有CircleCI集成的Firebase函数
在基本Firebase Functions项目中,正在Functions文件夹中创建package.json文件。现在我们将在我们的项目中使用CircleCI。要使此CI正常工作,package.json必须位于您的repo的顶部文件夹中,而不是任何其他子文件夹中,如本文所示: 现在,如果我将文件移动到根目录并更正所有路径,我可以在项目上构建和使用lint,但部署失败,出现错误,firebase没有项目的目录路径。firebase tools中似乎有一个硬编码方法,阻止将package.json移到functions文件夹之外 如果我复制package.json并将其放回functions文件夹,一切正常,但这不是一个解决方案 这是我想要的结构:具有CircleCI集成的Firebase函数,firebase,npm,google-cloud-functions,circleci,Firebase,Npm,Google Cloud Functions,Circleci,在基本Firebase Functions项目中,正在Functions文件夹中创建package.json文件。现在我们将在我们的项目中使用CircleCI。要使此CI正常工作,package.json必须位于您的repo的顶部文件夹中,而不是任何其他子文件夹中,如本文所示: 现在,如果我将文件移动到根目录并更正所有路径,我可以在项目上构建和使用lint,但部署失败,出现错误,firebase没有项目的目录路径。firebase tools中似乎有一个硬编码方法,阻止将package.json
myproject
|
+- .firebaserc
+- firebase.json
+- package.json
+- tsconfig.json
+- tslint.json
|
+- functions/
|
+- src/
| |
| +- index.ts
|
+- lib/
|
+- index.js
+- index.js.map
package.json
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "functions/lib/index.js",
"dependencies": {
"firebase-admin": "~5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"tslint": "^5.8.0",
"typescript": "^2.5.3"
},
"private": true
}
{
"compilerOptions": {
"lib": ["es6"],
"module": "commonjs",
"noImplicitReturns": true,
"outDir": "./functions/lib",
"sourceMap": true,
"target": "es6"
},
"compileOnSave": true,
"include": [
"./functions/src"
]
}
tsconfig.json
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "functions/lib/index.js",
"dependencies": {
"firebase-admin": "~5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"tslint": "^5.8.0",
"typescript": "^2.5.3"
},
"private": true
}
{
"compilerOptions": {
"lib": ["es6"],
"module": "commonjs",
"noImplicitReturns": true,
"outDir": "./functions/lib",
"sourceMap": true,
"target": "es6"
},
"compileOnSave": true,
"include": [
"./functions/src"
]
}
是否有人已经尝试过CircleCI的Firebase功能,或者有任何线索可以让它工作?好的,我已经启动并运行了这个功能。您需要为CircleCI中的每个命令指定工作目录,使其精确为
~/project/functions
。现在CircleCI正在查找package.json文件
这是CircleCI的配置.yml:
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:6.14
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "./functions/package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
# Install all needed dependencies from package.json
- run:
working_directory: ~/project/functions
command: yarn install
# Save the cache including node_modules folder
- save_cache:
paths:
- ~/project/functions/node_modules
key: v1-dependencies-{{ checksum "./functions/package.json" }}
# Create the folder for your unit test results
- run:
working_directory: ~/project/functions
command: mkdir junit
# run tests with mocha!
- run:
working_directory: ~/project/functions
command: yarn test_ci
environment:
MOCHA_FILE: junit/test-results.xml
when: always
- store_test_results:
path: ~/project/functions/junit
- store_artifacts:
path: ~/project/functions/junit
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha --require ts-node/register ./src/test/*.spec.ts",
"test_ci": "mocha --require ts-node/register --reporter mocha-junit-reporter ./src/test/*.spec.ts"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/firestore": "^0.13.1",
"@google-cloud/storage": "^1.6.0",
"@google-cloud/vision": "^0.17.0",
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"@types/chai": "^4.1.3",
"@types/mocha": "^5.2.0",
"@types/sinon": "^4.3.1",
"chai": "^4.1.2",
"firebase-functions-test": "^0.1.1",
"firebase-tools": "^3.18.0",
"mocha": "^5.1.1",
"mocha-junit-reporter": "^1.17.0",
"sinon": "^4.5.0",
"ts-node": "^5.0.1",
"tslint": "^5.8.0",
"typescript": "^2.5.3"
},
"private": true
}
以及带有额外命令的test\u ci
的package.json,用于在CircleCI上进行单元测试:
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:6.14
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "./functions/package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
# Install all needed dependencies from package.json
- run:
working_directory: ~/project/functions
command: yarn install
# Save the cache including node_modules folder
- save_cache:
paths:
- ~/project/functions/node_modules
key: v1-dependencies-{{ checksum "./functions/package.json" }}
# Create the folder for your unit test results
- run:
working_directory: ~/project/functions
command: mkdir junit
# run tests with mocha!
- run:
working_directory: ~/project/functions
command: yarn test_ci
environment:
MOCHA_FILE: junit/test-results.xml
when: always
- store_test_results:
path: ~/project/functions/junit
- store_artifacts:
path: ~/project/functions/junit
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha --require ts-node/register ./src/test/*.spec.ts",
"test_ci": "mocha --require ts-node/register --reporter mocha-junit-reporter ./src/test/*.spec.ts"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/firestore": "^0.13.1",
"@google-cloud/storage": "^1.6.0",
"@google-cloud/vision": "^0.17.0",
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"@types/chai": "^4.1.3",
"@types/mocha": "^5.2.0",
"@types/sinon": "^4.3.1",
"chai": "^4.1.2",
"firebase-functions-test": "^0.1.1",
"firebase-tools": "^3.18.0",
"mocha": "^5.1.1",
"mocha-junit-reporter": "^1.17.0",
"sinon": "^4.5.0",
"ts-node": "^5.0.1",
"tslint": "^5.8.0",
"typescript": "^2.5.3"
},
"private": true
}
好吧,我把这玩意儿弄起来了。您需要为CircleCI中的每个命令指定工作目录,使其精确为
~/project/functions
。现在CircleCI正在查找package.json文件
这是CircleCI的配置.yml:
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:6.14
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "./functions/package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
# Install all needed dependencies from package.json
- run:
working_directory: ~/project/functions
command: yarn install
# Save the cache including node_modules folder
- save_cache:
paths:
- ~/project/functions/node_modules
key: v1-dependencies-{{ checksum "./functions/package.json" }}
# Create the folder for your unit test results
- run:
working_directory: ~/project/functions
command: mkdir junit
# run tests with mocha!
- run:
working_directory: ~/project/functions
command: yarn test_ci
environment:
MOCHA_FILE: junit/test-results.xml
when: always
- store_test_results:
path: ~/project/functions/junit
- store_artifacts:
path: ~/project/functions/junit
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha --require ts-node/register ./src/test/*.spec.ts",
"test_ci": "mocha --require ts-node/register --reporter mocha-junit-reporter ./src/test/*.spec.ts"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/firestore": "^0.13.1",
"@google-cloud/storage": "^1.6.0",
"@google-cloud/vision": "^0.17.0",
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"@types/chai": "^4.1.3",
"@types/mocha": "^5.2.0",
"@types/sinon": "^4.3.1",
"chai": "^4.1.2",
"firebase-functions-test": "^0.1.1",
"firebase-tools": "^3.18.0",
"mocha": "^5.1.1",
"mocha-junit-reporter": "^1.17.0",
"sinon": "^4.5.0",
"ts-node": "^5.0.1",
"tslint": "^5.8.0",
"typescript": "^2.5.3"
},
"private": true
}
以及带有额外命令的test\u ci
的package.json,用于在CircleCI上进行单元测试:
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:6.14
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "./functions/package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
# Install all needed dependencies from package.json
- run:
working_directory: ~/project/functions
command: yarn install
# Save the cache including node_modules folder
- save_cache:
paths:
- ~/project/functions/node_modules
key: v1-dependencies-{{ checksum "./functions/package.json" }}
# Create the folder for your unit test results
- run:
working_directory: ~/project/functions
command: mkdir junit
# run tests with mocha!
- run:
working_directory: ~/project/functions
command: yarn test_ci
environment:
MOCHA_FILE: junit/test-results.xml
when: always
- store_test_results:
path: ~/project/functions/junit
- store_artifacts:
path: ~/project/functions/junit
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha --require ts-node/register ./src/test/*.spec.ts",
"test_ci": "mocha --require ts-node/register --reporter mocha-junit-reporter ./src/test/*.spec.ts"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/firestore": "^0.13.1",
"@google-cloud/storage": "^1.6.0",
"@google-cloud/vision": "^0.17.0",
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"@types/chai": "^4.1.3",
"@types/mocha": "^5.2.0",
"@types/sinon": "^4.3.1",
"chai": "^4.1.2",
"firebase-functions-test": "^0.1.1",
"firebase-tools": "^3.18.0",
"mocha": "^5.1.1",
"mocha-junit-reporter": "^1.17.0",
"sinon": "^4.5.0",
"ts-node": "^5.0.1",
"tslint": "^5.8.0",
"typescript": "^2.5.3"
},
"private": true
}
在运行npm命令之前,您不能让CircleCI有效地
cd函数
?我认为您无法移动package.json,因为函数
实际上是您正在使用的节点应用程序的根,而package.json必须位于节点应用程序的根。感谢您的澄清,移动文件不是一个选项。你是对的@Doug,我会试试这个,如果它有效的话,我会把它作为一个答案发布。在运行npm命令之前,你不能让CircleCI有效地cd函数
?我认为您无法移动package.json,因为函数
实际上是您正在使用的节点应用程序的根,而package.json必须位于节点应用程序的根。感谢您的澄清,移动文件不是一个选项。你是对的@Doug,我会试试这个,如果它有效的话,我会把它作为一个答案发布。