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
121 changes: 102 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: ci
on:
push:
pull_request:
# A new prisma release can break the arguments the action passes without any
# change here, so the newest CLIs are checked on a schedule too.
# A new prisma release can break the action without any change here, so the
# newest CLIs are checked on a schedule too. Failures go to Slack.
schedule:
- cron: "17 */6 * * *"
workflow_dispatch:
Expand Down Expand Up @@ -65,9 +65,9 @@ jobs:
strategy:
fail-fast: false
matrix:
# rc.29 is the last CLI that takes --stage. latest and dev are npm
# dist-tags, so a scheduled run tests each new release.
prisma: [8.0.0-rc.29, 8.0.0-rc.33, latest, dev]
# rc.29 is the last CLI that takes --stage. latest is an npm dist-tag,
# so a scheduled run tests each new release.
prisma: [8.0.0-rc.29, 8.0.0-rc.33, latest]
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
Expand All @@ -80,23 +80,106 @@ jobs:
PRISMA_CLI_BINS: ${{ runner.temp }}/prisma/node_modules/.bin/prisma
run: node --test tests/prisma-cli.test.mjs

open-issue-on-scheduled-failure:
needs: [check, prisma-cli]
if: failure() && github.event_name != 'push' && github.event_name != 'pull_request'
e2e:
name: The action deploys a real app with prisma ${{ matrix.prisma }}
# Pull requests from forks get no secrets. Branch pushes are covered by
# their pull request.
if: >-
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) &&
(github.event_name != 'push' || github.ref == 'refs/heads/main')
runs-on: ubuntu-latest
timeout-minutes: 40
strategy:
fail-fast: false
matrix:
# pinned is the version in e2e/app's lockfile; latest moves the app to
# prisma@latest and the Composer version it bundles.
prisma: [pinned, latest]
permissions:
issues: write
contents: read
# The sweep reads whether the run that made an environment has finished.
actions: read
env:
ENVIRONMENT: e2e-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.prisma }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
- name: Move the app to prisma@latest and its Composer version
if: matrix.prisma == 'latest'
working-directory: e2e/app
run: |
prisma=$(npm view prisma@latest version)
composer=$(npm view "prisma@$prisma" dependencies.@prisma/composer-cli)
echo "prisma $prisma, Composer $composer"
exact='^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'
if ! [[ $prisma =~ $exact && $composer =~ $exact ]]; then
echo "::error::could not resolve exact versions from npm: prisma \"$prisma\", Composer \"$composer\""
exit 1
fi
npm pkg set "devDependencies.prisma=$prisma" "dependencies.@prisma/composer=$composer" "dependencies.@prisma/composer-prisma-cloud=$composer"
bun install
- name: Deploy with the action
id: deploy
uses: ./
timeout-minutes: 15
env:
PRISMA_SERVICE_TOKEN: ${{ secrets.PRISMA_SERVICE_TOKEN }}
with:
working-directory: e2e/app
build-command: bun run build
environment: ${{ env.ENVIRONMENT }}
- name: Check the action's outputs and the deployed service
env:
OUTCOME: ${{ steps.deploy.outputs.outcome }}
URL: ${{ steps.deploy.outputs.url }}
URLS: ${{ steps.deploy.outputs.urls }}
REPORT_PATH: ${{ steps.deploy.outputs.report-path }}
timeout-minutes: 5
run: node e2e/verify.mjs
- name: Destroy the environment
if: always() && steps.deploy.outcome != 'skipped' && steps.deploy.outputs.outcome != 'skipped-no-credential'
working-directory: e2e/app
timeout-minutes: 10
env:
PRISMA_SERVICE_TOKEN: ${{ secrets.PRISMA_SERVICE_TOKEN }}
PRISMA_WORKSPACE_ID: ${{ vars.PRISMA_WORKSPACE_ID }}
run: bun scripts/destroy.ts
- name: Destroy environments earlier runs left behind
if: always() && steps.deploy.outcome != 'skipped' && steps.deploy.outputs.outcome != 'skipped-no-credential'
working-directory: e2e/app
timeout-minutes: 10
env:
PRISMA_SERVICE_TOKEN: ${{ secrets.PRISMA_SERVICE_TOKEN }}
PRISMA_WORKSPACE_ID: ${{ vars.PRISMA_WORKSPACE_ID }}
GITHUB_TOKEN: ${{ github.token }}
run: bun scripts/sweep.ts

report-failure:
name: Report a failure on main, a scheduled, manual or prisma-released run to Slack
needs: [check, prisma-cli, e2e]
# failure() misses a needed job that was cancelled or lost its runner.
if: >-
always() &&
(contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) &&
github.event_name != 'pull_request' &&
(github.event_name != 'push' || github.ref == 'refs/heads/main')
runs-on: ubuntu-latest
steps:
- name: Open or update the tracking issue
- name: Post to Slack
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
TEXT: >-
:rotating_light: prisma/cloud-deploy-action CI failed on a ${{ github.event_name }} run of ${{ github.ref_name }}
(check: ${{ needs.check.result }}, prisma CLI arguments: ${{ needs.prisma-cli.result }}, end-to-end deploy: ${{ needs.e2e.result }}).
Deploys that use the action may be broken.
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
title="Scheduled CI fails: a prisma release may break the action"
number=$(gh issue list --state open --search "in:title \"$title\"" --json number --jq '.[0].number')
if [ -n "$number" ]; then
gh issue comment "$number" --body "Still failing: $RUN_URL"
else
gh issue create --title "$title" --body "The action's checks fail against a prisma CLI release, so deploys that use it may be broken: $RUN_URL"
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
jq -n --arg text "$TEXT" '{text: $text}' |
curl --fail-with-body --silent --show-error -X POST -H 'Content-Type: application/json' --data @- "$SLACK_WEBHOOK_URL"
49 changes: 49 additions & 0 deletions .github/workflows/major-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: move major tag

# Workflows use the action as prisma/cloud-deploy-action@v1, so v1 must point
# at the newest v1.x.y release. Each run moves every major tag to its newest
# published release, so a run that GitHub cancels while it waits loses nothing.

on:
release:
# released fires for a full release, including a prerelease promoted to
# one, and never for a prerelease.
types: [released]
workflow_dispatch:

permissions:
contents: write

jobs:
move:
runs-on: ubuntu-latest
Comment thread
wmadden-electric marked this conversation as resolved.
Resolved
concurrency:
group: major-tag
cancel-in-progress: false
Comment thread
wmadden-electric marked this conversation as resolved.
Resolved
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
- name: Move each major tag to its newest published release
env:
GH_TOKEN: ${{ github.token }}
run: |
git fetch --tags --force --quiet
releases=$(gh release list --exclude-drafts --exclude-pre-releases --limit 1000 --json tagName --jq '.[].tagName' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' || true)
# A release can outlive its git tag; choose only among releases that have one.
releases=$(for tag in $releases; do if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then echo "$tag"; fi; done)
if [ -z "$releases" ]; then
echo "::error::found no published vX.Y.Z releases"
exit 1
fi
for major in $(echo "$releases" | cut -d. -f1 | sort -u); do
newest=$(echo "$releases" | grep "^$major\." | sort -V | tail -1)
target=$(git rev-parse "refs/tags/$newest^{commit}")
Comment thread
wmadden-electric marked this conversation as resolved.
Resolved
if [ "$(git rev-parse -q --verify "refs/tags/$major^{commit}" || true)" = "$target" ]; then
echo "$major already points at $newest"
continue
fi
git tag -f "$major" "$target"
git push --force origin "refs/tags/$major"
echo "$major now points at $newest ($target)"
done
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ Branch names reach the action as environment variables and are passed to the `pr

Plain Node with zero dependencies and no build step. Inputs arrive as `INPUT_*` environment variables; outputs and state go to `$GITHUB_OUTPUT` and `$GITHUB_STATE`.

CI tests the action in three ways. Unit tests cover the scripts. A matrix runs the exact arguments the action passes against real `prisma` CLIs, including the npm `latest` tag. An end-to-end job runs the action itself (`uses: ./`) on the small app in `e2e/app`: it deploys to a new preview environment, checks the outputs and that the service answers, then destroys the environment. It runs once with the app's pinned versions and once moved to `prisma@latest`. The end-to-end job needs the `PRISMA_SERVICE_TOKEN` secret and the `PRISMA_WORKSPACE_ID` variable. A sweep step destroys `e2e-*` environments whose run has finished, which are ones an earlier run could not destroy. It fails only when such an environment is more than a day old. To remove one by hand, run `ENVIRONMENT=<name> bun scripts/destroy.ts` in `e2e/app` with `PRISMA_SERVICE_TOKEN` and `PRISMA_WORKSPACE_ID` set. The end-to-end job covers the `bun install` path with the app's own `prisma` devDependency. It does not cover `npm ci` or the `prisma-version` input. CI also runs every 6 hours. A failed or cancelled job on `main`, on a scheduled run, on a manual run or on a `prisma-released` dispatch posts to Slack through the `SLACK_WEBHOOK_URL` secret.

Publishing a `v1.x.y` release, or promoting a prerelease to one, moves the `v1` tag to the newest published `v1.x.y` release (`.github/workflows/major-tag.yml`). Publishing a prerelease never moves it. To move it by hand, run that workflow.

## License

[Apache-2.0](LICENSE)
6 changes: 6 additions & 0 deletions e2e/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
dist/
.prisma-composer/
.prisma/
.alchemy/
report.json
1 change: 1 addition & 0 deletions e2e/app/app-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const APP_NAME = 'cloud-deploy-action-e2e';
Loading
Loading