This is an automated email from the ASF dual-hosted git repository. nfilotto pushed a commit to branch add-incremental-build in repository https://gitbox.apache.org/repos/asf/camel.git
commit 1305ce47218180ee8e228bff2ced086bfda95c60 Author: Nicolas Filotto <nfilo...@talend.com> AuthorDate: Thu Jun 1 11:11:57 2023 +0200 Add an incremental build --- .github/actions/incremental-build/action.yaml | 46 +++++++++++++++++ .../actions/incremental-build/incremental-build.sh | 59 ++++++++++++++++++++++ .github/workflows/pr-build-main.yml | 48 ++++++++++++++++++ 3 files changed, 153 insertions(+) diff --git a/.github/actions/incremental-build/action.yaml b/.github/actions/incremental-build/action.yaml new file mode 100644 index 00000000000..cfddf6de94d --- /dev/null +++ b/.github/actions/incremental-build/action.yaml @@ -0,0 +1,46 @@ +# +# 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: "Incremental Build Runner" +description: "Build only affected projects" +inputs: + checkstyle: + description: 'Flag indicating whether only checkstyle should be launched' + required: true + log: + description: 'Name of the log file' + required: true + start-commit: + description: 'Starting commit' + required: true + end-commit: + description: 'End commit' + required: true +runs: + using: "composite" + steps: + - id: install-mvnd + uses: ./.github/actions/install-mvnd + - name: maven build + shell: bash + run: ${{ github.action_path }}/incremental-build.sh ${{ steps.install-mvnd.outputs.mvnd-dir }}/mvnd ${{ inputs.checkstyle }} ${{ inputs.log }} ${{ inputs.start-commit }} ${{ inputs.end-commit }} + - name: archive logs + uses: actions/upload-artifact@v3 + if: always() + with: + name: ${{ inputs.log }} + path: ${{ inputs.log }} diff --git a/.github/actions/incremental-build/incremental-build.sh b/.github/actions/incremental-build/incremental-build.sh new file mode 100644 index 00000000000..b477caa7aea --- /dev/null +++ b/.github/actions/incremental-build/incremental-build.sh @@ -0,0 +1,59 @@ +# +# 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. +# + +# Modify maven options here if needed +MVN_DEFAULT_OPTS="-Dmvnd.threads=2 -V -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 --no-transfer-progress -e" +MVN_OPTS=${MVN_OPTS:-$MVN_DEFAULT_OPTS} + +function findProjectRoot () { + local path=${1} + while [[ "$path" != "" && ! -e "$path/pom.xml" ]]; do + path=${path%/*} + done + echo "$path" +} + +function main() { + local mavenBinary=${1} + local checkstyle=${2} + local log=${3} + local startCommit=${4:-""} + local endCommit=${5:-""} + + echo "Searching for affected projects" + local projects=$(git diff "${startCommit}..${endCommit}" --name-only --pretty=format:"" | sed 's|\(.*\)/.*|\1|' | uniq | sort) + local pl="" + local lastProjectRoot="" + for project in ${projects} + do + projectRoot=$(findProjectRoot ${project}) + if [[ ${projectRoot} != ${lastProjectRoot} ]] ; then + pl="$pl,${projectRoot}" + fi + done + pl="${pl:1}" + + if [[ ${checkstyle} = "true" ]] ; then + echo "Launching checkstyle command against the projects ${pl}" + $mavenBinary -l $log $MVN_OPTS -Dcheckstyle.failOnViolation=true checkstyle:checkstyle -pl "$pl" + else + echo "Launching fast build of the projects ${pl}, their dependencies and the projects that depend on them" + $mavenBinary -l $log $MVN_OPTS -Pfastinstall -DskipTests install -pl "$pl" -amd -am + fi +} + +main "$@" diff --git a/.github/workflows/pr-build-main.yml b/.github/workflows/pr-build-main.yml index 55dc4b599f1..2dc0e99304c 100644 --- a/.github/workflows/pr-build-main.yml +++ b/.github/workflows/pr-build-main.yml @@ -100,3 +100,51 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} start-commit: ${{ github.event.pull_request.base.sha }} end-commit: ${{ github.event.after }} + incremental-checkstyle: + if: github.repository == 'apache/camel' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + persist-credentials: false + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 17 + cache: 'maven' + - name: mvn checkstyle + uses: ./.github/actions/incremental-build + with: + checkstyle: true + log: checkstyle.log + start-commit: ${{ github.event.pull_request.base.sha }} + end-commit: ${{ github.event.after }} + incremental-build: + if: github.repository == 'apache/camel' + permissions: + issues: write + runs-on: ubuntu-latest + strategy: + matrix: + java: [ '17' ] + steps: + - uses: actions/checkout@v3 + with: + persist-credentials: false + fetch-depth: 0 + - id: install-packages + uses: ./.github/actions/install-packages + - name: Set up JDK ${{ matrix.java }} + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: ${{ matrix.java }} + cache: 'maven' + - name: maven build + uses: ./.github/actions/incremental-build + with: + checkstyle: false + log: build.log + start-commit: ${{ github.event.pull_request.base.sha }} + end-commit: ${{ github.event.after }}