|
| 1 | +import { exec } from "node:child_process"; |
| 2 | +import { |
| 3 | + existsSync, |
| 4 | + readFileSync, |
| 5 | + mkdirSync, |
| 6 | + rmSync, |
| 7 | + cpSync, |
| 8 | +} from "node:fs"; |
| 9 | +import { dirname, resolve } from "node:path"; |
| 10 | +import { exit } from "node:process"; |
| 11 | +import { fileURLToPath } from "node:url"; |
| 12 | +import { promisify } from "node:util"; |
| 13 | +import { parse } from "yaml"; |
| 14 | + |
| 15 | +const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 16 | + |
| 17 | +const configFilename = ".local-config"; |
| 18 | +const configFilePath = resolve(__dirname, configFilename); |
| 19 | + |
| 20 | +if (!existsSync(configFilePath)) { |
| 21 | + console.error(".local-config does not exist; create it with `yarn setup repo <path>`"); |
| 22 | + exit(1); |
| 23 | +} |
| 24 | + |
| 25 | +const config = parse(readFileSync(configFilePath, "utf8")); |
| 26 | + |
| 27 | +const agentforceMessagingRepoPath = config.agentforceMessaging?.repository; |
| 28 | +const resolvedRepoPath = agentforceMessagingRepoPath && resolve(__dirname, agentforceMessagingRepoPath); |
| 29 | +const resolvedPackageJsonPath = resolvedRepoPath && resolve(resolvedRepoPath, "package.json"); |
| 30 | + |
| 31 | +if (!resolvedRepoPath || !existsSync(resolvedPackageJsonPath)) { |
| 32 | + console.error( |
| 33 | + "A valid path to the agentforce-messaging repository was not specified in .local-config" |
| 34 | + ); |
| 35 | + exit(1); |
| 36 | +} |
| 37 | + |
| 38 | +const packageJson = JSON.parse(readFileSync(resolvedPackageJsonPath, "utf8")); |
| 39 | +const currentVersion = packageJson.version; |
| 40 | +const currentMajorMinorVersion = currentVersion.replace(/^(\d+\.\d+)\.\d+.*$/, "$1"); |
| 41 | +const versionIsValid = /^\d+\.\d+$/.test(currentMajorMinorVersion); |
| 42 | + |
| 43 | +if (!versionIsValid) { |
| 44 | + console.error(`agentforce-messaging version string "${currentVersion}" is not compatible with this tool; must be "x.x.x" or "x.x.x-tag"`); |
| 45 | + exit(1); |
| 46 | +} |
| 47 | + |
| 48 | +console.log(`Current agentforce-messaging version is ${currentMajorMinorVersion}`); |
| 49 | + |
| 50 | +const distDir = resolve(resolvedRepoPath, "dist/"); |
| 51 | +if (!existsSync(distDir)) { |
| 52 | + console.error("agentforce-messaging has not been built"); |
| 53 | + exit(1); |
| 54 | +} |
| 55 | + |
| 56 | +const releasesDir = resolve(__dirname, "builds/ngc"); |
| 57 | +const releaseDir = resolve(releasesDir, currentMajorMinorVersion); |
| 58 | +if (!existsSync(releaseDir)) { |
| 59 | + console.log(`Version ${currentMajorMinorVersion} not found in this repo; adding it now`); |
| 60 | +} else { |
| 61 | + console.log(`Overwriting existing ${currentMajorMinorVersion} release`); |
| 62 | + rmSync(releaseDir, { recursive: true }); |
| 63 | +} |
| 64 | +mkdirSync(releaseDir); |
| 65 | + |
| 66 | +console.log(`Copying version ${currentMajorMinorVersion} from agentforce-messaging`); |
| 67 | +cpSync(distDir, releaseDir, { recursive: true }); |
| 68 | +console.log(`Copying finished! Staging files for Git commit`); |
| 69 | +await promisify(exec)(`git add builds/ngc/${currentMajorMinorVersion}/*`); |
| 70 | +console.log(`Committing changes`); |
| 71 | +await promisify(exec)(`git commit -m "feat: auto-commit of agentforce-messaging v${currentVersion}`); |
| 72 | +console.log(`Commit completed. Be sure to push your changes and open a PR!`); |
0 commit comments