Skip to content

Commit e94e902

Browse files
feat(dx): add clone-webpack script and unify CI checkout logic (#72)
Co-authored-by: Aviv Keller <me@aviv.sh>
1 parent 348f7d0 commit e94e902

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ jobs:
3434
- name: Checkout code
3535
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3636

37-
- name: Read HEAD_COMMIT
38-
id: webpack-ref
39-
run: echo "ref=$(cat HEAD_COMMIT)" >> "$GITHUB_OUTPUT"
40-
41-
- name: Checkout webpack
42-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
43-
with:
44-
repository: webpack/webpack
45-
ref: ${{ steps.webpack-ref.outputs.ref }}
46-
path: webpack
47-
4837
- name: Setup Node.js
4938
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
5039
with:
@@ -54,6 +43,9 @@ jobs:
5443
- name: Install dependencies
5544
run: npm ci
5645

46+
- name: Clone webpack
47+
run: npm run clone-webpack
48+
5749
- name: Regenerate docs
5850
run: npm run generate-docs
5951

.github/workflows/sync.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ jobs:
3838
echo "New webpack commit detected, syncing."
3939
fi
4040
41-
- name: Checkout webpack
42-
if: steps.check.outputs.changed == 'true'
43-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
44-
with:
45-
repository: webpack/webpack
46-
ref: ${{ steps.latest.outputs.latest }}
47-
path: webpack
48-
4941
- name: Setup Node.js
5042
if: steps.check.outputs.changed == 'true'
5143
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
@@ -61,6 +53,10 @@ jobs:
6153
if: steps.check.outputs.changed == 'true'
6254
run: echo "${{ steps.latest.outputs.latest }}" > HEAD_COMMIT
6355

56+
- name: Clone webpack
57+
if: steps.check.outputs.changed == 'true'
58+
run: npm run clone-webpack
59+
6460
- name: Regenerate docs
6561
if: steps.check.outputs.changed == 'true'
6662
run: npm run generate-docs

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ This ensures documentation stays in sync with upstream webpack without manual in
3939

4040
| Script | Description |
4141
| ----------------------- | ------------------------------------ |
42+
| `npm run clone-webpack` | Clone webpack repo at pinned commit |
4243
| `npm run generate-docs` | Generate Markdown from webpack types |
4344
| `npm run build-html` | Convert Markdown to HTML |
4445
| `npm run build` | Generate docs + build HTML |

clone-webpack.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { readFile, access } from 'node:fs/promises';
2+
import { execFileSync } from 'node:child_process';
3+
4+
const WEBPACK_DIR = 'webpack';
5+
const REF = (await readFile('HEAD_COMMIT', 'utf-8')).trim();
6+
7+
try {
8+
await access(WEBPACK_DIR);
9+
execFileSync('git', ['fetch', '--all'], {
10+
cwd: WEBPACK_DIR,
11+
stdio: 'inherit',
12+
});
13+
} catch {
14+
execFileSync(
15+
'git',
16+
['clone', 'https://github.com/webpack/webpack.git', WEBPACK_DIR],
17+
{
18+
stdio: 'inherit',
19+
}
20+
);
21+
}
22+
23+
execFileSync('git', ['checkout', REF], { cwd: WEBPACK_DIR, stdio: 'inherit' });

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"scripts": {
3+
"clone-webpack": "node clone-webpack.mjs",
34
"generate-docs": "node generate-md.mjs",
45
"build-html": "doc-kit generate -t web --config-file ./doc-kit.config.mjs",
56
"build": "npm run generate-docs && npm run build-html",

0 commit comments

Comments
 (0)