chore(release): 0.8.0 #216
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| - labeled | |
| - reopened | |
| - ready_for_review | |
| permissions: | |
| contents: read | |
| id-token: write | |
| concurrency: | |
| group: publish-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
| jobs: | |
| preview: | |
| name: Publish PR preview | |
| if: >- | |
| github.event_name == 'pull_request' && | |
| github.event.pull_request.head.repo.full_name == github.repository && | |
| (github.event.action != 'labeled' || github.event.label.name == 'release:next') | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| permissions: | |
| contents: read | |
| id-token: write | |
| issues: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22.18.0" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Compute preview metadata | |
| id: preview | |
| run: | | |
| PR_NUMBER="${{ github.event.pull_request.number }}" | |
| PUBLISH_NEXT="${{ contains(github.event.pull_request.labels.*.name, 'release:next') }}" | |
| BASE_VERSION=$(node -e "const fs=require('fs');const p=JSON.parse(fs.readFileSync('package.json','utf8'));process.stdout.write(p.version)") | |
| if [ "$PUBLISH_NEXT" = "true" ]; then | |
| PREVIEW_VERSION="${BASE_VERSION}-next.${PR_NUMBER}.${{ github.run_number }}.${{ github.run_attempt }}" | |
| DIST_TAG="next" | |
| else | |
| PREVIEW_VERSION="${BASE_VERSION}-pr.${PR_NUMBER}.${{ github.run_number }}.${{ github.run_attempt }}" | |
| DIST_TAG="pr${PR_NUMBER}" | |
| fi | |
| echo "base_version=$BASE_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "version=$PREVIEW_VERSION" >> "$GITHUB_OUTPUT" | |
| echo "dist_tag=$DIST_TAG" >> "$GITHUB_OUTPUT" | |
| echo "publish_next=$PUBLISH_NEXT" >> "$GITHUB_OUTPUT" | |
| - name: Ensure npm version for trusted publishing | |
| run: | | |
| npm install -g npm@11.5.1 | |
| echo "Node: $(node --version)" | |
| echo "npm: $(npm --version)" | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Set preview package version | |
| env: | |
| PREVIEW_VERSION: ${{ steps.preview.outputs.version }} | |
| run: | | |
| node - <<'EOF' | |
| const fs = require("fs"); | |
| const packageJsonPath = "package.json"; | |
| const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); | |
| packageJson.version = process.env.PREVIEW_VERSION; | |
| fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`); | |
| EOF | |
| - name: Check | |
| run: bun run check | |
| - name: Typecheck | |
| run: bun run typecheck | |
| - name: Build | |
| run: bun run build | |
| env: | |
| CREATE_PRISMA_TELEMETRY_API_KEY: ${{ steps.preview.outputs.publish_next == 'true' && secrets.CREATE_PRISMA_TELEMETRY_API_KEY || '' }} | |
| CREATE_PRISMA_TELEMETRY_HOST: ${{ steps.preview.outputs.publish_next == 'true' && vars.CREATE_PRISMA_TELEMETRY_HOST || '' }} | |
| - name: Publish to npm | |
| run: npm publish --access public --tag "${{ steps.preview.outputs.dist_tag }}" | |
| - name: Update PR preview comment | |
| uses: actions/github-script@v7 | |
| env: | |
| PREVIEW_VERSION: ${{ steps.preview.outputs.version }} | |
| DIST_TAG: ${{ steps.preview.outputs.dist_tag }} | |
| PUBLISH_NEXT: ${{ steps.preview.outputs.publish_next }} | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| with: | |
| script: | | |
| const marker = "<!-- create-prisma-preview-comment -->"; | |
| const isNext = process.env.PUBLISH_NEXT === "true"; | |
| const body = [ | |
| marker, | |
| isNext ? "## @next preview published" : "## PR preview published", | |
| "", | |
| `- Version: \`${process.env.PREVIEW_VERSION}\``, | |
| `- Tag: \`${process.env.DIST_TAG}\``, | |
| ...(isNext | |
| ? ["- Trigger: PR has the `release:next` label, so this is available as `create-prisma@next`"] | |
| : []), | |
| `- Run with Bun: \`bunx create-prisma@${process.env.DIST_TAG}\``, | |
| `- Run with npm: \`npx create-prisma@${process.env.DIST_TAG}\``, | |
| `- Run with Yarn: \`yarn dlx create-prisma@${process.env.DIST_TAG}\``, | |
| `- Run with pnpm: \`pnpm dlx create-prisma@${process.env.DIST_TAG}\``, | |
| `- Run with Deno: \`deno run -A npm:create-prisma@${process.env.DIST_TAG}\``, | |
| `- Workflow run: ${process.env.RUN_URL}`, | |
| ].join("\n"); | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.payload.pull_request.number; | |
| const comments = await github.paginate(github.rest.issues.listComments, { | |
| owner, | |
| repo, | |
| issue_number, | |
| }); | |
| const existingComment = comments.find((comment) => | |
| comment.user?.type === "Bot" && comment.body?.includes(marker) | |
| ); | |
| if (existingComment) { | |
| await github.rest.issues.updateComment({ | |
| owner, | |
| repo, | |
| comment_id: existingComment.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number, | |
| body, | |
| }); | |
| } | |
| - name: Preview summary | |
| run: | | |
| if [ "${{ steps.preview.outputs.publish_next }}" = "true" ]; then | |
| echo "## @next preview published" >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| echo "## PR preview published" >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- Version: \`${{ steps.preview.outputs.version }}\`" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- Tag: \`${{ steps.preview.outputs.dist_tag }}\`" >> "$GITHUB_STEP_SUMMARY" | |
| if [ "${{ steps.preview.outputs.publish_next }}" = "true" ]; then | |
| echo "- Trigger: PR has the \`release:next\` label" >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| echo "- Run with Bun: \`bunx create-prisma@${{ steps.preview.outputs.dist_tag }}\`" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- Run with npm: \`npx create-prisma@${{ steps.preview.outputs.dist_tag }}\`" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- Run with Yarn: \`yarn dlx create-prisma@${{ steps.preview.outputs.dist_tag }}\`" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- Run with pnpm: \`pnpm dlx create-prisma@${{ steps.preview.outputs.dist_tag }}\`" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- Run with Deno: \`deno run -A npm:create-prisma@${{ steps.preview.outputs.dist_tag }}\`" >> "$GITHUB_STEP_SUMMARY" | |
| release: | |
| name: Release to npm | |
| if: github.event_name == 'push' && startsWith(github.event.head_commit.message, 'chore(release):') | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| env: | |
| CREATE_PRISMA_TELEMETRY_API_KEY: ${{ secrets.CREATE_PRISMA_TELEMETRY_API_KEY }} | |
| CREATE_PRISMA_TELEMETRY_HOST: ${{ vars.CREATE_PRISMA_TELEMETRY_HOST }} | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22.18.0" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Extract version from commit message | |
| id: version | |
| run: | | |
| VERSION=$(echo "${{ github.event.head_commit.message }}" | sed -E 's/^chore\(release\): ([0-9]+\.[0-9]+\.[0-9]+).*/\1/') | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "Releasing version: $VERSION" | |
| - name: Validate version format | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Error: Invalid version format '$VERSION'. Expected x.y.z" | |
| exit 1 | |
| fi | |
| - name: Verify package version matches commit | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| PACKAGE_VERSION=$(node -e "const fs=require('fs');const p=JSON.parse(fs.readFileSync('package.json','utf8'));process.stdout.write(p.version)") | |
| if [[ "$PACKAGE_VERSION" != "$VERSION" ]]; then | |
| echo "Error: package.json version is '$PACKAGE_VERSION' but commit version is '$VERSION'" | |
| exit 1 | |
| fi | |
| - name: Check if version already exists on npm | |
| id: check-version | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| if npm view create-prisma@$VERSION version >/dev/null 2>&1; then | |
| echo "Version $VERSION already exists on npm" | |
| echo "exists=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Version $VERSION is new" | |
| echo "exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Ensure npm version for trusted publishing | |
| if: steps.check-version.outputs.exists == 'false' | |
| run: | | |
| npm install -g npm@11.5.1 | |
| echo "Node: $(node --version)" | |
| echo "npm: $(npm --version)" | |
| - name: Setup Bun | |
| if: steps.check-version.outputs.exists == 'false' | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| if: steps.check-version.outputs.exists == 'false' | |
| run: bun install --frozen-lockfile | |
| - name: Check | |
| if: steps.check-version.outputs.exists == 'false' | |
| run: bun run check | |
| - name: Typecheck | |
| if: steps.check-version.outputs.exists == 'false' | |
| run: bun run typecheck | |
| - name: Build | |
| if: steps.check-version.outputs.exists == 'false' | |
| run: bun run build | |
| - name: Publish to npm | |
| if: steps.check-version.outputs.exists == 'false' | |
| run: npm publish --access public | |
| - name: Create and push git tag | |
| if: steps.check-version.outputs.exists == 'false' | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| if ! git rev-parse "v$VERSION" >/dev/null 2>&1; then | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git tag -a "v$VERSION" -m "Release v$VERSION" | |
| git push origin "v$VERSION" | |
| else | |
| echo "Tag v$VERSION already exists, skipping" | |
| fi | |
| - name: Create GitHub Release | |
| if: steps.check-version.outputs.exists == 'false' | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| if ! gh release view "v$VERSION" >/dev/null 2>&1; then | |
| bunx changelogithub | |
| else | |
| echo "Release v$VERSION already exists, skipping" | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Release summary | |
| if: steps.check-version.outputs.exists == 'false' | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| echo "## Release v$VERSION complete" >> "$GITHUB_STEP_SUMMARY" | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- https://www.npmjs.com/package/create-prisma/v/$VERSION" >> "$GITHUB_STEP_SUMMARY" |