|
| 1 | +"use strict"; |
| 2 | +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { |
| 3 | + if (k2 === undefined) k2 = k; |
| 4 | + var desc = Object.getOwnPropertyDescriptor(m, k); |
| 5 | + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { |
| 6 | + desc = { enumerable: true, get: function() { return m[k]; } }; |
| 7 | + } |
| 8 | + Object.defineProperty(o, k2, desc); |
| 9 | +}) : (function(o, m, k, k2) { |
| 10 | + if (k2 === undefined) k2 = k; |
| 11 | + o[k2] = m[k]; |
| 12 | +})); |
| 13 | +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { |
| 14 | + Object.defineProperty(o, "default", { enumerable: true, value: v }); |
| 15 | +}) : function(o, v) { |
| 16 | + o["default"] = v; |
| 17 | +}); |
| 18 | +var __importStar = (this && this.__importStar) || function (mod) { |
| 19 | + if (mod && mod.__esModule) return mod; |
| 20 | + var result = {}; |
| 21 | + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); |
| 22 | + __setModuleDefault(result, mod); |
| 23 | + return result; |
| 24 | +}; |
| 25 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 26 | +const child_process_1 = require("child_process"); |
| 27 | +const core = __importStar(require("@actions/core")); |
| 28 | +function run() { |
| 29 | + var _a, _b, _c, _d; |
| 30 | + try { |
| 31 | + const subprojectPrefixes = (_b = (_a = core.getInput('project_prefixes')) === null || _a === void 0 ? void 0 : _a.split(",")) !== null && _b !== void 0 ? _b : []; |
| 32 | + const requiredProjects = (_d = (_c = core.getInput('required_projects')) === null || _c === void 0 ? void 0 : _c.split(",")) !== null && _d !== void 0 ? _d : []; |
| 33 | + core.debug("executing git fetch"); |
| 34 | + (0, child_process_1.execSync)('git fetch --unshallow', { encoding: 'utf-8' }); |
| 35 | + const githubSha = process.env.GITHUB_SHA; |
| 36 | + if (!githubSha) { |
| 37 | + core.setFailed('GITHUB_SHA not set'); |
| 38 | + } |
| 39 | + const diffCmd = `git diff --name-only HEAD~1..${githubSha}`; |
| 40 | + core.debug(`Executing: ${diffCmd}`); |
| 41 | + core.debug(`Git Status: ${(0, child_process_1.execSync)(`git status`, { encoding: 'utf-8' }).trim()}`); |
| 42 | + core.debug(`SHA Exists: ${(0, child_process_1.execSync)(`git cat-file -e ${githubSha}`, { encoding: 'utf-8' }).trim()}`); |
| 43 | + let modifiedProjects = (0, child_process_1.execSync)(diffCmd, { encoding: 'utf8' }); |
| 44 | + core.debug("Modified Projects:" + modifiedProjects); |
| 45 | + core.debug("Required Projects:" + requiredProjects); |
| 46 | + if (modifiedProjects.includes('buildSrc/') && !modifiedProjects.includes('ktor-')) { |
| 47 | + core.debug("only buildSrc has modified"); |
| 48 | + modifiedProjects = "buildSrc"; |
| 49 | + } |
| 50 | + else { |
| 51 | + const subprojectPrefixesPattern = subprojectPrefixes.join("|"); |
| 52 | + core.debug("subprojectPrefixesPattern: " + subprojectPrefixesPattern); |
| 53 | + const regex = subprojectPrefixes.length > 0 |
| 54 | + ? new RegExp(`^(${subprojectPrefixesPattern})`) |
| 55 | + : null; |
| 56 | + let modifiedProjectsArray = modifiedProjects.split('\n') |
| 57 | + .filter(line => { |
| 58 | + return regex ? regex.test(line) : true; |
| 59 | + }) |
| 60 | + .map(line => line.split('/', 1)[0]) |
| 61 | + .sort() |
| 62 | + .filter((value, index, self) => self.indexOf(value) === index); |
| 63 | + modifiedProjects = [...new Set(modifiedProjectsArray.concat(requiredProjects))].join(','); |
| 64 | + } |
| 65 | + if (modifiedProjects) { |
| 66 | + core.info(`Modified subprojects including required projects: ${modifiedProjects}`); |
| 67 | + core.setOutput('modified_projects', modifiedProjects); |
| 68 | + } |
| 69 | + else { |
| 70 | + core.info("No modified subprojects"); |
| 71 | + } |
| 72 | + } |
| 73 | + catch (error) { |
| 74 | + core.setFailed(`Action failed with error: ${error}`); |
| 75 | + } |
| 76 | +} |
| 77 | +run(); |
0 commit comments