diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 45e7c79e7..000000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,72 +0,0 @@ -name: Release packages - -on: - 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 - -# Serialize with the release workflow on main while checking and updating latest. -concurrency: npm-package-release - -jobs: - build-cli-v1: - if: github.ref == 'refs/heads/maintenance/cli-v1' - runs-on: ubuntu-latest - permissions: - 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 - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - uses: actions/setup-node@v6 - with: - node-version-file: .nvmrc - registry-url: https://registry.npmjs.org - package-manager-cache: false - - uses: actions/download-artifact@v4 - with: - name: reflag-cli - path: ${{ runner.temp }} - - name: Check the packaged CLI version and npm latest tag - env: - CLI_VERSION: ${{ inputs.version }} - run: | - 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 diff --git a/scripts/cli-v1-release.mjs b/scripts/cli-v1-release.mjs deleted file mode 100644 index e361acece..000000000 --- a/scripts/cli-v1-release.mjs +++ /dev/null @@ -1,52 +0,0 @@ -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}`, - ); -} diff --git a/scripts/cli-v1-release.test.mjs b/scripts/cli-v1-release.test.mjs deleted file mode 100644 index 726913b99..000000000 --- a/scripts/cli-v1-release.test.mjs +++ /dev/null @@ -1,49 +0,0 @@ -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/, - ); - } -});