-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (55 loc) · 1.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const core = require("@actions/core");
const github = require("@actions/github");
const generateHowtoAsync = require("@yazilimvip/howto-script/build/service/HowtoServiceAsync")
.default;
// Firebase App (the core Firebase SDK) is always required and
// must be listed before other Firebase SDKs
const firebase = require("firebase/app");
// Add the Firebase services that you want to use
require("firebase/database");
require("firebase/auth");
try {
const genericErrorHandler = (error) => {
console.log("errorCode", error.code);
console.log("errorMessage", error.message);
};
const API_KEY = core.getInput("api-key");
const DATABASE_URL = core.getInput("database-url");
const PROJECT_ID = core.getInput("project-id");
const USERNAME = core.getInput("username");
const PASSWORD = core.getInput("password");
const HOWTO_DIR = core.getInput("howto-dir");
const firebaseConfig = {
apiKey: API_KEY,
databaseURL: DATABASE_URL,
projectId: PROJECT_ID,
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase
.auth()
.signInWithEmailAndPassword(USERNAME, PASSWORD)
.catch(genericErrorHandler)
.then(() => {
generateHowtoAsync(HOWTO_DIR).then((result) => {
firebase
.database()
.ref("howto")
.set(JSON.stringify(result))
.catch(genericErrorHandler)
.then(() => {
console.log("Operation Completed!");
firebase
.auth()
.signOut()
.catch(genericErrorHandler)
.then(() => {
console.log("Sign Out Success!");
process.exit(0);
});
});
});
});
} catch (error) {
core.setFailed(error.message);
}