mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
update status of cf deploy request
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -45,3 +45,5 @@ yarn.lock
|
||||
package.json
|
||||
package-lock.json
|
||||
node_modules/
|
||||
|
||||
cloud_functions/functions/src/functionConfig.json
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
import * as fs from "fs";
|
||||
// Initialize Firebase Admin
|
||||
import * as admin from "firebase-admin";
|
||||
// Initialize Firebase Admin
|
||||
|
||||
const serviceAccount = requireIfExists(`./firebase-credentials.json`);
|
||||
|
||||
function requireIfExists(module) {
|
||||
try {
|
||||
return require(module);
|
||||
} catch (error) {
|
||||
console.log("serviceAccount json not found");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (serviceAccount) {
|
||||
console.log(`Running on ${serviceAccount.project_id}`);
|
||||
admin.initializeApp({
|
||||
credential: admin.credential.cert(serviceAccount),
|
||||
databaseURL: `https://${serviceAccount.project_id}.firebaseio.com`,
|
||||
});
|
||||
const db = admin.firestore();
|
||||
|
||||
const docConfig2json = async (docPath: string, jsonPath: string) => {
|
||||
const doc = await db.doc(docPath).get();
|
||||
const data = doc.data();
|
||||
const jsonData = JSON.stringify(data ? data.config : "[]");
|
||||
fs.writeFileSync(jsonPath, jsonData);
|
||||
};
|
||||
|
||||
// Initialize Cloud Firestore Database
|
||||
|
||||
const main = async () => {
|
||||
await docConfig2json(
|
||||
"_FIRETABLE_/_SETTINGS_/_CONFIG_/_HISTORY_",
|
||||
"./src/history/config.json"
|
||||
);
|
||||
await docConfig2json(
|
||||
"_FIRETABLE_/_SETTINGS_/_CONFIG_/_ALGOLIA_",
|
||||
"./src/algolia/config.json"
|
||||
);
|
||||
await docConfig2json(
|
||||
"_FIRETABLE_/_SETTINGS_/_CONFIG_/_COLLECTION_SYNC_",
|
||||
"./src/collectionSync/config.json"
|
||||
);
|
||||
await docConfig2json(
|
||||
"_FIRETABLE_/_SETTINGS_/_CONFIG_/_SNAPSHOT_SYNC_",
|
||||
"./src/snapshotSync/config.json"
|
||||
);
|
||||
return true;
|
||||
};
|
||||
|
||||
main()
|
||||
.catch(err => console.log(err))
|
||||
.then(() => console.log("this will succeed"))
|
||||
.catch(() => "obligatory catch");
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "functions",
|
||||
"scripts": {
|
||||
"fetchConfig": "ts-node fetchConfig.ts",
|
||||
"updateStatus": "ts-node updateDeployStatus.ts",
|
||||
"generateConfig": "ts-node src/generateConfig.ts",
|
||||
"lint": "tslint --project tsconfig.json",
|
||||
"build": "tsc",
|
||||
@@ -14,7 +14,7 @@
|
||||
"engines": {
|
||||
"node": "10"
|
||||
},
|
||||
"main": "lib/src/index.js",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"@google-cloud/cloudbuild": "^1.5.0",
|
||||
"@google-cloud/firestore": "^3.7.5",
|
||||
|
||||
@@ -16,7 +16,8 @@ export const triggerCloudBuild = functions.https.onCall(
|
||||
context: functions.https.CallableContext
|
||||
) => {
|
||||
const {
|
||||
row, //ref, action
|
||||
row,
|
||||
ref, // action
|
||||
} = data;
|
||||
|
||||
if (!context.auth) {
|
||||
@@ -34,6 +35,7 @@ export const triggerCloudBuild = functions.https.onCall(
|
||||
_PROJECT_ID: projectId,
|
||||
_FUNCTIONS_GROUP: groupName,
|
||||
_FUNCTION_CONFIG: functionConfig,
|
||||
_REQUEST_DOC_PATH: ref.path,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -11,5 +11,5 @@
|
||||
"target": "es2017"
|
||||
},
|
||||
"compileOnSave": true,
|
||||
"include": ["src", "fetchConfig.ts", "generateConfig.ts"]
|
||||
"include": ["src", "generateConfig.ts"]
|
||||
}
|
||||
|
||||
31
cloud_functions/functions/updateDeployStatus.ts
Normal file
31
cloud_functions/functions/updateDeployStatus.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
// Initialize Firebase Admin
|
||||
import * as admin from "firebase-admin";
|
||||
// Initialize Firebase Admin
|
||||
const serverTimestamp = admin.firestore.FieldValue.serverTimestamp;
|
||||
const serviceAccount = requireIfExists(`./firebase-credentials.json`);
|
||||
|
||||
function requireIfExists(module) {
|
||||
try {
|
||||
return require(module);
|
||||
} catch (error) {
|
||||
console.log("serviceAccount json not found");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (serviceAccount) {
|
||||
console.log(`Running on ${serviceAccount.project_id}`);
|
||||
admin.initializeApp({
|
||||
credential: admin.credential.cert(serviceAccount),
|
||||
databaseURL: `https://${serviceAccount.project_id}.firebaseio.com`,
|
||||
});
|
||||
const db = admin.firestore();
|
||||
|
||||
const main = async deployRequestPath => {
|
||||
await db.doc(deployRequestPath).update({ deployedAt: serverTimestamp() });
|
||||
};
|
||||
|
||||
main(process.argv[2])
|
||||
.catch(err => console.log(err))
|
||||
.then(() => console.log("this will succeed"))
|
||||
.catch(() => "obligatory catch");
|
||||
}
|
||||
@@ -29,6 +29,12 @@ steps:
|
||||
- "--only"
|
||||
- "functions:${_FUNCTIONS_GROUP}"
|
||||
dir: "cloud_functions/functions"
|
||||
- name: node:10.15.1
|
||||
entrypoint: yarn
|
||||
args:
|
||||
- "updateStatus"
|
||||
- "${_REQUEST_DOC_PATH}"
|
||||
dir: "cloud_functions/functions"
|
||||
|
||||
substitutions:
|
||||
_PROJECT_ID: "project-id" # default value
|
||||
|
||||
Reference in New Issue
Block a user