From 979a47bf857607109e8015aed2459d8b9b797ba8 Mon Sep 17 00:00:00 2001 From: Sarvesh Chitkeshiwar <94628430+Sarveshpc@users.noreply.github.com> Date: Thu, 28 Mar 2024 23:19:58 +0530 Subject: [PATCH] Add files via upload --- code-check.yml | 116 +++++++++++++++++++++++++++++++++++++++++ issue-stale.yml | 26 +++++++++ prerelease-comment.yml | 65 +++++++++++++++++++++++ prerelease.yml | 60 +++++++++++++++++++++ release.yml | 53 +++++++++++++++++++ test.yml | 42 +++++++++++++++ 6 files changed, 362 insertions(+) create mode 100644 code-check.yml create mode 100644 issue-stale.yml create mode 100644 prerelease-comment.yml create mode 100644 prerelease.yml create mode 100644 release.yml create mode 100644 test.yml diff --git a/code-check.yml b/code-check.yml new file mode 100644 index 0000000..d40e830 --- /dev/null +++ b/code-check.yml @@ -0,0 +1,116 @@ +name: Code check + +on: + pull_request: + branches: ["*"] + +jobs: + lint: + runs-on: ubuntu-latest + name: pnpm lint + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2.2.4 + name: Install pnpm + id: pnpm-install + with: + version: 8.6.1 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + run: | + echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + run: pnpm install + + - run: pnpm lint + + format: + runs-on: ubuntu-latest + name: pnpm format:check + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2.2.4 + name: Install pnpm + id: pnpm-install + with: + version: 8.6.1 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + run: | + echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm install + + - run: pnpm format:check + + tsc: + runs-on: ubuntu-latest + name: pnpm typecheck + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2.2.4 + name: Install pnpm + id: pnpm-install + with: + version: 8.6.1 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + run: | + echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + run: pnpm install + + - run: pnpm typecheck diff --git a/issue-stale.yml b/issue-stale.yml new file mode 100644 index 0000000..e34856d --- /dev/null +++ b/issue-stale.yml @@ -0,0 +1,26 @@ +# Adapted from vercel/next.js +name: Issue Stale +on: + workflow_dispatch: + schedule: + # This runs every day 20 minutes before midnight: https://crontab.guru/#40_23_*_*_* + - cron: "40 23 * * *" + +jobs: + stale: + runs-on: ubuntu-latest + if: github.repository_owner == 'shadcn-ui' + steps: + - uses: actions/stale@v4 + id: stale-no-repro + name: "Close stale issues with no reproduction" + with: + repo-token: ${{ secrets.STALE_TOKEN }} + close-issue-message: "This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you." + days-before-issue-close: 7 + days-before-issue-stale: 15 + stale-pr-label: "stale?" + days-before-pr-close: -1 + days-before-pr-stale: -1 + exempt-issue-labels: "roadmap,next,bug" + operations-per-run: 300 # 1 operation per 100 issues, the rest is to label/comment/close diff --git a/prerelease-comment.yml b/prerelease-comment.yml new file mode 100644 index 0000000..ad21a54 --- /dev/null +++ b/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-ui' && + ${{ 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 prerelease is available for testing: + + ```sh + npx 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/prerelease.yml b/prerelease.yml new file mode 100644 index 0000000..ea41485 --- /dev/null +++ b/prerelease.yml @@ -0,0 +1,60 @@ +# Adapted from create-t3-app. + +name: Release - Beta + +on: + pull_request: + types: [labeled] + branches: + - main +jobs: + prerelease: + if: | + github.repository_owner == 'shadcn-ui' && + contains(github.event.pull_request.labels.*.name, '🚀 autorelease') + name: Build & Publish a beta release to NPM + runs-on: ubuntu-latest + environment: Preview + + steps: + - name: Checkout Repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Use PNPM + uses: pnpm/action-setup@v2.2.4 + with: + version: 8.6.1 + + - 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=$NPM_ACCESS_TOKEN" >> packages/cli/.npmrc + env: + NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} + + - name: Publish Beta to NPM + run: pnpm pub:beta + + - 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/release.yml b/release.yml new file mode 100644 index 0000000..7ec4840 --- /dev/null +++ b/release.yml @@ -0,0 +1,53 @@ +# Adapted from create-t3-app. + +name: Release + +on: + push: + branches: + - main + +jobs: + release: + if: ${{ github.repository_owner == 'shadcn-ui' }} + 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 + with: + version: 8.6.1 + + - name: Use Node.js 18 + uses: actions/setup-node@v3 + with: + version: 8.6.1 + 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" diff --git a/test.yml b/test.yml new file mode 100644 index 0000000..c350ce1 --- /dev/null +++ b/test.yml @@ -0,0 +1,42 @@ +name: Test + +on: + pull_request: + branches: ["*"] + +jobs: + test: + runs-on: ubuntu-latest + name: pnpm test + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - uses: pnpm/action-setup@v2.2.4 + name: Install pnpm + id: pnpm-install + with: + version: 8.6.1 + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + run: | + echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies + run: pnpm install + + - run: pnpm test