From c94a0c2ae07849916b6dbaffa85a6c10e740c74f Mon Sep 17 00:00:00 2001 From: Luca Schneider Date: Tue, 24 Sep 2024 15:30:14 +0200 Subject: [PATCH 1/6] Change workflow to publish to vercel --- .github/workflows/docs.yml | 82 ++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index b572d80f..d3c2be59 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,4 +1,7 @@ -name: docs +name: Build and Deploy packages/docs +env: + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} on: push: @@ -9,43 +12,62 @@ on: - ".github/workflows/docs.yml" jobs: - deploy: + build-and-deploy: runs-on: ubuntu-latest - permissions: - contents: write - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} steps: - uses: actions/checkout@v3 - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: "lts/*" - uses: pnpm/action-setup@v4 name: Install pnpm with: version: 8.6.1 run_install: false - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - uses: actions/cache@v3 - name: Setup pnpm cache + - name: Install Node.js + uses: actions/setup-node@v3 with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Install - working-directory: ./packages/docs + node-version: 20 + cache: "pnpm" + - name: Install node_modules run: pnpm install - - name: Build docs - working-directory: ./packages/docs - run: pnpm build - - name: Deploy to gh-pages - uses: peaceiris/actions-gh-pages@v3 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + - name: Add wasm32-wasi target + run: rustup target add wasm32-wasi + - name: Enable caching + uses: Swatinem/rust-cache@v2 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./packages/docs/docs/dist - cname: yak.js.org + workspaces: packages/yak-swc + + - name: Build with SWC + run: pnpm run build:swc + + - name: Install Vercel CLI + run: npm install -g vercel@35 + - name: Link Vercel project + run: vercel link packages/docs --yes --token ${{ secrets.VERCEL_TOKEN }} + + # Preview deployment (for pull requests and non-main pushes) + - name: Pull Vercel environment information (Preview) + if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') + run: vercel pull --yes --environment=preview --token ${{ secrets.VERCEL_TOKEN }} + - name: Build project artifacts (Preview) + if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') + run: vercel build --token ${{ secrets.VERCEL_TOKEN }} + - name: Deploy to Vercel (Preview) + if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') + run: vercel deploy --prebuilt --token ${{ secrets.VERCEL_TOKEN }} + + # Production deployment (for main branch pushes) + - name: Pull Vercel environment information (Production) + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + run: vercel pull --yes --environment=production --token ${{ secrets.VERCEL_TOKEN }} + - name: Build project artifacts (Production) + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + run: vercel build --prod --token ${{ secrets.VERCEL_TOKEN }} + - name: Deploy to Vercel (Production) + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + run: vercel deploy --prebuilt --prod --token ${{ secrets.VERCEL_TOKEN }} From 8c5f79623e2da923485b8ccff17f68bb5f7e6061 Mon Sep 17 00:00:00 2001 From: Luca Schneider Date: Tue, 24 Sep 2024 15:36:17 +0200 Subject: [PATCH 2/6] Execute build docs on PR's --- .github/workflows/docs.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index d3c2be59..9449d46a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,6 +10,12 @@ on: paths: - "packages/docs/**" - ".github/workflows/docs.yml" + pull_request: + branches: + - main + paths: + - "packages/docs/**" + - ".github/workflows/docs.yml" jobs: build-and-deploy: From 468535c92714d1fda0336f08b0bfd05cd59bba7d Mon Sep 17 00:00:00 2001 From: Luca Schneider Date: Tue, 24 Sep 2024 15:38:31 +0200 Subject: [PATCH 3/6] Try to use cwd with vercel cli --- .github/workflows/docs.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 9449d46a..864ffdd8 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -54,18 +54,18 @@ jobs: - name: Install Vercel CLI run: npm install -g vercel@35 - name: Link Vercel project - run: vercel link packages/docs --yes --token ${{ secrets.VERCEL_TOKEN }} + run: vercel link --cwd packages/docs --yes --token ${{ secrets.VERCEL_TOKEN }} # Preview deployment (for pull requests and non-main pushes) - name: Pull Vercel environment information (Preview) if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') - run: vercel pull --yes --environment=preview --token ${{ secrets.VERCEL_TOKEN }} + run: vercel pull --cwd packages/docs --yes --environment=preview --token ${{ secrets.VERCEL_TOKEN }} - name: Build project artifacts (Preview) if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') - run: vercel build --token ${{ secrets.VERCEL_TOKEN }} + run: vercel build --cwd packages/docs --token ${{ secrets.VERCEL_TOKEN }} - name: Deploy to Vercel (Preview) if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') - run: vercel deploy --prebuilt --token ${{ secrets.VERCEL_TOKEN }} + run: vercel deploy --cwd packages/docs --prebuilt --token ${{ secrets.VERCEL_TOKEN }} # Production deployment (for main branch pushes) - name: Pull Vercel environment information (Production) From e982cfb33508970ff79e85c96851a34709860067 Mon Sep 17 00:00:00 2001 From: Luca Schneider Date: Tue, 24 Sep 2024 15:46:54 +0200 Subject: [PATCH 4/6] Use different env variable --- .github/workflows/docs.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 864ffdd8..720b2405 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,6 +1,6 @@ name: Build and Deploy packages/docs env: - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_DOCS_PROJECT_ID }} VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} on: @@ -54,18 +54,18 @@ jobs: - name: Install Vercel CLI run: npm install -g vercel@35 - name: Link Vercel project - run: vercel link --cwd packages/docs --yes --token ${{ secrets.VERCEL_TOKEN }} + run: vercel link --yes --token ${{ secrets.VERCEL_TOKEN }} # Preview deployment (for pull requests and non-main pushes) - name: Pull Vercel environment information (Preview) if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') - run: vercel pull --cwd packages/docs --yes --environment=preview --token ${{ secrets.VERCEL_TOKEN }} + run: vercel pull --yes --environment=preview --token ${{ secrets.VERCEL_TOKEN }} - name: Build project artifacts (Preview) if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') - run: vercel build --cwd packages/docs --token ${{ secrets.VERCEL_TOKEN }} + run: vercel build --token ${{ secrets.VERCEL_TOKEN }} - name: Deploy to Vercel (Preview) if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref != 'refs/heads/main') - run: vercel deploy --cwd packages/docs --prebuilt --token ${{ secrets.VERCEL_TOKEN }} + run: vercel deploy --prebuilt --token ${{ secrets.VERCEL_TOKEN }} # Production deployment (for main branch pushes) - name: Pull Vercel environment information (Production) From 25d3976ff48b3b056934ca6620aefb31bb44a4fd Mon Sep 17 00:00:00 2001 From: Luca Schneider Date: Tue, 24 Sep 2024 15:50:26 +0200 Subject: [PATCH 5/6] Add scripts in package.json for workflow --- packages/docs/package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/docs/package.json b/packages/docs/package.json index 060da56a..ce3f95f4 100644 --- a/packages/docs/package.json +++ b/packages/docs/package.json @@ -3,9 +3,13 @@ "version": "0.0.0", "private": true, "scripts": { - "build": "next build", "dev": "next dev", + "build": "pnpm run build:yak && pnpm run build:next", + "build:next": "next build", + "build:yak": "pnpm run --filter next-yak build", + "build:swc": "pnpm run --filter yak-swc build", "start": "next start", + "lint": "next lint", "postinstall": "fumadocs-mdx" }, "dependencies": { From 881a6c2d2edd122437430089abe430bf43ff91c5 Mon Sep 17 00:00:00 2001 From: Luca Schneider Date: Tue, 24 Sep 2024 16:20:13 +0200 Subject: [PATCH 6/6] See if explicit including yak-swc helps --- packages/docs/next.config.mjs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/docs/next.config.mjs b/packages/docs/next.config.mjs index 1f620ed0..10637834 100644 --- a/packages/docs/next.config.mjs +++ b/packages/docs/next.config.mjs @@ -10,7 +10,15 @@ const config = { optimizePackageImports: ["shiki", "@shikijs/monaco"], // serverComponentsExternalPackages: ["next-yak"], }, - webpack: (config) => { + transpilePackages: ["yak-swc"], + webpack: (config, { isServer, webpack }) => { + if (isServer) { + config.plugins.push( + new webpack.ProvidePlugin({ + YourDependency: "yak-swc", + }) + ); + } config.module.rules.push({ test: /\.d\.c?ts$/, resourceQuery: /raw/,