@appright/funnelshift 0.15.0 → 0.16.0

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/cli/index.js CHANGED
@@ -8,11 +8,11 @@ import { join } from 'node:path';
8
8
  const argv = process.argv;
9
9
  const arg = (n) => argArg(argv, n);
10
10
  const opt = (n) => optArg(argv, n);
11
- const git = (c) => { try {
11
+ const git = (c, none = 'unknown') => { try {
12
12
  return execSync(`git ${c}`, { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
13
13
  }
14
14
  catch {
15
- return 'unknown';
15
+ return none;
16
16
  } };
17
17
  const commit = process.env.GITHUB_SHA || git('rev-parse HEAD');
18
18
  const branch = process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || git('rev-parse --abbrev-ref HEAD');
@@ -24,13 +24,15 @@ async function main() {
24
24
  return;
25
25
  }
26
26
  if (cmd !== 'build' && cmd !== 'upload')
27
- throw new Error('usage: funnel-kit init --project <slug> [--dir <path>] [--force] | build|upload --funnel <slug> [--api <url>] [--project <slug>]');
27
+ throw new Error('usage: funnel-kit init --project <slug> [--dir <path>] [--force] | build --funnel <slug> | upload --funnel <slug> [--api <url>] [--project <slug>] [--message <text>]');
28
28
  const funnel = arg('funnel');
29
29
  if (cmd === 'build') {
30
30
  console.log(await buildFunnel(process.cwd(), funnel, { commit, branch }));
31
31
  }
32
32
  else {
33
- const lines = await runUpload({ dir: join(process.cwd(), 'dist', funnel), funnel, commit, branch, env: process.env, api: opt('api'), project: opt('project') });
33
+ // the build's name in the service: --message, else the subject of the commit (none outside git)
34
+ const message = opt('message') ?? git('log -1 --format=%s', '');
35
+ const lines = await runUpload({ dir: join(process.cwd(), 'dist', funnel), funnel, commit, branch, message, env: process.env, api: opt('api'), project: opt('project') });
34
36
  for (const l of lines)
35
37
  console.log(l);
36
38
  }
@@ -1,3 +1,4 @@
1
+ export declare function commitSubject(msg: string | undefined): string;
1
2
  export declare function uploadBuild(o: {
2
3
  dir: string;
3
4
  api: string;
@@ -5,6 +6,7 @@ export declare function uploadBuild(o: {
5
6
  funnel: string;
6
7
  commit: string;
7
8
  branch: string;
9
+ message?: string;
8
10
  token: string;
9
11
  fetchImpl?: typeof fetch;
10
12
  }): Promise<{
@@ -22,6 +24,7 @@ export declare function runUpload(o: {
22
24
  funnel: string;
23
25
  commit: string;
24
26
  branch: string;
27
+ message?: string;
25
28
  env: Record<string, string | undefined>;
26
29
  api?: string;
27
30
  project?: string;
@@ -17,6 +17,12 @@ function files(root, rel = '') {
17
17
  throw new Error(`not a regular file in build dir: ${r}`);
18
18
  });
19
19
  }
20
+ // commitSubject is the commit message the build is named by in the service («#14 · Новый текст пейвола»): its first line, or '' for
21
+ // none. The merge commit GitHub makes for a pull request («Merge <sha> into <sha>») says nothing about the build and is left out.
22
+ export function commitSubject(msg) {
23
+ const s = (msg ?? '').split(/\r?\n/)[0].trim();
24
+ return /^Merge [0-9a-f]{40} into [0-9a-f]{40}$/.test(s) ? '' : s;
25
+ }
20
26
  export async function uploadBuild(o) {
21
27
  const list = files(o.dir);
22
28
  for (const need of ['index.html', 'manifest.json']) {
@@ -33,6 +39,10 @@ export async function uploadBuild(o) {
33
39
  const form = new FormData();
34
40
  for (const k of ['project', 'funnel', 'commit', 'branch'])
35
41
  form.set(k, o[k]);
42
+ // the commit subject names the build (kit 0.16.0); a server before it ignores the field
43
+ const message = commitSubject(o.message);
44
+ if (message)
45
+ form.set('message', message);
36
46
  form.set('artifact', new Blob([art], { type: 'application/gzip' }), 'build.tgz');
37
47
  const r = await (o.fetchImpl ?? fetch)(`${o.api.replace(/\/+$/, '')}/api/builds`, { method: 'POST', body: form, headers: { Authorization: `Bearer ${o.token}` } });
38
48
  const text = await r.text();
@@ -85,6 +95,6 @@ export async function runUpload(o) {
85
95
  throw new Error('the service address is not set: use FUNNELS_API_URL or --api <url>');
86
96
  const fetchImpl = o.fetchImpl ?? fetch;
87
97
  const project = o.project || o.env.FUNNELS_PROJECT || await projectOfToken(api, token, fetchImpl);
88
- const res = await uploadBuild({ dir: o.dir, api, project, funnel: o.funnel, commit: o.commit, branch: o.branch, token, fetchImpl });
98
+ const res = await uploadBuild({ dir: o.dir, api, project, funnel: o.funnel, commit: o.commit, branch: o.branch, message: o.message, token, fetchImpl });
89
99
  return uploadLines(res);
90
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appright/funnelshift",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",