Copilot commented on code in PR #6860: URL: https://github.com/apache/incubator-kie/pull/6860#discussion_r3892888097
########## .github/workflows/ci-parallel.yaml: ########## @@ -0,0 +1,178 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +name: 'CI :: Build - Parallel' + +on: + pull_request: + types: [opened, synchronize, reopened, closed, labeled] + branches: [main] + paths-ignore: + - 'LICENSE' + - '**/.gitignore' + - '**.md' + - '**.adoc' + - '*.txt' + - 'docsimg/**' + - '.ci/jenkins/**' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + + # Compute build scopes and partition affected modules. + # Uploads per-partition files as artifact and outputs a JSON array of + # partition names that have affected modules. + compute-partitions: + if: >- + github.event.action != 'closed' + && github.event_name == 'pull_request' + && contains(github.event.pull_request.labels.*.name, 'parallel ci') + runs-on: ubuntu-latest + outputs: + partitions: ${{ steps.partitions.outputs.partitions }} + steps: + - name: "SETUP :: Checkout to load local actions" + uses: actions/checkout@v7 + + - uses: ./.github/actions/ci-setup + with: + ref: ${{ github.base_ref }} + java-version: 17 + partitions-dir: .github/supporting-files/ci/partitions + + - id: partitions + name: "SETUP :: Build partition matrix" + shell: bash + run: | + json='[' + first=true + for f in "${{ runner.temp }}"/maven-pl-affected-partition*.txt "${{ runner.temp }}"/maven-pl-affected-default.txt; do + [ ! -s "$f" ] && continue + name=$(basename "$f" .txt | sed 's/^maven-pl-affected-//') + $first || json+=',' + first=false + json+="\"$name\"" + done + json+=']' + echo "partitions=$json" >> "$GITHUB_OUTPUT" + echo "Partitions with affected modules: $json" + + - uses: actions/upload-artifact@v7 + with: + name: partition-files + path: | + ${{ runner.temp }}/maven-pl-affected-partition*.txt + ${{ runner.temp }}/maven-pl-affected-default.txt + ${{ runner.temp }}/maven-pl-upstream-partition*.txt + ${{ runner.temp }}/maven-pl-upstream-default.txt + ${{ runner.temp }}/maven-pl-image-producers-partition*.txt + ${{ runner.temp }}/maven-pl-image-producers-default.txt + + # Each partition runs as an independent job via the dynamic matrix. + # GHA computes the cross-product of partition × java × os. + test: + needs: compute-partitions + if: needs.compute-partitions.outputs.partitions != '[]' + name: '${{ matrix.partition }} :: ${{ matrix.os }}, Java ${{ matrix.java }}' + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + partition: ${{ fromJSON(needs.compute-partitions.outputs.partitions) }} + java: [17, 21] + os: [ubuntu-latest] + steps: + - name: "SETUP :: Checkout to load local actions" + uses: actions/checkout@v7 + + - uses: ./.github/actions/ci-setup + with: + ref: ${{ github.base_ref }} + java-version: ${{ matrix.java }} + skip-build-scopes: true + + - uses: actions/download-artifact@v7 + with: + name: partition-files + path: ${{ runner.temp }} + + # Flag glossary: + # --no-transfer-progress silence download progress bars (critical for 800+ modules) + # -fae / --fail-at-end continue past failures so all broken modules are reported + # -Dsurefire.redirectTestOutputToFile=true redirect test JVM stdout/stderr to surefire-reports files + # -Denforcer.skip=true skip Enforcer plugin + # -Dcheckstyle.skip=true skip Checkstyle plugin + # -Dformatter.skip=true skip formatter plugin + # -Darchunit.skip=true skip ArchUnit plugin + # -Dquarkus.build.skip=true skip Quarkus application build + # -Ddisable.quarkus.plugin=true skip compile-time Quarkus bootstrap + # -Dskip.quarkus.image.assembly=true skip assemblies that package target/quarkus-app + + - name: "PR CHECK :: BUILD :: Upstream modules (tests skipped)" + shell: bash + run: | + pl=$(paste -sd, "${{ runner.temp }}/maven-pl-upstream-${{ matrix.partition }}.txt") + [ -z "$pl" ] && echo "No upstream modules. Skipping." && exit 0 + mvn -T 1C --batch-mode --no-transfer-progress -fae -DskipTests -DskipITs -Dquarkus.build.skip=true -Ddisable.quarkus.plugin=true -Dskip.quarkus.image.assembly=true -Denforcer.skip=true -Dcheckstyle.skip=true -Dformatter.skip=true -Darchunit.skip=true -Dsurefire.redirectTestOutputToFile=true -pl "$pl" install + + - name: "PR CHECK :: BUILD :: Required image-producing modules" + shell: bash + run: | + pl=$(paste -sd, "${{ runner.temp }}/maven-pl-image-producers-${{ matrix.partition }}.txt") + [ -z "$pl" ] && echo "No required image-producing modules. Skipping." && exit 0 + mvn -T 1C --batch-mode --no-transfer-progress -fae -DskipTests -DskipITs -Denforcer.skip=true -Dcheckstyle.skip=true -Dformatter.skip=true -Darchunit.skip=true -Dsurefire.redirectTestOutputToFile=true -pl "$pl" install + + - name: "PR CHECK :: TEST :: ${{ matrix.partition }}" + shell: bash + run: | + pl=$(paste -sd, "${{ runner.temp }}/maven-pl-affected-${{ matrix.partition }}.txt") + [ -z "$pl" ] && echo "No affected modules. Skipping." && exit 0 + mvn --batch-mode --no-transfer-progress -fae -Dsurefire.redirectTestOutputToFile=true -Dfull -Dreproducible -pl "$pl" install + + - name: 'SUMMARY :: Publish' + if: always() + shell: bash + env: + MERMAID_EXPANDED: ${{ matrix.java == 21 }} + MATRIX_OS: ${{ matrix.os }} + MATRIX_JAVA: ${{ matrix.java }} + run: | + MAVEN_PL_AFFECTED=$(paste -sd, "$MAVEN_PL_AFFECTED_FILE" 2>/dev/null || true) \ + MAVEN_PL_UPSTREAM=$(paste -sd, "$MAVEN_PL_UPSTREAM_FILE" 2>/dev/null || true) \ + MAVEN_PL_CHANGED=$(paste -sd, "$MAVEN_PL_CHANGED_FILE" 2>/dev/null || true) \ Review Comment: These variables read the unpartitioned placeholder files created by `ci-setup`, which remain empty because this job skips scope computation. The downloaded partition files use suffixed names, and the dependency graph is not included in the artifact either. As a result, every partition summary omits its build scope and presents a full-build reproduction command instead of the commands for the modules this job actually tested. Upload/download the graph and point the summary at `maven-pl-{affected,upstream}-${{ matrix.partition }}.txt` (and provide an appropriately partitioned changed set). ########## .github/workflows/ci-parallel.yaml: ########## @@ -0,0 +1,178 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +name: 'CI :: Build - Parallel' + +on: + pull_request: + types: [opened, synchronize, reopened, closed, labeled] Review Comment: Label-based routing is incomplete. This workflow listens for `labeled` but not `unlabeled`, while `ci.yaml` listens for neither. Removing `parallel ci` therefore does not start the standard build, and adding it after a standard build has started does not trigger a standard-workflow run that can cancel that build, so the transition can leave either no replacement CI run or both builds running. Subscribe both workflows to `labeled` and `unlabeled`; their existing job conditions can then route each event and concurrency can cancel the superseded run. ########## script/ci/CiComputeBuildScopes.java: ########## @@ -241,6 +277,104 @@ private static void writeLines(Path out, Collection<String> lines) throws IOExce Files.write(out, sorted); } + private static Set<String> imageProducersIn(Set<String> modules, Set<String> imageProducers) { + Set<String> result = new LinkedHashSet<>(modules); + result.retainAll(imageProducers); + return result; + } + + static class Partition { + final String name; + final Set<String> entries; + Set<String> closure = Set.of(); + Set<String> assigned = new LinkedHashSet<>(); + Set<String> upstream = new LinkedHashSet<>(); + Partition(String name, Set<String> entries) { + this.name = name; + this.entries = entries; + } + } + + static List<Partition> readPartitionFiles(Path partitionsDir, Map<Path, String> dirToGa, Path cwd) throws IOException { + List<Path> files; + try (Stream<Path> s = Files.list(partitionsDir)) { + files = s.filter(f -> f.getFileName().toString().startsWith("partition") && f.getFileName().toString().endsWith(".txt")) + .sorted() + .collect(Collectors.toList()); + } + List<Partition> result = new ArrayList<>(); + for (Path file : files) { + String partName = file.getFileName().toString().replaceFirst("\\.txt$", ""); + result.add(new Partition(partName, readModuleFile(file, dirToGa, cwd, partName))); + } + return result; + } + + static Set<String> readModuleFile(Path file, Map<Path, String> dirToGa, Path cwd, String listName) throws IOException { + Set<String> modules = new LinkedHashSet<>(); + for (String line : Files.readAllLines(file)) { + String trimmed = line.trim(); + if (trimmed.isEmpty() || trimmed.startsWith("#")) continue; + Path modDir = cwd.resolve(trimmed).toAbsolutePath().normalize(); + String ga = dirToGa.get(modDir); + if (ga == null) { + System.err.println("ERROR: " + listName + ": '" + trimmed + "' does not resolve to a reactor module"); + System.exit(1); + } + modules.add(ga); + } + return modules; + } + + private static void computePartitionClosures(List<Partition> partitions, DepGraph graph) { + for (Partition p : partitions) { + p.closure = DepGraph.traverse(p.entries, graph.upstreamOf); + } + } + + private static void assignToPartitionsExclusive(Set<String> affected, List<Partition> partitions, + Partition defaultPartition) { + List<Partition> explicit = partitions.stream() + .filter(p -> p != defaultPartition) + .collect(Collectors.toList()); + for (String ga : affected) { + Partition sole = null; + int count = 0; + for (Partition p : explicit) { + if (p.closure.contains(ga)) { + sole = p; + count++; + if (count > 1) break; + } + } + if (count == 1) { + sole.assigned.add(ga); + } else { + defaultPartition.assigned.add(ga); + } + } + } + + // The upstream set intentionally includes the partition's own affected modules. + // Without them, an upstream module from another partition could fail to resolve + // dependencies on this partition's affected modules (e.g., shared module U depends + // on affected module V — if V is removed from upstream, building U fails). + private static void computePerPartitionUpstream(List<Partition> partitions, DepGraph graph) { + for (Partition p : partitions) { + if (p.assigned.isEmpty()) continue; + p.upstream = DepGraph.traverse(p.assigned, graph.upstreamOf); Review Comment: This traversal includes every seed, so every assigned module is written to both the partition's upstream file and its affected file. The workflow consequently installs every affected module once with tests skipped and then installs it again with tests; the committed goldens confirm complete overlap (for example, all 452 default affected modules in scenario 03 also appear upstream). This substantially duplicates the expensive work this PR is intended to parallelize. Keep other-partition dependencies in the upstream set, but exclude this partition's own assigned modules; derive the image-producer prebuild list from the union before exclusion so affected image producers can still be built ahead of their consumers. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
