diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ed7075..57aff09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,17 +34,6 @@ jobs: - name: Checkout code uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Read HEAD_COMMIT - id: webpack-ref - run: echo "ref=$(cat HEAD_COMMIT)" >> "$GITHUB_OUTPUT" - - - name: Checkout webpack - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - with: - repository: webpack/webpack - ref: ${{ steps.webpack-ref.outputs.ref }} - path: webpack - - name: Setup Node.js uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 with: @@ -54,6 +43,9 @@ jobs: - name: Install dependencies run: npm ci + - name: Clone webpack + run: npm run clone-webpack + - name: Regenerate docs run: npm run generate-docs diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 29eaef8..40ff5da 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -38,14 +38,6 @@ jobs: echo "New webpack commit detected, syncing." fi - - name: Checkout webpack - if: steps.check.outputs.changed == 'true' - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - with: - repository: webpack/webpack - ref: ${{ steps.latest.outputs.latest }} - path: webpack - - name: Setup Node.js if: steps.check.outputs.changed == 'true' uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 @@ -61,6 +53,10 @@ jobs: if: steps.check.outputs.changed == 'true' run: echo "${{ steps.latest.outputs.latest }}" > HEAD_COMMIT + - name: Clone webpack + if: steps.check.outputs.changed == 'true' + run: npm run clone-webpack + - name: Regenerate docs if: steps.check.outputs.changed == 'true' run: npm run generate-docs diff --git a/README.md b/README.md index 24dfb85..1a3a112 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ This ensures documentation stays in sync with upstream webpack without manual in | Script | Description | | ----------------------- | ------------------------------------ | +| `npm run clone-webpack` | Clone webpack repo at pinned commit | | `npm run generate-docs` | Generate Markdown from webpack types | | `npm run build-html` | Convert Markdown to HTML | | `npm run build` | Generate docs + build HTML | diff --git a/clone-webpack.mjs b/clone-webpack.mjs new file mode 100644 index 0000000..578a460 --- /dev/null +++ b/clone-webpack.mjs @@ -0,0 +1,23 @@ +import { readFile, access } from 'node:fs/promises'; +import { execFileSync } from 'node:child_process'; + +const WEBPACK_DIR = 'webpack'; +const REF = (await readFile('HEAD_COMMIT', 'utf-8')).trim(); + +try { + await access(WEBPACK_DIR); + execFileSync('git', ['fetch', '--all'], { + cwd: WEBPACK_DIR, + stdio: 'inherit', + }); +} catch { + execFileSync( + 'git', + ['clone', 'https://github.com/webpack/webpack.git', WEBPACK_DIR], + { + stdio: 'inherit', + } + ); +} + +execFileSync('git', ['checkout', REF], { cwd: WEBPACK_DIR, stdio: 'inherit' }); diff --git a/package.json b/package.json index 029a5c9..b8562d8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "scripts": { + "clone-webpack": "node clone-webpack.mjs", "generate-docs": "node generate-md.mjs", "build-html": "doc-kit generate -t web --config-file ./doc-kit.config.mjs", "build": "npm run generate-docs && npm run build-html",