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
1 change: 1 addition & 0 deletions .drive/deferred.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ Each needs a change to the Prisma Cloud Management API.

## Later Composer work

- **The publishable-location lint does not check every workspace member.** `scripts/lint-publishable-location.mjs` lists manifests by path globs that leave out `website/`, which is in the pnpm workspace. The promotion workflow takes its package list from `packages/9-public/` at the release's tag, and the publish workflow publishes every non-private workspace member. If `website/` ever became publishable, publish would ship it, promotion would leave it out, and the lint would not notice. Nothing is wrong today: `website/` is private. Fix by having the lint list members the way `publish-packages.mjs` does (`pnpm list -r`).
- **Destroying production deletes the operator's platform variables.** Destroying an app's production environment deletes its Prisma Cloud project, and with it every variable the operator set. The platform never returns a value, so an operator who kept no copy must make a new secret. Options: keep the project when it holds rows that are not Composer's, or warn before deleting. Needs its own decision about destroy.
- **An author-declared per-reader variable**, one that maps to the service scope the platform is expected to add, so that two readers of one name are guaranteed different values. Not built: where a value lives is the operator's choice on the platform, and nobody has a case that needs the author to force it. Wait for a real case.
- **A warning when the app names a variable another module expects under a different name.** Not needed: the deploy report lists every name with its readers, so a module wired to the wrong name shows up there.
Expand Down
203 changes: 203 additions & 0 deletions .github/workflows/promote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
name: Promote a release to latest

# A release is published under the `next` dist-tag (publish.yml); a bare
# install resolves `latest`. This workflow moves `latest` to a published
# release, by hand, once the Prisma ORM, Composer and prisma CLI versions that
# work together are all released and checked. See docs/oss/versioning.md.
#
# Three jobs, so that the npm token meets no code from the repository and no
# repository write access:
# - check: no npm token, read-only. Runs this workflow's own scripts on the
# release's tag, checked out as data only, and outputs what to move. A dry
# run ends here, from any branch.
# - promote: main only, not a dry run. Holds the token from the npm-promote
# environment, checks out nothing, and has no repository permissions.
# - mark-latest: marks the GitHub Release as Latest. Holds no npm token.

on:
workflow_dispatch:
inputs:
version:
description: "Release version to promote, such as 0.41.0"
required: true
type: string
dry-run:
description: "Dry run: check the release and print the moves, without changing any tag"
required: false
default: true
type: boolean
allow-downgrade:
description: "Allow moving latest back to an older release (a rollback)"
required: false
default: false
type: boolean

# A dry run from a branch gets its own group, so it cannot cancel a real
# promotion waiting in the queue.
concurrency:
group: ${{ github.ref == 'refs/heads/main' && 'npm-promote' || format('npm-promote-{0}', github.ref) }}
cancel-in-progress: false

permissions: {}

jobs:
check:
name: Check the release
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
plan: ${{ steps.plan.outputs.plan }}

steps:
- name: Check the inputs
env:
VERSION: ${{ inputs.version }}
DRY_RUN: ${{ inputs.dry-run }}
run: |
if ! printf '%s' "$VERSION" | grep -Eq '^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'; then
echo "::error::\"$VERSION\" is not a release version, such as 0.41.0."
exit 1
fi
if [ "$DRY_RUN" != "true" ] && [ "$GITHUB_REF" != "refs/heads/main" ]; then
echo "::error::A real promotion runs only from main. Run from $GITHUB_REF as a dry run, or dispatch from main."
exit 1
fi

- name: Checkout this workflow's ref
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
persist-credentials: false

# Data only: nothing in this folder is run.
- name: Checkout the release's tag as data
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: refs/tags/v${{ inputs.version }}
path: release-data
persist-credentials: false

- name: Check the release's tag is on main
env:
VERSION: ${{ inputs.version }}
run: |
tagged="$(git rev-parse "refs/tags/v$VERSION^{commit}")"
if [ "$(git -C release-data rev-parse HEAD)" != "$tagged" ]; then
echo "::error::The two checkouts of v$VERSION differ; the tag moved during the run."
exit 1
fi
if ! git merge-base --is-ancestor "$tagged" origin/main; then
echo "::error::v$VERSION points at $tagged, which is not on main. Only a release published from main can be promoted."
exit 1
fi

- name: Check the GitHub Release exists
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ inputs.version }}
run: gh release view "v$VERSION" --repo "$GITHUB_REPOSITORY" --json tagName > /dev/null

# Node only: nothing else may run before the plan is written.
- name: Setup mise
uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4.0.1
with:
cache: false

- name: Plan the promotion
id: plan
env:
VERSION: ${{ inputs.version }}
ALLOW_DOWNGRADE: ${{ inputs.allow-downgrade }}
run: |
flags=()
if [ "$ALLOW_DOWNGRADE" = "true" ]; then flags+=(--allow-downgrade); fi
node scripts/promote-release.ts "$VERSION" --release-root release-data --plan-out "$RUNNER_TEMP/plan.json" "${flags[@]}"
echo "plan=$(jq -c . "$RUNNER_TEMP/plan.json")" >> "$GITHUB_OUTPUT"

promote:
name: Move latest to the release
needs: check
if: ${{ github.ref == 'refs/heads/main' && !inputs.dry-run }}
runs-on: ubuntu-latest
environment: npm-promote
permissions: {}
outputs:
version: ${{ steps.move.outputs.version }}

steps:
- name: Check the npm token
env:
NPM_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }}
run: |
if [ -z "$NPM_TOKEN" ]; then
echo "::error::The npm-promote environment has no NPM_PROMOTE_TOKEN secret. Create a short-lived npm token, add it to that environment as NPM_PROMOTE_TOKEN, run again, then delete the secret and revoke the token. See docs/oss/versioning.md."
exit 1
fi
echo "::add-mask::$NPM_TOKEN"

# Runs no code from the repository: the plan comes from the check job,
# and each name and version in it is checked before use. The token
# reaches npm only through this step's environment, by a config file
# outside any checkout that refers to NODE_AUTH_TOKEN rather than
# holding it.
- name: Move latest
id: move
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PROMOTE_TOKEN }}
PLAN: ${{ needs.check.outputs.plan }}
VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
version_re='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
name_re='^@prisma/composer(-[a-z0-9-]+)?$'
release="$(jq -r '.version' <<<"$PLAN")"
entries="$(jq -r '.packages[] | "\(.name) \(.version)"' <<<"$PLAN")"
[[ $release =~ $version_re ]] || { echo "::error::The plan's version \"$release\" is not a release version."; exit 1; }
[ "$release" = "$VERSION" ] || { echo "::error::The plan is for $release, not the requested $VERSION."; exit 1; }
[ -n "$entries" ] || { echo "::error::The plan lists no package."; exit 1; }
while read -r name version <&3; do
[[ $name =~ $name_re ]] || { echo "::error::The plan names \"$name\", which is not one of ours."; exit 1; }
[ "$version" = "$release" ] || { echo "::error::The plan gives $name \"$version\", not the release's $release."; exit 1; }
done 3<<<"$entries"

npmrc="$RUNNER_TEMP/promote.npmrc"
printf '%s\n' 'registry=https://registry.npmjs.org/' "//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}" > "$npmrc"
export NPM_CONFIG_USERCONFIG="$npmrc"

while read -r name version <&3; do
if [ "$(npm view "$name@$version" version 2>/dev/null || true)" != "$version" ]; then
echo "::error::$name@$version is not on the registry. Nothing moved."
exit 1
fi
done 3<<<"$entries"

moved=()
while read -r name version <&3; do
if [ "$(npm view "$name" dist-tags.latest)" = "$version" ]; then
echo "$name: latest is already $version"
continue
fi
if npm dist-tag add "$name@$version" latest || npm dist-tag add "$name@$version" latest; then
moved+=("$name")
echo "$name: latest moved to $version"
else
echo "::error::Moving latest failed for $name@$version. Moved in this run: ${moved[*]:-none}. Run the workflow again to move the rest; packages already moved are left alone."
exit 1
fi
done 3<<<"$entries"
echo "version=$release" >> "$GITHUB_OUTPUT"

mark-latest:
name: Mark the GitHub Release as Latest
needs: promote
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# publish.yml creates the GitHub Release without the Latest mark.
- name: Mark the GitHub Release as Latest
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.promote.outputs.version }}
run: gh release edit "v$VERSION" --repo "$GITHUB_REPOSITORY" --latest
45 changes: 26 additions & 19 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ name: Publish to npm
# - push to `main` with the root `version` unchanged → publish `<base>-dev.N`
# under dist-tag `dev`.
# - push to `main` with the root `version` changed → publish `<base>` under
# dist-tag `latest` and create a GitHub Release. This is how a merged
# release-bump PR auto-ships. The same run then publishes `<base>-dev.N`
# dist-tag `next` and create a GitHub Release. This is how a merged
# release-bump PR publishes a release. It never moves `latest`: a
# maintainer promotes the release to `latest` later
# (docs/oss/versioning.md). The same run then publishes `<base>-dev.N`
# under `dev`, so every push to `main` — release or not — leaves the `dev`
# dist-tag on a build of that commit. When releases skipped the dev
# publish, `dev` sat on the previous base until the next routine push.
# - workflow_dispatch → publish `<base>` under the chosen dist-tag (default
# `latest`); also the dry-run path.
# `next`; `latest` and `dev` are refused); also the dry-run path. A run under
# `next` re-publishes a release whose publish failed, and counts as a release.

on:
push:
Expand All @@ -24,9 +27,9 @@ on:
workflow_dispatch:
inputs:
dist-tag:
description: "npm dist-tag (e.g., latest, dev, beta)"
description: "npm dist-tag: next re-publishes a release whose publish failed (latest and dev are refused)"
required: true
default: "latest"
default: "next"
type: string
dry-run:
description: "Dry-run only (build + pack + gate, no npm publish, no GitHub Release)."
Expand All @@ -48,15 +51,15 @@ jobs:
# dry-run path performs no registry writes and skips the GitHub Release step.
if: ${{ github.ref == 'refs/heads/main' || (github.event_name == 'workflow_dispatch' && github.event.inputs.dry-run == 'true') }}
permissions:
contents: write # Required to create the GitHub Release + tag for stable publishes
contents: write # Required to create the GitHub Release and git tags
id-token: write # Required for npm OIDC Trusted Publishing

steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
# determine-version.ts compares the root `package.json` version at
# `github.event.before` to HEAD to decide dev vs latest; a multi-commit
# `github.event.before` to HEAD to decide dev vs release; a multi-commit
# push can place `before` arbitrarily far back, so fetch full history.
fetch-depth: 0

Expand Down Expand Up @@ -135,10 +138,11 @@ jobs:
NPM_CONFIG_PROVENANCE: "true"
run: node scripts/publish-packages.mjs --tag "${{ steps.version.outputs.tag }}"

# Lightweight git tag for non-stable publishes (dev / beta). Stable publishes
# get a tag via `gh release create` below. Idempotent: skip if v$VERSION exists.
- name: Create lightweight git tag for non-stable publishes
if: ${{ steps.version.outputs.tag != 'latest' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }}
# Lightweight git tag for publishes that are not releases (a manual run
# under a tag such as `beta`). Releases get their tag from
# `gh release create` below. Idempotent: skip if v$VERSION exists.
- name: Create lightweight git tag for publishes that are not releases
if: ${{ steps.version.outputs.release != 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
Expand All @@ -152,11 +156,13 @@ jobs:
-f "sha=$GITHUB_SHA"
fi

# Emit a GitHub Release for stable publishes only (dist-tag `latest`).
# Notes are auto-generated from the commits/PRs since the previous tag.
# Emit a GitHub Release for releases: a release-bump push, or a manual
# run under `next`. Notes are auto-generated from the commits/PRs since
# the previous tag. `--latest=false`: GitHub marks it its latest release
# when promote.yml moves npm `latest`.
# Idempotent on rerun: edit an existing Release rather than re-create it.
- name: Create GitHub Release for stable publishes
if: ${{ steps.version.outputs.tag == 'latest' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }}
- name: Create GitHub Release
if: ${{ steps.version.outputs.release == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
Expand All @@ -169,16 +175,17 @@ jobs:
gh release create "v$VERSION" \
--target "$GITHUB_SHA" \
--title "v$VERSION" \
--latest=false \
--generate-notes
fi

# Tell prisma-cli a release shipped so its update-product-versions
# workflow can open the repin PR now instead of at its daily run
# (prisma-cli docs/oss/release-automation.md). Stable publishes only:
# the receiver re-reads the registry at the release dist-tag, so a dev
# publish would be a no-op there. Never fails the publish.
# (prisma-cli docs/oss/release-automation.md). Releases only: the
# receiver reads each product's `next` tag first, so it finds this
# release; a dev publish would be a no-op there. Never fails the publish.
- name: Notify prisma-cli
if: ${{ steps.version.outputs.tag == 'latest' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }}
if: ${{ steps.version.outputs.release == 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true') }}
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.DEPLOY_GITHUB_TOKEN }}
Expand Down
Loading
Loading