Skip to content

Commit

Permalink
CIで使用しているスクリプトをTypeScript化する
Browse files Browse the repository at this point in the history
  • Loading branch information
massongit committed Oct 24, 2024
1 parent 4aaf650 commit d9ddd65
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/pr-copy-ci-sudden-death.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
57 changes: 37 additions & 20 deletions scripts/pr_copy_ci_sudden_death/pr_copy_ci/copy_package.ts
Original file line number Diff line number Diff line change
@@ -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",
);
};
}
4 changes: 4 additions & 0 deletions scripts/pr_copy_ci_sudden_death/pr_copy_ci/npm_ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

npm ci
mv node_modules/ ../

0 comments on commit d9ddd65

Please sign in to comment.