From 60a3b47262a1ced9a1170271ddfcba22603f841d Mon Sep 17 00:00:00 2001 From: fraxy-v <65565042+fraxy-v@users.noreply.github.com> Date: Sun, 1 Sep 2024 11:20:18 +0300 Subject: [PATCH] Update c-cpp.yml --- .github/workflows/c-cpp.yml | 48 +++---------------------------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 2e53855..b9e8270 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -31,7 +31,7 @@ jobs: with: script: | const diff = require('./scripts/diff.js'); - console.log(diff()) + return diff(); - name: Get affected targets id: find-targets @@ -39,51 +39,9 @@ jobs: with: result-encoding: string script: | - const fs = require('fs'); - const { execSync } = require('child_process'); - - let sources = execSync(`git diff --name-only origin/master`).toString().split('\n') - let outputs = []; - let commands = JSON.parse(fs.readFileSync('build/compile_commands.json', 'utf8')); - for (let src of sources) { - if (src.endsWith('.cpp') || src.endsWith('.h') || src.endsWith('.c') - || src.endsWith('.hpp')) { - const idx = commands.findIndex(entry => entry.file.endsWith(src)); - if (idx >= 0) { - let entry = commands[idx]; - if (entry.output !== 'undefined') { - entry.output = entry.command.split(' ').find(token => token.endsWith('.o')); - } - outputs.push(entry.output); - commands.splice(idx, 1); - } - } - } - - targets = new Set(); - while (outputs.length > 0) { - level_targets = new Set(); - for (const output of outputs) { - let lines = execSync(`ninja -C build -t query ${output}`).toString().split('\n'); + const targets = require('./scripts/targets.js'); + return targets('${{steps.get-modified-source.outputs.result}} '); - let insert = false; - for (const line of lines) { - if (line.endsWith('outputs:')) { - insert = true; - continue; - } - const value = line.trim(); - if (insert && value.length > 0) { - level_targets.add(value); - } - } - } - - outputs = [...level_targets]; - targets = new Set([...targets, ...level_targets]); - } - return [...targets].join(' '); - - name: Build affected targets if: ${{steps.find-targets.outputs.result != ''}} run: ninja -C build ${{steps.find-targets.outputs.result}}