@faable/faable 1.5.15 → 1.5.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api/context.js
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
|
-
import { CredentialsStore } from '../lib/CredentialsStore.js';
|
|
2
1
|
import { FaableApi } from './FaableApi.js';
|
|
3
2
|
import { apikey_strategy } from './strategies/apikey.strategy.js';
|
|
3
|
+
import { getIDToken } from '@actions/core';
|
|
4
|
+
import { oidc_strategy } from './strategies/oidc.strategy.js';
|
|
4
5
|
|
|
6
|
+
// import { CredentialsStore } from "../lib/CredentialsStore";
|
|
5
7
|
const context = async () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
let api;
|
|
9
|
+
if (process.env.FAABLE_APIKEY) {
|
|
10
|
+
const apikey = process.env.FAABLE_APIKEY;
|
|
11
|
+
api = FaableApi.create({ authStrategy: apikey_strategy, auth: { apikey } });
|
|
12
|
+
}
|
|
13
|
+
//const store = new CredentialsStore();
|
|
14
|
+
//(await store.loadCredentials())?.apikey
|
|
15
|
+
// Github actions environment
|
|
16
|
+
if (process.env.GITHUB_ACTIONS === 'true') {
|
|
17
|
+
try {
|
|
18
|
+
const idToken = await getIDToken("https://faable.com");
|
|
19
|
+
api = FaableApi.create({ authStrategy: oidc_strategy, auth: { idToken } });
|
|
20
|
+
}
|
|
21
|
+
catch (_) {
|
|
22
|
+
console.error("Error fetching token, configure 'permissions: id-token: write'");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
8
25
|
return {
|
|
9
|
-
api
|
|
26
|
+
api,
|
|
10
27
|
};
|
|
11
28
|
};
|
|
12
29
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const oidc_strategy = (config) => {
|
|
2
|
+
const { idToken } = config;
|
|
3
|
+
if (!idToken) {
|
|
4
|
+
throw new Error("Missing idToken.");
|
|
5
|
+
}
|
|
6
|
+
return {
|
|
7
|
+
headers: async () => {
|
|
8
|
+
return {
|
|
9
|
+
Authorization: `Bearer ${idToken}`,
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { oidc_strategy };
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { writeGithubAction } from './writeGithubAction.js';
|
|
2
2
|
|
|
3
3
|
const init = {
|
|
4
4
|
command: ["initialize", "$0"],
|
|
5
5
|
describe: "Initialize Faable",
|
|
6
6
|
builder: (yargs) => {
|
|
7
7
|
return yargs
|
|
8
|
-
.option("
|
|
9
|
-
alias: "
|
|
8
|
+
.option("overwrite", {
|
|
9
|
+
alias: "o",
|
|
10
10
|
type: "boolean",
|
|
11
|
-
description: "
|
|
11
|
+
description: "Overwrite generated file",
|
|
12
12
|
default: false,
|
|
13
13
|
})
|
|
14
14
|
.showHelpOnFail(false);
|
|
15
15
|
},
|
|
16
16
|
handler: async (args) => {
|
|
17
|
-
const {
|
|
18
|
-
|
|
19
|
-
await helper.initializeGithubAction(force);
|
|
17
|
+
const { overwrite } = args;
|
|
18
|
+
await writeGithubAction({ overwrite });
|
|
20
19
|
},
|
|
21
20
|
};
|
|
22
21
|
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import path__default from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { log } from '../../log.js';
|
|
4
|
+
import prompts from 'prompts';
|
|
5
|
+
import { CredentialsStore } from '../../lib/CredentialsStore.js';
|
|
6
|
+
import yaml from 'yaml';
|
|
7
|
+
|
|
8
|
+
const store = new CredentialsStore();
|
|
9
|
+
const get_workflows_dir = () => {
|
|
10
|
+
return path__default.join(process.cwd(), ".github", "workflows");
|
|
11
|
+
};
|
|
12
|
+
const get_default_action = () => {
|
|
13
|
+
return path__default.join(get_workflows_dir(), "deploy.yml");
|
|
14
|
+
};
|
|
15
|
+
const demandConfig = async (force = false) => {
|
|
16
|
+
const creds = await store.loadCredentials();
|
|
17
|
+
if (creds?.apikey) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const { apikey } = await prompts([
|
|
21
|
+
{
|
|
22
|
+
type: "text",
|
|
23
|
+
name: "apikey",
|
|
24
|
+
message: "What is your Faable ApiKey?",
|
|
25
|
+
},
|
|
26
|
+
]);
|
|
27
|
+
await store.saveApiKey({ apikey });
|
|
28
|
+
};
|
|
29
|
+
const tentativeName = async () => {
|
|
30
|
+
try {
|
|
31
|
+
const pkg = path__default.join(process.cwd(), "package.json");
|
|
32
|
+
const { name } = await fs.readJSON(pkg);
|
|
33
|
+
return name;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const checkPackageManager = async () => {
|
|
40
|
+
if (fs.existsSync(path__default.join(process.cwd(), "package-lock.json"))) {
|
|
41
|
+
return "npm";
|
|
42
|
+
}
|
|
43
|
+
if (fs.existsSync(path__default.join(process.cwd(), "yarn.lock"))) {
|
|
44
|
+
return "yarn";
|
|
45
|
+
}
|
|
46
|
+
throw new Error("No package-lock.json or yarn.lock file found");
|
|
47
|
+
};
|
|
48
|
+
const writeGithubAction = async (params = {}) => {
|
|
49
|
+
const { overwrite } = params;
|
|
50
|
+
await demandConfig();
|
|
51
|
+
const gh_action_file = get_default_action();
|
|
52
|
+
// Already configured
|
|
53
|
+
if (!overwrite && fs.pathExistsSync(gh_action_file)) {
|
|
54
|
+
log.info(`Github action is already configured.`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const onCancel = (prompt) => {
|
|
58
|
+
log.info("Cancel");
|
|
59
|
+
process.exit(0);
|
|
60
|
+
};
|
|
61
|
+
const { app_name } = await prompts([
|
|
62
|
+
{
|
|
63
|
+
type: "text",
|
|
64
|
+
name: "app_name",
|
|
65
|
+
initial: await tentativeName(),
|
|
66
|
+
message: "Which app are you deploying",
|
|
67
|
+
},
|
|
68
|
+
], { onCancel });
|
|
69
|
+
const manager = await checkPackageManager();
|
|
70
|
+
const action = {
|
|
71
|
+
name: "Deploy to Faable",
|
|
72
|
+
on: {
|
|
73
|
+
push: {
|
|
74
|
+
branches: ["main"],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
permissions: {
|
|
78
|
+
"id-token": "write",
|
|
79
|
+
"contents": "read"
|
|
80
|
+
},
|
|
81
|
+
jobs: {
|
|
82
|
+
deploy: {
|
|
83
|
+
"runs-on": "ubuntu-latest",
|
|
84
|
+
steps: [
|
|
85
|
+
{ uses: "actions/checkout@v2" },
|
|
86
|
+
{
|
|
87
|
+
uses: "actions/setup-node@v4",
|
|
88
|
+
with: {
|
|
89
|
+
"node-version": "lts/*",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
...(manager == "npm" ? [{ run: "npm ci" }] : []),
|
|
93
|
+
...(manager == "yarn"
|
|
94
|
+
? [{ run: "yarn install --frozen-lockfile" }]
|
|
95
|
+
: []),
|
|
96
|
+
{
|
|
97
|
+
name: "Deploy to Faable",
|
|
98
|
+
run: `npx @faable/faable deploy ${app_name}`,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
await fs.writeFile(gh_action_file, yaml.stringify(action));
|
|
105
|
+
log.info(`Written ${gh_action_file}`);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { writeGithubAction };
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"name": "@faable/faable",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
4
|
"dependencies": {
|
|
5
|
+
"@actions/core": "^3.0.0",
|
|
5
6
|
"axios": "^1.13.2",
|
|
6
7
|
"fs-extra": "^11.3.2",
|
|
7
8
|
"handlebars": "^4.7.8",
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
"yaml": "^2.8.2",
|
|
15
16
|
"yargs": "^18.0.0"
|
|
16
17
|
},
|
|
17
|
-
"version": "1.5.
|
|
18
|
+
"version": "1.5.16",
|
|
18
19
|
"bin": {
|
|
19
20
|
"faable": "bin/faable.js"
|
|
20
21
|
},
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import path__default from 'path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import { log } from '../../log.js';
|
|
4
|
-
import prompts from 'prompts';
|
|
5
|
-
import { CredentialsStore } from '../../lib/CredentialsStore.js';
|
|
6
|
-
import yaml from 'yaml';
|
|
7
|
-
|
|
8
|
-
class ConfigurationHelper {
|
|
9
|
-
store;
|
|
10
|
-
constructor() {
|
|
11
|
-
this.store = new CredentialsStore();
|
|
12
|
-
}
|
|
13
|
-
get workflows_dir() {
|
|
14
|
-
return path__default.join(process.cwd(), ".github", "workflows");
|
|
15
|
-
}
|
|
16
|
-
get default_action() {
|
|
17
|
-
return path__default.join(this.workflows_dir, "deploy.yml");
|
|
18
|
-
}
|
|
19
|
-
async demandConfig(force = false) {
|
|
20
|
-
const creds = await this.store.loadCredentials();
|
|
21
|
-
if (creds?.apikey) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const { apikey } = await prompts([
|
|
25
|
-
{
|
|
26
|
-
type: "text",
|
|
27
|
-
name: "apikey",
|
|
28
|
-
message: "What is your Faable ApiKey?",
|
|
29
|
-
},
|
|
30
|
-
]);
|
|
31
|
-
await this.store.saveApiKey({ apikey });
|
|
32
|
-
}
|
|
33
|
-
async tentativeName() {
|
|
34
|
-
try {
|
|
35
|
-
const pkg = path__default.join(process.cwd(), "package.json");
|
|
36
|
-
const { name } = await fs.readJSON(pkg);
|
|
37
|
-
return name;
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async checkPackageManager() {
|
|
44
|
-
if (fs.existsSync(path__default.join(process.cwd(), "package-lock.json"))) {
|
|
45
|
-
return "npm";
|
|
46
|
-
}
|
|
47
|
-
if (fs.existsSync(path__default.join(process.cwd(), "yarn.lock"))) {
|
|
48
|
-
return "yarn";
|
|
49
|
-
}
|
|
50
|
-
throw new Error("No package-lock.json or yarn.lock file found");
|
|
51
|
-
}
|
|
52
|
-
async initializeGithubAction(force = false) {
|
|
53
|
-
await this.demandConfig();
|
|
54
|
-
// Already configured
|
|
55
|
-
if (!force && fs.pathExistsSync(this.default_action)) {
|
|
56
|
-
log.info(`Github action is already configured.`);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const onCancel = (prompt) => {
|
|
60
|
-
log.info("Cancel");
|
|
61
|
-
process.exit(0);
|
|
62
|
-
};
|
|
63
|
-
const { app_name } = await prompts([
|
|
64
|
-
{
|
|
65
|
-
type: "text",
|
|
66
|
-
name: "app_name",
|
|
67
|
-
initial: await this.tentativeName(),
|
|
68
|
-
message: "Which app are you deploying",
|
|
69
|
-
},
|
|
70
|
-
], { onCancel });
|
|
71
|
-
const manager = await this.checkPackageManager();
|
|
72
|
-
const action = {
|
|
73
|
-
name: "Deploy to Faable",
|
|
74
|
-
on: {
|
|
75
|
-
push: {
|
|
76
|
-
branches: ["main"],
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
env: {
|
|
80
|
-
FAABLE_APIKEY: "${{ secrets.FAABLE_APIKEY }}",
|
|
81
|
-
},
|
|
82
|
-
jobs: {
|
|
83
|
-
deploy: {
|
|
84
|
-
"runs-on": "ubuntu-latest",
|
|
85
|
-
steps: [
|
|
86
|
-
{ uses: "actions/checkout@v2" },
|
|
87
|
-
{ name: "Prepare CLI", run: "npm i -g @faable/faable" },
|
|
88
|
-
{
|
|
89
|
-
uses: "actions/setup-node@v3",
|
|
90
|
-
with: {
|
|
91
|
-
"node-version": "18",
|
|
92
|
-
cache: manager,
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
...(manager == "npm" ? [{ run: "npm ci" }] : []),
|
|
96
|
-
...(manager == "yarn"
|
|
97
|
-
? [{ run: "yarn install --frozen-lockfile" }]
|
|
98
|
-
: []),
|
|
99
|
-
{
|
|
100
|
-
name: "Deploy to Faable",
|
|
101
|
-
run: `faable deploy ${app_name}`,
|
|
102
|
-
},
|
|
103
|
-
],
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
await fs.writeFile(this.default_action, yaml.stringify(action));
|
|
108
|
-
log.info(`Written ${this.default_action}`);
|
|
109
|
-
log.info(`Remember to create FAABLE_APIKEY on Github repo secrets`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export { ConfigurationHelper };
|