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
5 changes: 0 additions & 5 deletions .changeset/cli-multi-org.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/tidy-dependency-scanning.md

This file was deleted.

103 changes: 55 additions & 48 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,72 @@
name: Release packages

on:
push:
branches:
- main
workflow_dispatch:
inputs:
version:
description: Stable CLI version on maintenance/cli-v1
required: true
type: string
dry_run:
description: Build and check without publishing
default: true
type: boolean

concurrency: ${{ github.workflow }}-${{ github.ref }}
# Serialize with the release workflow on main while checking and updating latest.
concurrency: npm-package-release

jobs:
release:
build-cli-v1:
if: github.ref == 'refs/heads/maintenance/cli-v1'
runs-on: ubuntu-latest
permissions:
contents: write
contents: read
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- run: corepack enable
- uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
cache: yarn
- run: yarn install --immutable
- run: node --test scripts/cli-v1-release.test.mjs
- run: yarn workspace @reflag/cli test
- run: yarn workspace @reflag/cli build
- run: yarn workspace @reflag/cli pack --out "$RUNNER_TEMP/reflag-cli.tgz"
- uses: actions/upload-artifact@v4
with:
name: reflag-cli
path: ${{ runner.temp }}/reflag-cli.tgz
if-no-files-found: error
overwrite: true

publish-cli-v1:
needs: build-cli-v1
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
# Use the PAT for git operations so the release PR update can trigger CI.
token: ${{ secrets.CHANGESETS_BOT_TOKEN }}
- name: Enable corepack
run: corepack enable
persist-credentials: false
- uses: actions/setup-node@v6
with:
node-version-file: ".nvmrc"
cache: "yarn"
cache-dependency-path: "**/yarn.lock"
registry-url: "https://registry.npmjs.org"
scope: "@reflag"
- name: Install dependencies
run: yarn install --immutable
- name: Create release PR or publish packages
id: changesets
uses: changesets/action@v1
node-version-file: .nvmrc
registry-url: https://registry.npmjs.org
package-manager-cache: false
- uses: actions/download-artifact@v4
with:
version: yarn version-packages
publish: yarn release-packages
title: Version Packages
commit: Version Packages
name: reflag-cli
path: ${{ runner.temp }}
- name: Check the packaged CLI version and npm latest tag
env:
GITHUB_TOKEN: ${{ secrets.CHANGESETS_BOT_TOKEN }}
- name: Build docs
if: steps.changesets.outputs.published == 'true'
run: yarn docs
- name: Checkout docs with SSH
if: steps.changesets.outputs.published == 'true'
uses: actions/checkout@v3
with:
repository: reflagcom/docs
ssh-key: ${{ secrets.DOCS_DEPLOY_KEY }}
path: reflag-docs
- name: Copy generated docs to docs repo
if: steps.changesets.outputs.published == 'true'
run: |
rm -rf reflag-docs/sdk
cp -R dist/docs reflag-docs/sdk
- name: Commit and push changes
if: steps.changesets.outputs.published == 'true'
CLI_VERSION: ${{ inputs.version }}
run: |
cd reflag-docs
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@reflag.com"
git add sdk
git commit -m "Update documentation" && git push || echo "No docs changes to commit"
set -o pipefail
tar -xOf "$RUNNER_TEMP/reflag-cli.tgz" package/package.json | node scripts/cli-v1-release.mjs
- name: Publish CLI v1 to latest
if: ${{ !inputs.dry_run }}
run: npm publish "$RUNNER_TEMP/reflag-cli.tgz" --access public --tag latest --ignore-scripts
8 changes: 8 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @reflag/cli

## 1.0.5

### Patch Changes

- ee30ad5: Fix app discovery for users who belong to multiple organizations. `reflag apps list` shows each app's organization, `reflag init` lets you choose an organization, and existing configs resolve their `appId` without requiring an `orgId`. Use `orgId` or `--org-id` to restrict the CLI to one organization. API keys remain scoped to their app.
- 1adfced: Update Express and Zod to patched versions. Preserve CLI schema parsing behavior when migrating to Zod 4.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reflag/cli",
"version": "1.0.4",
"version": "1.0.5",
"description": "CLI for Reflag service",
"homepage": "https://docs.reflag.com/",
"license": "MIT",
Expand Down
52 changes: 52 additions & 0 deletions scripts/cli-v1-release.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";

const packageName = "@reflag/cli";
const stableV1 = /^1\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;

export function assertCliV1Release(manifest, requestedVersion, latest) {
if (manifest.name !== packageName || manifest.private) {
throw new Error(`Expected the public ${packageName} package`);
}
if (
!stableV1.test(requestedVersion) ||
manifest.version !== requestedVersion
) {
throw new Error(
"The requested stable CLI v1 version must match the packaged version",
);
}

const current = typeof latest === "string" && stableV1.exec(latest);
if (!current) {
throw new Error(
`Refusing to update npm latest: '${latest}' is not a stable CLI v1 version`,
);
}
const expected = `1.${current[1]}.${BigInt(current[2]) + 1n}`;
if (requestedVersion !== expected) {
throw new Error(
`Expected the next CLI v1 patch (${expected}), not ${requestedVersion}`,
);
}
}

if (
process.argv[1] &&
resolve(process.argv[1]) === fileURLToPath(import.meta.url)
) {
const manifest = JSON.parse(readFileSync(0, "utf8"));
const response = await fetch(
`https://registry.npmjs.org/-/package/${encodeURIComponent(packageName)}/dist-tags`,
{ signal: AbortSignal.timeout(10_000) },
);
if (!response.ok) {
throw new Error(`Could not read npm dist-tags (HTTP ${response.status})`);
}
const { latest } = await response.json();
assertCliV1Release(manifest, process.env.CLI_VERSION, latest);
console.log(
`Verified ${packageName} can move npm latest from ${latest} to ${manifest.version}`,
);
}
49 changes: 49 additions & 0 deletions scripts/cli-v1-release.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import assert from "node:assert/strict";
import { test } from "node:test";

import { assertCliV1Release } from "./cli-v1-release.mjs";

const cli = { name: "@reflag/cli", version: "1.0.5" };

test("accepts the next stable CLI v1 patch", () => {
assert.doesNotThrow(() => assertCliV1Release(cli, "1.0.5", "1.0.4"));
});

test("does not let a maintenance release move latest if it no longer points at a stable v1", () => {
for (const latest of [undefined, "0.9.9", "1.0.4-next.1", "2.0.0"]) {
assert.throws(
() => assertCliV1Release(cli, "1.0.5", latest),
/not a stable CLI v1/,
);
}
});

test("rejects skipped patches, already released versions, and downgrades", () => {
for (const latest of ["1.0.3", "1.0.5", "1.0.6", "1.1.1"]) {
assert.throws(
() => assertCliV1Release(cli, "1.0.5", latest),
/Expected the next CLI v1 patch/,
);
}
});

test("rejects unconfirmed, prerelease, and different package versions", () => {
for (const version of [undefined, "1.0.6", "1.0.5-next.0", "2.0.0"]) {
assert.throws(
() => assertCliV1Release(cli, version, "1.0.4"),
/must match the packaged version/,
);
}
});

test("rejects building a different or private package", () => {
for (const manifest of [
{ ...cli, name: "@reflag/node-sdk" },
{ ...cli, private: true },
]) {
assert.throws(
() => assertCliV1Release(manifest, "1.0.5", "1.0.4"),
/Expected the public @reflag\/cli package/,
);
}
});
Loading