Skip to content
Open
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
130 changes: 130 additions & 0 deletions .github/workflows/check-dev-build-with-cloud-deploy-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: cloud-deploy-action can drive the dev build

# An early warning, not a blocker: the dev build must stay published so
# prisma/cloud-deploy-action can be fixed against it. The Test check on
# pull requests runs the same test and blocks the release instead.
# See docs/oss/release-automation.md.

on:
workflow_run:
workflows: ["Publish to npm"]
types: [completed]
branches: [main]

permissions: {}

jobs:
cloud-deploy-action-drives-dev-build:
name: prisma/cloud-deploy-action can drive the dev build
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
env:
ACTION_REF: ${{ vars.CLOUD_DEPLOY_ACTION_REF || 'v1' }}

steps:
# Checked on every run so a missing secret shows up at the first
# publish, not at the first incompatibility.
- name: Check that SLACK_WEBHOOK_URL is set
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
if [ -z "$SLACK_WEBHOOK_URL" ]; then
echo "::error::The SLACK_WEBHOOK_URL secret is not set, so this check cannot report a failure."
exit 1
fi

# publish.yml uploads this artifact only after it really published.
- name: Find the published dev version
id: dev
env:
GH_TOKEN: ${{ github.token }}
PUBLISH_RUN_ID: ${{ github.event.workflow_run.id }}
run: |
artifact=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$PUBLISH_RUN_ID/artifacts" \
--jq '.artifacts[] | select(.name == "published-dev-version") | .id')
if [ -z "$artifact" ]; then
published=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$PUBLISH_RUN_ID/jobs" \
--jq '[.jobs[].steps[] | select(.name == "Publish the dev version")] | first | .conclusion')
if [ "$published" = success ]; then
echo "::error::Publish run $PUBLISH_RUN_ID published a dev build but has no published-dev-version artifact."
exit 1
fi
echo "Publish run $PUBLISH_RUN_ID published no dev build (its publish step: ${published:-absent}). Nothing to check."
exit 0
fi
gh run download "$PUBLISH_RUN_ID" --repo "$GITHUB_REPOSITORY" --name published-dev-version --dir "$RUNNER_TEMP/published-dev-version"
version=$(cat "$RUNNER_TEMP/published-dev-version/version")
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-[0-9A-Za-z.-]+$ ]]; then
echo "::error::The published-dev-version artifact holds \"$version\", which is not a version."
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"

- name: Checkout
if: ${{ steps.dev.outputs.version != '' }}
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false

- name: Set up Node.js
if: ${{ steps.dev.outputs.version != '' }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: .node-version

- name: Install prisma@${{ steps.dev.outputs.version }}
if: ${{ steps.dev.outputs.version != '' }}
env:
VERSION: ${{ steps.dev.outputs.version }}
run: npm install --prefix "$RUNNER_TEMP/prisma-dev" --no-save --no-package-lock "prisma@$VERSION"

- name: Check out prisma/cloud-deploy-action
if: ${{ steps.dev.outputs.version != '' }}
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
repository: prisma/cloud-deploy-action
ref: ${{ env.ACTION_REF }}
path: .reference/cloud-deploy-action
persist-credentials: false

- name: prisma/cloud-deploy-action can drive prisma@${{ steps.dev.outputs.version }}
id: drive
if: ${{ steps.dev.outputs.version != '' }}
run: |
code=0
node scripts/check-cloud-deploy-action.mjs .reference/cloud-deploy-action "$RUNNER_TEMP/prisma-dev/node_modules/.bin/prisma" || code=$?
echo "exit-code=$code" >> "$GITHUB_OUTPUT"
exit "$code"

- name: Alert Slack
if: ${{ failure() }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
DRIVE_EXIT_CODE: ${{ steps.drive.outputs.exit-code }}
VERSION: ${{ steps.dev.outputs.version }}
PUBLISH_RUN_URL: ${{ github.event.workflow_run.html_url }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ -z "$SLACK_WEBHOOK_URL" ]; then
echo "::error::The SLACK_WEBHOOK_URL secret is not set, so this failure was not reported."
exit 1
fi
# Exit codes of scripts/check-cloud-deploy-action.mjs.
case "$DRIVE_EXIT_CODE" in
1)
text="The dev build prisma@$VERSION fails prisma/cloud-deploy-action's test: the released action ($ACTION_REF) cannot drive it. The fix is a prisma/cloud-deploy-action release whose rule covers these dev builds and the next CLI version. Until then the next prisma CLI release is blocked, and this alert repeats on each merge to prisma-cli's main. See docs/oss/release-automation.md#changing-the-deploy-arguments-on-purpose."
;;
2)
text="The check that prisma/cloud-deploy-action can drive prisma@$VERSION could not run, so the dev build was not tested: the action's test file or the installed prisma executable is missing, or the action's deploy cases did not run. The run log says which."
;;
*)
text="The check that prisma/cloud-deploy-action can drive the dev build could not run, so the dev build was not tested: the published dev version artifact is missing or unreadable, npm install failed, or a checkout failed. Publish run: $PUBLISH_RUN_URL"
;;
esac
payload=$(jq -n --arg text "$text" --arg run "$RUN_URL" '{text: "\($text)\nRun: \($run)"}')
curl --fail-with-body --silent --show-error \
-H "Content-Type: application/json" \
--data "$payload" \
"$SLACK_WEBHOOK_URL"
18 changes: 18 additions & 0 deletions .github/workflows/pr-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,21 @@ jobs:
env:
PUBLISH_CHANNEL: dev
run: pnpm check:conformance

# prisma/cloud-deploy-action runs `prisma deploy` with fixed
# arguments. `v1` is the moving tag users run, so a CLI change that
# breaks those arguments fails here, before it can be released. See
# docs/oss/release-automation.md for CLOUD_DEPLOY_ACTION_REF.
- name: Build the prisma package
run: pnpm exec turbo run build --filter=prisma

- name: Check out prisma/cloud-deploy-action
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
repository: prisma/cloud-deploy-action
ref: ${{ vars.CLOUD_DEPLOY_ACTION_REF || 'v1' }}
path: .reference/cloud-deploy-action
persist-credentials: false

- name: prisma/cloud-deploy-action can drive this CLI
run: node scripts/check-cloud-deploy-action.mjs .reference/cloud-deploy-action packages/prisma/dist/prisma.js
27 changes: 26 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish to npm
name: Publish to npm # check-dev-build-with-cloud-deploy-action.yml finds this workflow by this name

# Every run publishes a dev build. A run also publishes a release when
# the push changed the root `version`, or a dispatch asked for one. The
Expand Down Expand Up @@ -104,6 +104,7 @@ jobs:
NPM_CONFIG_PROVENANCE: "true"
run: bash scripts/publish-packages.sh latest @prisma/cli-engine

# check-dev-build-with-cloud-deploy-action.yml reads this step's result by its name.
- name: Publish the dev version
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true' }}
env:
Expand All @@ -121,6 +122,30 @@ jobs:
"@prisma/cli@$DEV_VERSION" \
"prisma@$DEV_VERSION"

# Read by check-dev-build-with-cloud-deploy-action.yml, which runs as
# its own workflow so its result never holds or fails this one.
- name: Record the published dev version
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true' }}
continue-on-error: true
timeout-minutes: 2
env:
DEV_VERSION: ${{ steps.version.outputs.devVersion }}
run: |
mkdir -p "$RUNNER_TEMP/dev-version"
printf '%s\n' "$DEV_VERSION" > "$RUNNER_TEMP/dev-version/version"

- name: Upload the published dev version
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.dry-run != 'true' }}
continue-on-error: true
timeout-minutes: 2
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: published-dev-version
path: ${{ runner.temp }}/dev-version/version
if-no-files-found: error
overwrite: true
retention-days: 7

# --- The release: only when the committed version changed. ---

- name: Restore the committed versions
Expand Down
Loading
Loading