diff --git a/.github/changeset-version.js b/.github/changeset-version.js new file mode 100644 index 00000000000..e1b4cef66f0 --- /dev/null +++ b/.github/changeset-version.js @@ -0,0 +1,12 @@ +// ORIGINALLY FROM CLOUDFLARE WRANGLER: +// https://github.com/cloudflare/wrangler2/blob/main/.github/changeset-version.js + +import { exec } from "child_process" + +// This script is used by the `release.yml` workflow to update the version of the packages being released. +// The standard step is only to run `changeset version` but this does not update the package-lock.json file. +// So we also run `npm install`, which does this update. +// This is a workaround until this is handled automatically by `changeset version`. +// See https://github.com/changesets/changesets/issues/421. +exec("npx changeset version") +exec("npm install") diff --git a/.github/version-script-beta.js b/.github/version-script-beta.js new file mode 100644 index 00000000000..a1b060bd862 --- /dev/null +++ b/.github/version-script-beta.js @@ -0,0 +1,21 @@ +// ORIGINALLY FROM CLOUDFLARE WRANGLER: +// https://github.com/cloudflare/wrangler2/blob/main/.github/version-script.js + +import { exec } from "child_process" +import fs from "fs" + +const pkgJsonPath = "cli/package.json" +try { + const pkg = JSON.parse(fs.readFileSync(pkgJsonPath)) + exec("git rev-parse --short HEAD", (err, stdout) => { + if (err) { + console.log(err) + process.exit(1) + } + pkg.version = "0.0.0-beta." + stdout.trim() + fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, "\t") + "\n") + }) +} catch (error) { + console.error(error) + process.exit(1) +} diff --git a/.github/version-script-next.js b/.github/version-script-next.js new file mode 100644 index 00000000000..9a1a6169577 --- /dev/null +++ b/.github/version-script-next.js @@ -0,0 +1,21 @@ +// ORIGINALLY FROM CLOUDFLARE WRANGLER: +// https://github.com/cloudflare/wrangler2/blob/main/.github/version-script.js + +import { exec } from "child_process" +import fs from "fs" + +const pkgJsonPath = "cli/package.json" +try { + const pkg = JSON.parse(fs.readFileSync(pkgJsonPath)) + exec("git rev-parse --short HEAD", (err, stdout) => { + if (err) { + console.log(err) + process.exit(1) + } + pkg.version = "0.0.0-next." + stdout.trim() + fs.writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, "\t") + "\n") + }) +} catch (error) { + console.error(error) + process.exit(1) +} diff --git a/.github/workflows/prerelease-comment.yml b/.github/workflows/prerelease-comment.yml new file mode 100644 index 00000000000..7a25514368b --- /dev/null +++ b/.github/workflows/prerelease-comment.yml @@ -0,0 +1,65 @@ +# Adapted from create-t3-app. +name: Write Beta Release comment + +on: + workflow_run: + workflows: ["Release - Beta"] + types: + - completed + +jobs: + comment: + if: | + github.repository_owner == 'shadcn' && + ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + name: Write comment to the PR + steps: + - name: "Comment on PR" + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + + for (const artifact of allArtifacts.data.artifacts) { + // Extract the PR number and package version from the artifact name + const match = /^npm-package-\@shadcn\/ui@(.*?)-pr-(\d+)/.exec(artifact.name); + + if (match) { + require("fs").appendFileSync( + process.env.GITHUB_ENV, + `\nBETA_PACKAGE_VERSION=${match[1]}` + + `\nWORKFLOW_RUN_PR=${match[2]}` + + `\nWORKFLOW_RUN_ID=${context.payload.workflow_run.id}` + ); + break; + } + } + + - name: "Comment on PR with Link" + uses: marocchino/sticky-pull-request-comment@v2 + with: + number: ${{ env.WORKFLOW_RUN_PR }} + message: | + A new @shadcn/ui prerelease is available for testing. You can install this latest build in your project with: + + ```sh + pnpm @shadcn/ui@${{ env.BETA_PACKAGE_VERSION }} + ``` + + - name: "Remove the autorelease label once published" + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{ env.WORKFLOW_RUN_PR }}, + name: '🚀 autorelease', + }); diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml new file mode 100644 index 00000000000..497c1eeb6a9 --- /dev/null +++ b/.github/workflows/prerelease.yml @@ -0,0 +1,57 @@ +# Adapted from create-t3-app. + +name: Release - Beta + +on: + pull_request: + types: [labeled] + branches: + - main +jobs: + prerelease: + if: | + github.repository_owner == 'shadcn' && + contains(github.event.pull_request.labels.*.name, '🚀 autorelease') + name: Build & Publish a beta release to NPM + runs-on: ubuntu-latest + + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Use PNPM + uses: pnpm/action-setup@v2.2.4 + + - name: Use Node.js 18 + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: "pnpm" + + - name: Install NPM Dependencies + run: pnpm install + + - name: Modify package.json version + run: node .github/version-script-beta.js + + - name: Authenticate to NPM + run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_ACCESS_TOKEN }}" > packages/cli/.npmrc + + - name: Publish Beta to NPM + run: pnpm pub:beta + env: + NPM_PUBLISH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} + + - name: get-npm-version + id: package-version + uses: martinbeentjes/npm-get-version-action@main + with: + path: packages/cli + + - name: Upload packaged artifact + uses: actions/upload-artifact@v2 + with: + name: npm-package-@shadcn\/ui@${{ steps.package-version.outputs.current-version }}-pr-${{ github.event.number }} # encode the PR number into the artifact name + path: packages/cli/dist/index.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000000..8571bb3084a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,50 @@ +# Adapted from create-t3-app. + +name: Release + +on: + push: + branches: + - main + +jobs: + release: + if: ${{ github.repository_owner == 'shadcn' }} + name: Create a PR for release workflow + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Use PNPM + uses: pnpm/action-setup@v2.2.4 + + - name: Use Node.js 18 + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: "pnpm" + + - name: Install NPM Dependencies + run: pnpm install + + - name: Check for errors + run: pnpm check + + - name: Build the package + run: pnpm build:cli + + - name: Create Version PR or Publish to NPM + id: changesets + uses: changesets/action@v1.4.1 + with: + commit: "chore(release): version packages" + title: "chore(release): version packages" + version: node .github/changeset-version.js + publish: npx changeset publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} + NODE_ENV: "production"