๐Ÿ“ฆ cloudflare / vinext

๐Ÿ“„ ecosystem-run.yml ยท 161 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161name: Ecosystem Run

on:
  workflow_call:
    inputs:
      repo_url:
        required: true
        type: string
      next_version:
        required: true
        type: string
      node_version:
        required: false
        type: string
        default: "24"

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout vinext
        uses: actions/checkout@v4

      - name: Setup pnpm
        uses: pnpm/action-setup@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ inputs.node_version }}
          cache: pnpm

      - name: Build vinext
        run: |
          pnpm install --frozen-lockfile
          pnpm run build

      - name: Read vinext versions
        id: versions
        run: |
          node - <<'NODE'
          const fs = require('fs');
          const path = require('path');
          const pkg = require('./packages/vinext/package.json');
          const clean = (value) => value.replace(/^[^0-9]*/, '');
          const react = clean(pkg.peerDependencies.react);
          const reactDom = clean(pkg.peerDependencies['react-dom']);
          const vite = clean(pkg.peerDependencies.vite);
          const rsc = clean(pkg.dependencies['@vitejs/plugin-rsc']);
          const lines = [
            `react=${react}`,
            `react_dom=${reactDom}`,
            `vite=${vite}`,
            `rsc=${rsc}`,
          ].join('\n');
          fs.appendFileSync(process.env.GITHUB_OUTPUT, `${lines}\n`);
          NODE

      - name: Validate repo URL
        env:
          REPO_URL: ${{ inputs.repo_url }}
        run: |
          node - <<'NODE'
          const fs = require('fs');

          const input = process.env.REPO_URL;
          const allowed = JSON.parse(fs.readFileSync('.github/repos.json', 'utf8'))
            .map((repo) => repo.url);

          if (!allowed.includes(input)) {
            console.error(`repo_url not in allowlist: ${input}`);
            process.exit(1);
          }
          NODE

      - name: Clone target repo
        env:
          REPO_URL: ${{ inputs.repo_url }}
        run: git clone --depth 1 -- "$REPO_URL" target-repo

      - name: Install dependencies
        working-directory: target-repo
        run: npm install --legacy-peer-deps

      - name: Pin Next.js and React versions
        working-directory: target-repo
        env:
          NEXT_VERSION: ${{ inputs.next_version }}
          REACT_VERSION: ${{ steps.versions.outputs.react }}
          REACT_DOM_VERSION: ${{ steps.versions.outputs.react_dom }}
        run: npm install --legacy-peer-deps "next@$NEXT_VERSION" "react@$REACT_VERSION" "react-dom@$REACT_DOM_VERSION"

      - name: Install vinext
        working-directory: target-repo
        env:
          VINEXT_PKG: ${{ github.workspace }}/packages/vinext
          VITE_VERSION: ${{ steps.versions.outputs.vite }}
          RSC_VERSION: ${{ steps.versions.outputs.rsc }}
        run: npm install --legacy-peer-deps "$VINEXT_PKG" "vite@$VITE_VERSION" "@vitejs/plugin-rsc@$RSC_VERSION"

      - name: Build with vinext
        working-directory: target-repo
        run: ./node_modules/.bin/vinext build

      - name: Verify build output
        working-directory: target-repo
        run: |
          node - <<'NODE'
          const fs = require('fs');
          const path = require('path');

          const ensureNonEmptyDir = (dir) => {
            if (!fs.existsSync(dir)) {
              console.error(`missing ${dir}`);
              process.exit(1);
            }
            const entries = fs.readdirSync(dir);
            if (entries.length === 0) {
              console.error(`empty ${dir}`);
              process.exit(1);
            }
          };

          const clientDir = 'dist/client';
          ensureNonEmptyDir(clientDir);

          const hasJs = (dir) => {
            const entries = fs.readdirSync(dir, { withFileTypes: true });
            for (const entry of entries) {
              const entryPath = path.join(dir, entry.name);
              if (entry.isDirectory()) {
                if (hasJs(entryPath)) {
                  return true;
                }
                continue;
              }
              if (entry.name.endsWith('.js') || entry.name.endsWith('.mjs')) {
                return true;
              }
            }
            return false;
          };

          if (!hasJs(clientDir)) {
            console.error(`no js artifacts in ${clientDir}`);
            process.exit(1);
          }

          const serverDir = 'dist/server';
          ensureNonEmptyDir(serverDir);

          if (!hasJs(serverDir)) {
            console.error(`no js artifacts in ${serverDir}`);
            process.exit(1);
          }
          NODE