@faable/faable 1.24.1 โ†’ 1.26.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.
@@ -3,6 +3,7 @@ import { Configuration } from '../../lib/Configuration.js';
3
3
  import { log } from '../../log.js';
4
4
  import { link } from '../link/index.js';
5
5
  import { git_context } from './git_context.js';
6
+ import { propose_release } from './release_version.js';
6
7
  import { deploy_remote } from './remote/index.js';
7
8
  import { resolve_app_id } from './resolve_app_id.js';
8
9
  import { secrets } from './secrets/index.js';
@@ -25,6 +26,10 @@ const deploy = {
25
26
  alias: 'w',
26
27
  type: 'string',
27
28
  description: 'Working directory'
29
+ })
30
+ .option('release', {
31
+ type: 'string',
32
+ description: 'Release version to record on the deployment (injected as FAABLE_RELEASE). Defaults to FAABLE_RELEASE env or the latest git tag'
28
33
  })
29
34
  .showHelpOnFail(false);
30
35
  },
@@ -47,6 +52,13 @@ const deploy = {
47
52
  // Capture the commit/ref/actor so the deployment records which commit
48
53
  // it came from and who pushed it (env in CI, git fallback locally).
49
54
  const git = await git_context({ workdir });
55
+ // Propose the release version (--release > FAABLE_RELEASE > git tag).
56
+ // Optional: when absent the platform injects no FAABLE_RELEASE and the
57
+ // app falls back to its own version source.
58
+ const proposed = await propose_release({ workdir, explicit: args.release });
59
+ if (proposed) {
60
+ log.info(`๐Ÿท๏ธ Release: ${proposed.release} (from ${proposed.source})`);
61
+ }
50
62
  // Remote build only (arch/deploy/remote-artifact-default-cutover.md): the
51
63
  // CLI no longer builds โ€” it uploads the source and the platform builds
52
64
  // server-side (framework detection, buildpacks, artifact/image output all
@@ -54,7 +66,13 @@ const deploy = {
54
66
  // (build_mode=local opt-out, or the global kill-switch off) or a build
55
67
  // error throws and exits red.
56
68
  log.info(`๐Ÿš€ Deploying "${app.name}" (${app.id})`);
57
- const deployment = await deploy_remote({ api, app, git, workdir });
69
+ const deployment = await deploy_remote({
70
+ api,
71
+ app,
72
+ git,
73
+ release: proposed?.release,
74
+ workdir
75
+ });
58
76
  const dashboard_url = `https://dashboard.faable.com/deploy/${app.team}/app/${app.id}`;
59
77
  log.info(`Preparing to deploy in faable cloud ยท ${deployment.id}`);
60
78
  log.info(`๐Ÿ“Š View it in the dashboard -> ${dashboard_url}`);
@@ -0,0 +1,53 @@
1
+ import { exec } from 'child_process';
2
+
3
+ // Quiet git runner, same contract as git_context's: trimmed stdout or
4
+ // undefined on any failure. A deploy must never fail because a release
5
+ // version couldn't be proposed.
6
+ const gitRunner = (workdir) => command => new Promise(resolve => {
7
+ exec(command, { cwd: workdir }, (err, stdout) => {
8
+ if (err)
9
+ return resolve(undefined);
10
+ const out = stdout?.toString().trim();
11
+ resolve(out || undefined);
12
+ });
13
+ });
14
+ // Loose version shape: "starts like semver". Filters out non-version tags
15
+ // (e.g. "nightly", "deploy-2026-07-01") when falling back to git describe;
16
+ // explicit values (--release / FAABLE_RELEASE) are NEVER validated โ€” the
17
+ // platform treats release as free text.
18
+ const looksLikeVersion = (v) => /^\d+\.\d+\.\d+/.test(v);
19
+ const stripV = (tag) => tag.replace(/^v/, "");
20
+ /**
21
+ * Propose the release version for a deploy (Sentry propose-version pattern):
22
+ * explicit `--release` > `FAABLE_RELEASE` env > latest reachable git tag
23
+ * (`v1.2.3` or `1.2.3`, e.g. the tag semantic-release created) > undefined.
24
+ * When undefined the field is omitted from the deployment and the platform
25
+ * injects no FAABLE_RELEASE โ€” the app falls back to its own version source.
26
+ * No SHA fallback: the commit already travels as `github_commit`.
27
+ */
28
+ const propose_release = async (opts) => {
29
+ const env = opts?.env ?? process.env;
30
+ const run = opts?.run ?? gitRunner(opts?.workdir);
31
+ if (opts?.explicit)
32
+ return { release: opts.explicit, source: "--release" };
33
+ if (env.FAABLE_RELEASE)
34
+ return { release: env.FAABLE_RELEASE, source: "FAABLE_RELEASE env" };
35
+ // Latest tag reachable from HEAD. Try version-shaped tags first so a
36
+ // repo that also tags non-releases still resolves; retry unfiltered for
37
+ // repos whose release tags carry no `v` prefix.
38
+ for (const cmd of [
39
+ `git describe --tags --abbrev=0 --match "v[0-9]*"`,
40
+ `git describe --tags --abbrev=0`,
41
+ ]) {
42
+ const tag = await run(cmd);
43
+ if (!tag)
44
+ continue;
45
+ const version = stripV(tag);
46
+ if (looksLikeVersion(version)) {
47
+ return { release: version, source: `git tag ${tag}` };
48
+ }
49
+ }
50
+ return undefined;
51
+ };
52
+
53
+ export { propose_release };
@@ -15,7 +15,7 @@ import { upload_missing_blobs } from './upload.js';
15
15
  * BUILD_ERROR โ€” throws so the command exits red.
16
16
  */
17
17
  const deploy_remote = async (props) => {
18
- const { api, app, git, workdir } = props;
18
+ const { api, app, git, release, workdir } = props;
19
19
  log.info(`โ˜๏ธ Remote build`);
20
20
  const manifest = await collect_manifest(workdir);
21
21
  log.info(`๐Ÿ—‚๏ธ ${manifest.length} files in the source manifest`);
@@ -25,6 +25,7 @@ const deploy_remote = async (props) => {
25
25
  const deployment = await api.createDeployment({
26
26
  app_id: app.id,
27
27
  source: { manifest },
28
+ ...(release ? { release } : {}),
28
29
  ...git,
29
30
  });
30
31
  log.info(`Preparing to build in faable cloud ยท ${deployment.id}`);
@@ -3,8 +3,8 @@ import prompts from 'prompts';
3
3
  import { log } from '../../log.js';
4
4
  import { Configuration } from '../../lib/Configuration.js';
5
5
  import { getGitRemoteUrl } from '../../lib/git_remote.js';
6
- import { workflowExists, DEPLOY_WORKFLOW_PATH, writeWorkflow, DEPLOY_DOCS_URL, DEPLOY_WORKFLOW_YAML } from './workflow_template.js';
7
6
 
7
+ const DEPLOY_DOCS_URL = "https://faable.com/docs/deploy/github-actions";
8
8
  const link = {
9
9
  command: "link",
10
10
  describe: "Link the local repository with a Faable app",
@@ -70,8 +70,9 @@ const link = {
70
70
  }
71
71
  // The API verifies that the user has a connected GitHub identity AND
72
72
  // access to the repository before persisting the link.
73
+ let linked;
73
74
  try {
74
- await api.linkRepository(selectedApp.id, { repository: gitUrl });
75
+ linked = await api.linkRepository(selectedApp.id, { repository: gitUrl });
75
76
  }
76
77
  catch (err) {
77
78
  const code = err?.code;
@@ -97,10 +98,17 @@ const link = {
97
98
  // Save locally for CLI convenience (only after the API confirms the link)
98
99
  Configuration.instance().saveConfig({ app_slug: selectedApp.name, app_id: selectedApp.id });
99
100
  log.info(`Successfully linked local repository to ${selectedApp.name}.`);
100
- // Onboarding: deploys happen via a GitHub Actions workflow on push. Offer
101
- // to scaffold it, and always explain the next steps so the user isn't left
102
- // wondering why nothing deploys.
103
- await setupDeployWorkflow(workdir);
101
+ // Deploy v4: push-to-deploy is server-side by default โ€” no workflow to
102
+ // scaffold. A repo that brings its own Faable workflow keeps deploying
103
+ // through it (the API leaves the trigger on the Action in that case).
104
+ const branch = linked?.github_branch || "main";
105
+ if (linked?.deploy_trigger === "webhook") {
106
+ log.info(`Push to deploy is on: every push to "${branch}" deploys automatically.`);
107
+ log.info(`Prefer deploying from your own CI? Docs: ${DEPLOY_DOCS_URL}`);
108
+ }
109
+ else {
110
+ log.info(`This repository has its own Faable deploy workflow โ€” pushes to "${branch}" keep deploying through it. Docs: ${DEPLOY_DOCS_URL}`);
111
+ }
104
112
  },
105
113
  };
106
114
  // Top-level `faable link` predates the per-product layout (`faable deploy link`).
@@ -115,32 +123,5 @@ const link_deprecated = {
115
123
  await link.handler(args);
116
124
  }
117
125
  };
118
- const setupDeployWorkflow = async (workdir) => {
119
- if (workflowExists(workdir)) {
120
- log.info(`Deploy workflow already present at ${DEPLOY_WORKFLOW_PATH}. Commit & push to "main" to deploy.`);
121
- return;
122
- }
123
- const { create } = await prompts({
124
- type: "toggle",
125
- name: "create",
126
- message: `Create the GitHub Actions deploy workflow (${DEPLOY_WORKFLOW_PATH})?`,
127
- initial: true,
128
- active: "yes",
129
- inactive: "no",
130
- });
131
- if (create) {
132
- const filePath = await writeWorkflow(workdir);
133
- log.info(`Created ${filePath}`);
134
- log.info("Next steps:");
135
- log.info(" 1. Commit the workflow file");
136
- log.info(' 2. Push to "main" โ€” that triggers your first deploy');
137
- log.info(`Docs: ${DEPLOY_DOCS_URL}`);
138
- }
139
- else {
140
- log.info(`Skipped. To enable automated deploys, add ${DEPLOY_WORKFLOW_PATH} with:`);
141
- log.info(`\n${DEPLOY_WORKFLOW_YAML}`);
142
- log.info(`Then commit & push to "main". Docs: ${DEPLOY_DOCS_URL}`);
143
- }
144
- };
145
126
 
146
127
  export { link, link_deprecated };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/faable",
3
- "version": "1.24.1",
3
+ "version": "1.26.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Marc Pomar <marc@faable.com>",
@@ -1,36 +0,0 @@
1
- import { mkdir, writeFile } from 'fs/promises';
2
- import { existsSync } from 'fs';
3
- import { join, dirname } from 'path';
4
-
5
- // The canonical GitHub Actions workflow that deploys a Faable app on push.
6
- // Mirrors the docs at https://faable.com/docs/deploy/github-actions.
7
- const DEPLOY_WORKFLOW_PATH = ".github/workflows/deploy.yaml";
8
- const DEPLOY_WORKFLOW_YAML = `name: Deploy to Faable
9
- on:
10
- push:
11
- branches:
12
- - main
13
- permissions:
14
- id-token: write
15
- contents: write
16
- pull-requests: write
17
- issues: write
18
- jobs:
19
- deploy:
20
- runs-on: ubuntu-latest
21
- timeout-minutes: 10
22
- steps:
23
- - uses: actions/checkout@v6
24
- - uses: actions/setup-node@v6
25
- - run: npx @faable/faable@latest deploy
26
- `;
27
- const DEPLOY_DOCS_URL = "https://faable.com/docs/deploy/github-actions";
28
- const workflowExists = (workdir) => existsSync(join(workdir, DEPLOY_WORKFLOW_PATH));
29
- const writeWorkflow = async (workdir) => {
30
- const filePath = join(workdir, DEPLOY_WORKFLOW_PATH);
31
- await mkdir(dirname(filePath), { recursive: true });
32
- await writeFile(filePath, DEPLOY_WORKFLOW_YAML, "utf8");
33
- return filePath;
34
- };
35
-
36
- export { DEPLOY_DOCS_URL, DEPLOY_WORKFLOW_PATH, DEPLOY_WORKFLOW_YAML, workflowExists, writeWorkflow };