Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ price and permissions are published as soon as their checks pass.
| `flb init [dir]` | Scaffolds from [fleetbase/starter-extension](https://github.com/fleetbase/starter-extension): package names under your organization, PHP namespace, engine route, and an `extension.json` with `compat` ranges |
| `flb build [--prebuilt --console <path>]` | Engine tarball (`npm pack`), api archive (Composer layout), optional prebuilt engine dist, and `.fleetbase/release.json` |
| `flb bump <version\|patch\|minor\|major\|prerelease>` | One version in extension.json, package.json and composer.json |
| `flb publish [--channel beta] [--submit]` | Creates the draft listing if needed, uploads the release, streams the check results |
| `flb publish [--channel beta] [--submit]` | Creates the draft listing if needed, uploads the release, streams the check results. In GitHub Actions it can use trusted publishing (`--oidc`, see below) |
| `flb release list\|status\|submit\|withdraw\|yank` | Release lifecycle, by `rel_` id or by version inside the extension |
| `flb listing list\|show\|update\|categories` | The catalog listing: subtitle, description, category, tags, URLs, icon (`--file listing.json` for several at once); shows what is still needed before a first release can be submitted |
| `flb search [query]` / `flb info <slug>` | The public catalog |
Expand Down Expand Up @@ -86,7 +86,50 @@ Service token: commands that need one ask you to `flb login` again.
- No command prints a token unless you pass `--show-token`.
- Tokens are never written anywhere but this file: no `.npmrc`, no `auth.json`, no
`.fleetbase/` files in your extension.
- In CI, set `FLB_TOKEN` instead of logging in; it is never written to disk.
- In CI, set `FLB_TOKEN` instead of logging in; it is never written to disk. From GitHub
Actions, `flb publish` can use trusted publishing instead (next section).

## Publishing from GitHub Actions

With trusted publishing a workflow publishes releases without any stored secret: `flb
publish` requests the job's GitHub OIDC token and exchanges it (`POST /v1/auth/oidc/github`)
for a short-lived `flbt_` token that can publish releases of that one extension, when the
token's claims match a trusted publisher configured on the listing.

1. Publish the first release from your machine (`flb login`, `flb publish`) or create the
listing in Studio: trusted publishing does not create listings or add packages to them.
2. In Studio → Access, add a trusted publisher to the listing: the repository (`owner/repo`),
the workflow file name (`release.yml`), optionally an environment (`release`), and the
refs it may publish from (`refs/tags/v*`).
3. Add the workflow, with `permissions: id-token: write`:

```yaml
on:
push:
tags: ['v*']
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v4
- uses: fleetbase/fleetbase-cli/action@v2
```

The action ([action/README.md](action/README.md), example in
[action/examples/publish-on-tag.yml](action/examples/publish-on-tag.yml)) installs the CLI,
runs `flb publish --json --submit` and exposes the release id, version and status as outputs.

Without the action, run `flb publish` in a job with `id-token: write`. It picks its token in
this order: `FLB_TOKEN`; a trusted publishing exchange when the job can request an OIDC token
(`ACTIONS_ID_TOKEN_REQUEST_URL` is set), or with `--oidc`; the stored login. `--no-oidc` skips
the exchange. The OIDC token's audience is the registry's host name (`registry.fleetbase.io`);
`FLB_OIDC_AUDIENCE` overrides it. Only `flb publish` does the exchange. Neither token is
printed or written to disk, and the exchanged token is renewed if it is about to expire while
the checks run.

## Building

Expand Down
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- `flb init` scaffolds from fleetbase/starter-extension with your organization's package names, PHP namespace and an `extension.json` with `compat` ranges.
- `flb build` writes the engine tarball, the Composer api archive and, with `--prebuilt --console <path>`, the prebuilt engine dist from ember-core's `build-engine-release`; `flb bump` keeps the three manifests on one version.
- `flb publish [--channel beta] [--submit]` creates the listing, uploads the release and streams the registry checks; `flb release status|submit|withdraw|yank|list` follow it through review.
- Trusted publishing from GitHub Actions: `flb publish` exchanges the job's OIDC token for a short-lived, publish-only token when a trusted publisher is configured on the listing. The composite action `fleetbase/fleetbase-cli/action@v2` installs the CLI, publishes and exposes the release id, version and status.
- `flb search`, `flb info`: the public catalog.
- `flb listing list|show|update|categories`: complete the catalog listing from the terminal.
- `flb instance code|register|status|updates`: instance registration from a server shell; `register --path|--docker` hands the code to the instance (`registry:register`) so its token never leaves it.
Expand Down
105 changes: 105 additions & 0 deletions action/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Publish a Fleetbase extension (GitHub Action)

`fleetbase/fleetbase-cli/action` builds an extension and publishes it to the Fleetbase
Extensions Registry with `flb publish`. With **trusted publishing** it needs no secret: the job
asks GitHub for an OIDC token, and the registry trades it for a short-lived token that can
publish releases of that one extension, provided the token's repository, workflow, ref and
environment match a trusted publisher configured on the listing.

```yaml
on:
push:
tags: ['v*']

permissions:
contents: read
id-token: write

jobs:
publish:
runs-on: ubuntu-latest
environment: release # optional, if the trusted publisher requires it
steps:
- uses: actions/checkout@v4
- uses: fleetbase/fleetbase-cli/action@v2
```

A complete workflow is in [examples/publish-on-tag.yml](examples/publish-on-tag.yml).

## Setting up trusted publishing

1. The listing must exist. Trusted publishing tokens can publish releases but cannot create
listings or change their packages, so publish the first release from your machine
(`flb login`, then `flb publish`), or create the listing in Studio.
2. In Studio → Access, add a trusted publisher to the listing:
- **Repository**: `owner/repo`
- **Workflow**: the workflow file name, e.g. `release.yml`
- **Environment** (optional): e.g. `release`. The job must then declare `environment: release`.
- **Allowed refs**: e.g. `refs/tags/v*`
3. Add the workflow with `permissions: id-token: write`.

The CLI looks up the listing by the extension's npm package name (the composer name when the
extension has no engine). The OIDC token is requested for the audience the registry expects
by default, its host name (`registry.fleetbase.io`); set `oidc-audience` only if the registry
was configured with another one.

Neither the OIDC token nor the exchanged token is printed or written to disk. The exchanged
token lasts about 15 minutes; `flb` exchanges again when it is about to expire during a long
check run.

## With a token instead

Pass a personal token with the `publish` scope (`flb token create --name ci --scopes publish`)
as `token`. It takes precedence over trusted publishing, and is the only way to publish a
listing's first release from CI. A job-level `FLB_TOKEN` environment variable does the same.

```yaml
- uses: fleetbase/fleetbase-cli/action@v2
with:
token: ${{ secrets.FLEETBASE_TOKEN }}
```

## Inputs

| Input | Default | Description |
| --- | --- | --- |
| `path` | `.` | Extension directory (with `extension.json`) |
| `registry` | `https://registry.fleetbase.io` | Registry Service URL |
| `channel` | extension.json, else `stable` | `stable` or `beta` |
| `submit` | `true` | Submit for review as soon as the checks pass |
| `wait` | `true` | Follow the checks until the release settles; `false` returns after the upload |
| `timeout` | `15m` | How long to follow the checks |
| `notes` | | Release notes |
| `notes-file` | | File with the release notes |
| `token` | | Personal token instead of trusted publishing |
| `oidc-audience` | registry host name | Audience of the GitHub OIDC token (`FLB_OIDC_AUDIENCE`) |
| `install-command` | | Run in `path` before publishing, e.g. `pnpm install --frozen-lockfile` |
| `args` | | Extra `flb publish` arguments, split on whitespace, e.g. `--ignore-scripts` |
| `cli-version` | `^2.0.0-0` | `@fleetbase/cli` version, range or dist-tag from npm; `source` builds the CLI from this action's checkout |
| `node-version` | `22` | Node.js for `actions/setup-node`; empty to use the runner's Node (20.10 or later) |

## Outputs

| Output | Description |
| --- | --- |
| `release-id` | The release id (`rel_…`) |
| `version` | The released version |
| `status` | The release status when the step finished: `published`, `submitted`, `in_review`, `uploaded`, `failed_checks`, … |
| `channel` | The release channel |
| `extension` | The listing slug |

The step also writes the release and its check results to the job summary. It fails when
the checks fail, when a requested submit was refused (the listing is not ready), or when
anything before the upload fails; the outputs are set whenever the upload happened.

## What the build needs

`flb publish` builds the release first (see `flb build`): the engine with `npm pack` and the
api archive from the files `composer.json` autoloads. Neither needs the extension's
dependencies installed, unless `package.json` has `prepare`/`prepack` scripts that do; then
set `install-command` (and set up pnpm or yarn first if you use them), or pass
`args: --ignore-scripts`. Composer and PHP are not needed. Prebuilt engine dists
(`--prebuilt --console <path>`) need a console checkout in the job and are not set up by the
action.

The action runs on Linux and macOS runners.
179 changes: 179 additions & 0 deletions action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
name: Publish a Fleetbase extension
description: Build and publish a Fleetbase extension to the Fleetbase Extensions Registry with `flb publish`, using trusted publishing (GitHub OIDC) or a token.
author: Fleetbase
branding:
icon: upload-cloud
color: blue

inputs:
path:
description: Extension directory (the one with extension.json), relative to the workspace.
required: false
default: '.'
registry:
description: Registry Service URL.
required: false
default: 'https://registry.fleetbase.io'
channel:
description: Release channel, stable or beta. Default is the channel in extension.json, else stable.
required: false
default: ''
submit:
description: Submit the release for review as soon as its checks pass.
required: false
default: 'true'
wait:
description: Follow the registry checks (and the submit) until the release settles. With false the step returns after the upload.
required: false
default: 'true'
timeout:
description: How long to follow the checks (90s, 15m, 1h).
required: false
default: '15m'
notes:
description: Release notes.
required: false
default: ''
notes-file:
description: File with the release notes, relative to the workspace.
required: false
default: ''
token:
description: 'A personal token (flbp_, publish scope) to use instead of trusted publishing. Leave empty to exchange the job''s GitHub OIDC token, which needs `permissions: id-token: write`.'
required: false
default: ''
oidc-audience:
description: Audience for the GitHub OIDC token. Default is the registry's host name, which is what the registry expects unless it was configured otherwise.
required: false
default: ''
install-command:
description: Command run in `path` before publishing, e.g. `pnpm install --frozen-lockfile`. Needed only when `npm pack` runs prepare/prepack scripts that need the extension's dependencies.
required: false
default: ''
args:
description: Extra arguments for `flb publish`, e.g. `--ignore-scripts` or `--rebuild`.
required: false
default: ''
cli-version:
description: Version (or range or dist-tag) of @fleetbase/cli to install from npm, or `source` to build the CLI from this action's own checkout.
required: false
default: '^2.0.0-0'
node-version:
description: Node.js version for actions/setup-node. Set to an empty string to use the Node already on the runner (20.10 or later).
required: false
default: '22'

outputs:
release-id:
description: The release id (rel_…).
value: ${{ steps.publish.outputs.release-id }}
version:
description: The released version.
value: ${{ steps.publish.outputs.version }}
status:
description: The release status when the step finished (uploaded, checking, failed_checks, submitted, in_review, published, …).
value: ${{ steps.publish.outputs.status }}
channel:
description: The release channel.
value: ${{ steps.publish.outputs.channel }}
extension:
description: The listing slug.
value: ${{ steps.publish.outputs.extension }}

runs:
using: composite
steps:
- name: Set up Node.js
if: inputs.node-version != ''
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}

- name: Install the Fleetbase CLI
id: cli
shell: bash
env:
CLI_VERSION: ${{ inputs.cli-version }}
ACTION_PATH: ${{ github.action_path }}
run: |
set -euo pipefail
if [ "$CLI_VERSION" = "source" ]; then
cli_root="$(cd "$ACTION_PATH/.." && pwd)"
(cd "$cli_root" && npm ci --no-audit --no-fund && npm run build)
bin="$cli_root/dist/bin/flb.js"
else
npm install --global --no-audit --no-fund "@fleetbase/cli@${CLI_VERSION:-latest}"
bin="$(npm root --global)/@fleetbase/cli/dist/bin/flb.js"
fi
echo "flb $(node "$bin" --version)"
echo "bin=$bin" >> "$GITHUB_OUTPUT"

- name: Install the extension's dependencies
if: inputs.install-command != ''
shell: bash
working-directory: ${{ inputs.path }}
env:
INSTALL_COMMAND: ${{ inputs.install-command }}
run: bash -euo pipefail -c "$INSTALL_COMMAND"

- name: Publish
id: publish
shell: bash
env:
FLB_BIN: ${{ steps.cli.outputs.bin }}
INPUT_PATH: ${{ inputs.path }}
INPUT_REGISTRY: ${{ inputs.registry }}
INPUT_CHANNEL: ${{ inputs.channel }}
INPUT_SUBMIT: ${{ inputs.submit }}
INPUT_WAIT: ${{ inputs.wait }}
INPUT_TIMEOUT: ${{ inputs.timeout }}
INPUT_NOTES: ${{ inputs.notes }}
INPUT_NOTES_FILE: ${{ inputs.notes-file }}
INPUT_ARGS: ${{ inputs.args }}
INPUT_TOKEN: ${{ inputs.token }}
INPUT_OIDC_AUDIENCE: ${{ inputs.oidc-audience }}
run: |
set -euo pipefail
# a token input overrides FLB_TOKEN; without one, FLB_TOKEN from the job (if any) is kept
if [ -n "$INPUT_TOKEN" ]; then
echo "::add-mask::$INPUT_TOKEN"
export FLB_TOKEN="$INPUT_TOKEN"
fi
if [ -n "$INPUT_OIDC_AUDIENCE" ]; then
export FLB_OIDC_AUDIENCE="$INPUT_OIDC_AUDIENCE"
fi
unset INPUT_TOKEN

args=(publish "$INPUT_PATH" --json --timeout "$INPUT_TIMEOUT")
[ -n "$INPUT_REGISTRY" ] && args+=(--registry "$INPUT_REGISTRY")
[ -n "$INPUT_CHANNEL" ] && args+=(--channel "$INPUT_CHANNEL")
[ "$INPUT_SUBMIT" = "true" ] && args+=(--submit)
[ "$INPUT_WAIT" = "false" ] && args+=(--no-wait)
[ -n "$INPUT_NOTES" ] && args+=(--notes "$INPUT_NOTES")
[ -n "$INPUT_NOTES_FILE" ] && args+=(--notes-file "$INPUT_NOTES_FILE")
if [ -n "$INPUT_ARGS" ]; then
read -r -a extra <<< "$INPUT_ARGS"
args+=("${extra[@]}")
fi

result="$RUNNER_TEMP/flb-publish-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT.json"
set +e
node "$FLB_BIN" "${args[@]}" > "$result"
code=$?
set -e

# the release JSON is on stdout whenever the upload happened, even when checks failed
node -e '
const fs = require("fs");
let release;
try { release = JSON.parse(fs.readFileSync(process.argv[1], "utf8")); } catch { process.exit(0); }
if (!release || !release.id) process.exit(0);
const outputs = { "release-id": release.id, version: release.version, status: release.status, channel: release.channel, extension: release.extension && release.extension.slug };
fs.appendFileSync(process.env.GITHUB_OUTPUT, Object.entries(outputs).map(([k, v]) => `${k}=${v ?? ""}\n`).join(""));
const checks = (release.checks || []).map((c) => `| ${c.skipped ? "–" : c.passed ? "✓" : "✗"} | ${c.check} | ${(c.summary || "").replace(/\|/g, "\\|")} |`);
const summary = [`### ${outputs.extension}@${release.version}: ${String(release.status).replace(/_/g, " ")}`, "", `Release \`${release.id}\` on the ${release.channel} channel.`];
if (checks.length) summary.push("", "| | Check | Summary |", "| --- | --- | --- |", ...checks);
if (process.env.GITHUB_STEP_SUMMARY) fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, summary.join("\n") + "\n");
' "$result"
rm -f "$result"
exit "$code"
43 changes: 43 additions & 0 deletions action/examples/publish-on-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Publishes the extension to the Fleetbase Extensions Registry when a version tag is pushed.
#
# Copy to .github/workflows/release.yml in the extension's repository. Trusted publishing needs
# no secret: in Studio → Access, add a trusted publisher for this repository with
# repository owner/repo
# workflow release.yml (this file's name)
# environment release (optional; remove `environment:` below if you do not use one)
# refs refs/tags/v*
# The listing must exist first (publish the first release with `flb publish` after `flb login`).
#
# Bump the version in extension.json, package.json and composer.json (`flb bump patch`), commit,
# then `git tag v1.2.3 && git push --tags`.

name: Publish to the Fleetbase Registry

on:
push:
tags: ['v*']

permissions:
contents: read
id-token: write # lets the job request the GitHub OIDC token flb exchanges

jobs:
publish:
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v4

# Only needed when package.json has prepare/prepack scripts that need dependencies;
# then also set `install-command` below (e.g. `pnpm install --frozen-lockfile`).
# - uses: pnpm/action-setup@v4

- name: Publish
id: publish
uses: fleetbase/fleetbase-cli/action@v2
with:
submit: true
notes: Release ${{ github.ref_name }}

- name: Result
run: echo "Release ${{ steps.publish.outputs.release-id }} (${{ steps.publish.outputs.version }}) is ${{ steps.publish.outputs.status }}"
Loading
Loading