|
| 1 | +name: Release CLI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_type: |
| 7 | + description: Version strategy to publish |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + default: current |
| 11 | + options: |
| 12 | + - current |
| 13 | + - alpha |
| 14 | + - custom |
| 15 | + custom_version: |
| 16 | + description: Exact version when release_type is custom (for example 0.2.0) |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + dry_run: |
| 20 | + description: Validate the release without publishing, tagging, or pushing |
| 21 | + required: false |
| 22 | + type: boolean |
| 23 | + default: false |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: release-cli-main |
| 27 | + cancel-in-progress: false |
| 28 | + |
| 29 | +jobs: |
| 30 | + release: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + contents: write |
| 34 | + id-token: write |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Ensure workflow runs from main |
| 38 | + run: | |
| 39 | + if [ "${GITHUB_REF}" != "refs/heads/main" ]; then |
| 40 | + echo "This workflow only releases from main." |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | +
|
| 44 | + - uses: actions/checkout@v5 |
| 45 | + with: |
| 46 | + fetch-depth: 0 |
| 47 | + |
| 48 | + - uses: pnpm/action-setup@v5 |
| 49 | + with: |
| 50 | + version: 10.30.0 |
| 51 | + |
| 52 | + - uses: actions/setup-node@v6 |
| 53 | + with: |
| 54 | + node-version: 24 |
| 55 | + registry-url: https://registry.npmjs.org |
| 56 | + cache: pnpm |
| 57 | + |
| 58 | + - name: Install dependencies |
| 59 | + run: pnpm install --frozen-lockfile |
| 60 | + |
| 61 | + - name: Configure git author |
| 62 | + run: | |
| 63 | + git config user.name "github-actions[bot]" |
| 64 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 65 | +
|
| 66 | + - name: Bump CLI version |
| 67 | + id: cli_version |
| 68 | + env: |
| 69 | + RELEASE_TYPE: ${{ inputs.release_type }} |
| 70 | + CUSTOM_VERSION: ${{ inputs.custom_version }} |
| 71 | + run: | |
| 72 | + if [ "${RELEASE_TYPE}" = "custom" ] && [ -z "${CUSTOM_VERSION}" ]; then |
| 73 | + echo "custom_version is required when release_type=custom." |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | +
|
| 77 | + if [ "${RELEASE_TYPE}" = "current" ]; then |
| 78 | + VERSION="$(node -e "process.stdout.write(JSON.parse(require('fs').readFileSync('packages/cli/package.json', 'utf8')).version)")" |
| 79 | + printf 'version=%s\n' "${VERSION}" >> "$GITHUB_OUTPUT" |
| 80 | + exit 0 |
| 81 | + fi |
| 82 | +
|
| 83 | + TARGET="prerelease --preid alpha" |
| 84 | + if [ "${RELEASE_TYPE}" = "custom" ]; then |
| 85 | + TARGET="${CUSTOM_VERSION}" |
| 86 | + fi |
| 87 | +
|
| 88 | + npm --prefix packages/cli version ${TARGET} --no-git-tag-version >/dev/null |
| 89 | + VERSION="$(node -e "process.stdout.write(JSON.parse(require('fs').readFileSync('packages/cli/package.json', 'utf8')).version)")" |
| 90 | + printf 'version=%s\n' "${VERSION}" >> "$GITHUB_OUTPUT" |
| 91 | +
|
| 92 | + - name: Fail if version already exists on npm |
| 93 | + run: | |
| 94 | + PACKAGE='@prisma/cli' |
| 95 | + VERSION='${{ steps.cli_version.outputs.version }}' |
| 96 | + if npm view "${PACKAGE}@${VERSION}" version >/dev/null 2>&1; then |
| 97 | + echo "${PACKAGE}@${VERSION} already exists on npm." |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | +
|
| 101 | + - name: Run focused CLI tests |
| 102 | + run: pnpm --filter @prisma/cli test |
| 103 | + |
| 104 | + - name: Build CLI package |
| 105 | + run: pnpm --filter @prisma/cli build |
| 106 | + |
| 107 | + - name: Prepare staged publish package |
| 108 | + run: node scripts/prepare-cli-publish.mjs .publish/cli |
| 109 | + |
| 110 | + - name: Audit staged package contents |
| 111 | + working-directory: .publish/cli |
| 112 | + run: | |
| 113 | + PACK_JSON="$(npm pack --dry-run --json)" |
| 114 | + PACK_JSON="${PACK_JSON}" node -e " |
| 115 | + const pack = JSON.parse(process.env.PACK_JSON)[0] |
| 116 | + const files = pack.files.map((file) => file.path).sort() |
| 117 | + const forbidden = files.filter((file) => |
| 118 | + file.startsWith('src/') || |
| 119 | + file.startsWith('tests/') || |
| 120 | + file.startsWith('fixtures/') || |
| 121 | + file.startsWith('docs/') || |
| 122 | + file.startsWith('.prisma/') || |
| 123 | + file.startsWith('.publish/') |
| 124 | + ) |
| 125 | + if (forbidden.length) { |
| 126 | + console.error('Forbidden files in npm package:', forbidden.join(', ')) |
| 127 | + process.exit(1) |
| 128 | + } |
| 129 | + for (const required of ['dist/cli.js', 'README.md', 'LICENSE', 'package.json']) { |
| 130 | + if (!files.includes(required)) { |
| 131 | + console.error('Missing required package file:', required) |
| 132 | + process.exit(1) |
| 133 | + } |
| 134 | + } |
| 135 | + " |
| 136 | +
|
| 137 | + - name: Smoke test staged tarball install |
| 138 | + run: | |
| 139 | + TARBALL="$(cd .publish/cli && npm pack --silent)" |
| 140 | + TMPDIR="$(mktemp -d)" |
| 141 | + cat > "${TMPDIR}/package.json" <<'EOF' |
| 142 | + { |
| 143 | + "name": "cli-publish-smoke", |
| 144 | + "private": true |
| 145 | + } |
| 146 | + EOF |
| 147 | + pnpm add -D "${PWD}/.publish/cli/${TARBALL}" --dir "${TMPDIR}" |
| 148 | + ( |
| 149 | + cd "${TMPDIR}" |
| 150 | + pnpm prisma-cli --help |
| 151 | + pnpm prisma-cli auth whoami --json |
| 152 | + ) |
| 153 | +
|
| 154 | + - name: Ensure release still targets the latest main |
| 155 | + if: ${{ !inputs.dry_run }} |
| 156 | + run: | |
| 157 | + git fetch origin main |
| 158 | + if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then |
| 159 | + echo "main moved while the release was running. Rerun the workflow from the latest main." |
| 160 | + exit 1 |
| 161 | + fi |
| 162 | +
|
| 163 | + - name: Publish to npm |
| 164 | + if: ${{ !inputs.dry_run }} |
| 165 | + working-directory: .publish/cli |
| 166 | + run: npm publish --access public --tag preview --provenance |
| 167 | + |
| 168 | + - name: Commit release version |
| 169 | + if: ${{ !inputs.dry_run }} |
| 170 | + run: | |
| 171 | + VERSION='${{ steps.cli_version.outputs.version }}' |
| 172 | + git add packages/cli/package.json |
| 173 | + if ! git diff --cached --quiet; then |
| 174 | + git commit -m "chore(cli): release @prisma/cli v${VERSION}" |
| 175 | + fi |
| 176 | + git tag "cli-v${VERSION}" |
| 177 | +
|
| 178 | + - name: Push release commit and tag |
| 179 | + if: ${{ !inputs.dry_run }} |
| 180 | + run: | |
| 181 | + VERSION='${{ steps.cli_version.outputs.version }}' |
| 182 | + git push origin HEAD:main |
| 183 | + git push origin "cli-v${VERSION}" |
| 184 | +
|
| 185 | + - name: Summarize release |
| 186 | + run: | |
| 187 | + VERSION='${{ steps.cli_version.outputs.version }}' |
| 188 | + { |
| 189 | + echo "## Release CLI" |
| 190 | + echo |
| 191 | + echo "- Version: \`${VERSION}\`" |
| 192 | + echo "- Dry run: \`${{ inputs.dry_run }}\`" |
| 193 | + if [ '${{ inputs.dry_run }}' = 'true' ]; then |
| 194 | + echo "- Publish: skipped" |
| 195 | + echo "- Tag/push: skipped" |
| 196 | + else |
| 197 | + echo "- npm package: \`@prisma/cli@${VERSION}\`" |
| 198 | + echo "- npm dist-tag: \`preview\`" |
| 199 | + echo "- git tag: \`cli-v${VERSION}\`" |
| 200 | + fi |
| 201 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments