diff --git a/.github/workflows/pr-copy-ci-sudden-death.yml b/.github/workflows/pr-copy-ci-sudden-death.yml index 254483aff..5c1a5cf04 100644 --- a/.github/workflows/pr-copy-ci-sudden-death.yml +++ b/.github/workflows/pr-copy-ci-sudden-death.yml @@ -26,13 +26,25 @@ jobs: fetch-depth: 0 repository: ${{ github.repository_owner }}/hato-bot path: hato-bot + - name: Set up Node.js + uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 + with: + cache: npm + cache-dependency-path: sudden-death/package-lock.json + node-version-file: sudden-death/package.json + - run: bash "${GITHUB_WORKSPACE}/sudden-death/scripts/pr_copy_ci_sudden_death/pr_copy_ci/npm_ci.sh" + working-directory: sudden-death - name: Copy CI run: bash "${GITHUB_WORKSPACE}/sudden-death/scripts/pr_copy_ci_sudden_death/pr_copy_ci/copy_ci.sh" - name: Copy package.json uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1 with: script: | - const script = require(`${process.env.GITHUB_WORKSPACE}/sudden-death/scripts/pr_copy_ci_sudden_death/pr_copy_ci/copy_package.js`) + const {tsImport} = require('tsx/esm/api') + const {script} = await tsImport( + './scripts/pr_copy_ci_sudden_death/pr_copy_ci/copy_package.ts', + process.env.GITHUB_WORKSPACE + '/sudden-death/' + ) script() - uses: dev-hato/actions-diff-pr-management@e5c78b251a69f44f93b2f1398e06b129bcf151ec # v1.2.0 with: diff --git a/scripts/pr_copy_ci_sudden_death/pr_copy_ci/copy_package.ts b/scripts/pr_copy_ci_sudden_death/pr_copy_ci/copy_package.ts index d7eeb8b69..fb294623a 100644 --- a/scripts/pr_copy_ci_sudden_death/pr_copy_ci/copy_package.ts +++ b/scripts/pr_copy_ci_sudden_death/pr_copy_ci/copy_package.ts @@ -1,39 +1,56 @@ -const fs = require("fs"); -const hatoBotPackage = require( - `${process.env.GITHUB_WORKSPACE}/hato-bot/package.json`, -); -const hatoBotPackageLock = require( - `${process.env.GITHUB_WORKSPACE}/hato-bot/package-lock.json`, -); -const suddenDeathPackage = require( - `${process.env.GITHUB_WORKSPACE}/sudden-death/package.json`, -); -const suddenDeathPackageLock = require( - `${process.env.GITHUB_WORKSPACE}/sudden-death/package-lock.json`, -); - -module.exports = () => { +import {readFileSync,writeFileSync} from "fs"; + +export function script() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const hatoBotPackage: { [key: string]: any } = JSON.parse( + readFileSync( + `${process.env.GITHUB_WORKSPACE}/hato-bot/package.json`, + ).toString(), + ); + + const suddenDeathPackagePath = `${process.env.GITHUB_WORKSPACE}/sudden-death/package.json`; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const suddenDeathPackage: { [key: string]: any } = JSON.parse( + readFileSync(suddenDeathPackagePath).toString(), + ); + delete hatoBotPackage.scripts; for (const packageKey of Object.keys(hatoBotPackage)) { suddenDeathPackage[packageKey] = hatoBotPackage[packageKey]; } - fs.writeFileSync( - `${process.env.GITHUB_WORKSPACE}/sudden-death/package.json`, + writeFileSync( + suddenDeathPackagePath, JSON.stringify(suddenDeathPackage, null, " ") + "\n", "utf8", ); + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const hatoBotPackageLock: { [key: string]: any } = JSON.parse( + readFileSync( + `${process.env.GITHUB_WORKSPACE}/hato-bot/package-lock.json`, + ).toString(), + ); + + const suddenDeathPackageLockPath = `${process.env.GITHUB_WORKSPACE}/sudden-death/package-lock.json`; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const suddenDeathPackageLock: { [key: string]: any } = JSON.parse( + readFileSync(suddenDeathPackageLockPath).toString(), + ); + delete hatoBotPackageLock.name; for (const packageLockKey of Object.keys(hatoBotPackageLock)) { suddenDeathPackageLock[packageLockKey] = hatoBotPackageLock[packageLockKey]; } - fs.writeFileSync( - `${process.env.GITHUB_WORKSPACE}/sudden-death/package-lock.json`, + writeFileSync( + suddenDeathPackageLockPath, JSON.stringify(suddenDeathPackageLock, null, " ") + "\n", "utf8", ); -}; +} diff --git a/scripts/pr_copy_ci_sudden_death/pr_copy_ci/npm_ci.sh b/scripts/pr_copy_ci_sudden_death/pr_copy_ci/npm_ci.sh new file mode 100755 index 000000000..5f1bdbbd7 --- /dev/null +++ b/scripts/pr_copy_ci_sudden_death/pr_copy_ci/npm_ci.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +npm ci +mv node_modules/ ../