Daily Build Quarkus main

#
# 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: Daily Build Quarkus main

on:
  schedule:
    # Run every day at 2AM
    - cron:  '0 2 * * *'

env:
  LANG: en_US.UTF-8
  MAVEN_OPTS: -Xmx3000m
  CQ_MAVEN_ARGS: -V -ntp -e -Daether.connector.http.connectionMaxTtl=120
  TESTCONTAINERS_RYUK_DISABLED: true
  ISSUE_ID: 2926

jobs:
  initial-mvn-install:
    if: github.repository == 'apache/camel-quarkus'
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-native-matrix.outputs.matrix }}
      examples-matrix: ${{ steps.set-examples-matrix.outputs.examples-matrix }}
      alternate-jvm-matrix: ${{ steps.set-alternate-jvm-matrix.outputs.alternate-jvm-matrix }}
    env:
      MAVEN_OPTS: -Xmx4600m
    steps:
      - name: Check free space on disk
        run: |
          df -h /
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: Set Workflow Build ID
        run: |
          [ ! -d ~/build-data ] && mkdir -p ~/build-data
          echo "${{ github.run_id }}-${{ github.run_number }}-$(uuidgen)" > ~/build-data/build-id.txt
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: quarkus-main
          fetch-depth: 0
      - name: Rebase branch main onto quarkus-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase origin/main
          git rev-parse origin/main > ~/build-data/main-sha.txt
      - name: Build Quarkus
        run: |
          cd ../
          git clone --depth 1 --branch main https://github.com/quarkusio/quarkus.git \
            && cd quarkus \
            && echo "Current Quarkus commit:" $(git rev-parse HEAD) \
            && sed -i '/<module>integration-tests<\/module>/d' pom.xml \
            && ./mvnw ${CQ_MAVEN_ARGS} clean install -Dquickly -Prelocations -T1C
      - name: Update extension metadata
        run: |
          ./mvnw -N cq:update-quarkus-metadata ${CQ_MAVEN_ARGS}
      - name: mvn clean install -DskipTests
        run: |
          eval ./mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} clean install -DskipTests -Dquarkus.build.skip -Pformat
      - name: Sync Maven properties
        run: |
          ./mvnw cq:sync-versions ${CQ_MAVEN_ARGS} -N
      - name: Fail if there are uncommitted changes
        shell: bash
        run: |
          [[ -z $(git status --porcelain | grep -v antora.yml) ]] || { echo 'There are uncommitted changes'; git status; git diff; exit 1; }
      - name: Tar Maven Repo
        shell: bash
        run: |
          tar -czf ${{ runner.temp }}/maven-repo.tgz -C ~ build-data .m2/repository
          ls -lh ${{ runner.temp }}/maven-repo.tgz
          df -h /
      - name: Persist Maven Repo
        uses: actions/upload-artifact@v4
        with:
          name: maven-repo
          path: ${{ runner.temp }}/maven-repo.tgz
          retention-days: 1
      - name: Setup Native Test Matrix
        id: set-native-matrix
        run: |
          CATEGORIES=$(yq -M -N -I 0 -o=json e 'keys' tooling/scripts/test-categories.yaml | tr '"' "'")
          echo "matrix={'category': ${CATEGORIES}}" >> $GITHUB_OUTPUT
      - name: Setup Alternate JVM Matrix
        id: set-alternate-jvm-matrix
        shell: bash
        run: |
          cd integration-tests
          mvn help:evaluate -Dexpression=project.modules -N -q -DforceStdout | sed -e 's/<[^>]*>//g' -e 's/^[[:space:]]*//' -e '/^$/d' > ${{ runner.temp }}/itest-modules.txt
          GROUP1_MODULES=$(cat ${{ runner.temp }}/itest-modules.txt | grep -E '^[a-m].*' | tr '\n' ',' | sed 's/,$//')
          GROUP2_MODULES=$(cat ${{ runner.temp }}/itest-modules.txt | grep -E '^[n-z].*' | tr '\n' ',' | sed 's/,$//')
          echo "alternate-jvm-matrix={'include': [{'name': 'group-01', 'modules': '${GROUP1_MODULES}'},{'name': 'group-02', 'modules': '${GROUP2_MODULES}'}]}" >> $GITHUB_OUTPUT
      - name: Setup Examples Matrix
        id: set-examples-matrix
        run: |
          EXAMPLES_BRANCH="camel-quarkus-main"
          if [[ ${GITHUB_REF_NAME} =~ [0-9]+.[0-9]+.x ]]; then
              EXAMPLES_BRANCH=${GITHUB_REF_NAME}
          elif [[ ${GITHUB_BASE_REF} =~ [0-9]+.[0-9]+.x ]]; then
              EXAMPLES_BRANCH=${GITHUB_BASE_REF}
          fi

          sudo apt install groovy -y --no-install-recommends
          EXAMPLES_MATRIX=$(groovy -DEXAMPLES_BRANCH=${EXAMPLES_BRANCH} tooling/scripts/generate-examples-matrix.groovy)
          echo "examples-matrix=${EXAMPLES_MATRIX}" >> $GITHUB_OUTPUT
      - name: Report Build Failure
        if: failure() || cancelled()
        run: |
          # Abort rebase in case something went wrong as we may have broken pom.xml files
          if [[ -e ".git/rebase" || -e ".git/rebase-apply" || -e ".git/rebase-merge" ]]; then
            git rebase --abort
          fi

          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=quarkus-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  native-tests:
    name: Native Tests - ${{matrix.category}}
    needs: initial-mvn-install
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix: ${{ fromJson(needs.initial-mvn-install.outputs.matrix) }}
    steps:
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: quarkus-main
          fetch-depth: 0
      - name: Reclaim Disk Space
        run: .github/reclaim-disk-space.sh
      - name: Rebase branch main onto quarkus-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: Integration Tests
        run: |
          for MODULE in $(yq -M -N e ".${{ matrix.category }}" tooling/scripts/test-categories.yaml | grep -vE '^\s*#' | cut -f2 -d' '); do
            if [[ "${MODULE}" == "null" ]]; then
              continue
            fi

            MODULE="integration-tests/$(echo ${MODULE} | sed 's/^[ \t]*//;s/[ \t]*$//')"

            if [[ "x$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=ci.native.tests.skip -DforceStdout -q -f ${MODULE})" == "xtrue" ]]; then
              JVM_MODULES+=("${MODULE}")
            else
              NATIVE_MODULES+=("${MODULE}")
            fi
          done

          if [[ ${#JVM_MODULES[@]} -eq 0 ]] && [[ ${#NATIVE_MODULES[@]} -eq 0 ]]; then
            echo "No test modules were found for category ${{ matrix.category }}"
            exit 1
          fi

          IFS=,
          if [[ ${JVM_MODULES[@]} ]]; then
            eval ./mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} clean test \
              -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
              -Pdocker,ci \
              -pl "${JVM_MODULES[*]}"
          fi

          if [[ ${NATIVE_MODULES[@]} ]]; then
            eval ./mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} clean verify \
              -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
              -Dquarkus.native.builder-image.pull=missing \
              -Pnative,docker,ci \
              --fail-at-end \
              -pl "${NATIVE_MODULES[*]}"
          fi
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: integration-tests
      - name: Fail if there are uncommitted changes
        shell: bash
        run: |
          [[ -z $(git status --porcelain) ]] || { echo 'There are uncommitted changes'; git status; git diff; exit 1; }
      - name: Report Build Failure
        if: failure() || cancelled()
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=quarkus-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  functional-extension-tests:
    runs-on: ubuntu-latest
    needs: initial-mvn-install
    env:
      MAVEN_OPTS: -Xmx3000m
    steps:
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: quarkus-main
          fetch-depth: 0
      - name: Rebase branch main onto quarkus-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: cd extensions-core && mvn test
        run: |
          cd extensions-core
          ../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
            --fail-at-end \
            test
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: extensions-core
      - name: cd extensions && mvn test
        run: |
          cd extensions
          ../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
            --fail-at-end \
            test
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: extensions
      - name: cd test-framework && mvn test
        run: |
          cd test-framework
          ../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
            --fail-at-end \
            test
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: test-framework
      - name: cd tooling && mvn verify
        run: |
          cd tooling
          ../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
            --fail-at-end \
            verify
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: tooling
      - name: cd catalog && mvn test
        run: |
          cd catalog
          ../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
            test
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: catalog
      - name: Report Build Failure
        if: failure() || cancelled()
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=quarkus-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  extensions-jvm-tests:
    runs-on: ubuntu-latest
    needs: initial-mvn-install
    strategy:
      fail-fast: false
      matrix:
        java: [ '17', '21' ]
    env:
      MAVEN_OPTS: -Xmx3000m
    steps:
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: quarkus-main
          fetch-depth: 0
      - name: Rebase branch main onto quarkus-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Set up JDK ${{ matrix.java }}
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: ${{ matrix.java }}
      - name: cd integration-tests-jvm && mvn clean test
        run: |
          cd integration-tests-jvm
          ../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
            --fail-at-end \
            clean test
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: integration-tests-jvm
      - name: Report Build Failure
        if: failure() || cancelled()
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=quarkus-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  integration-tests-alternative-jdk:
    runs-on: ubuntu-latest
    needs: initial-mvn-install
    strategy:
      fail-fast: false
      matrix: ${{ fromJson(needs.initial-mvn-install.outputs.alternate-jvm-matrix) }}
    env:
      MAVEN_OPTS: -Xmx3000m
    steps:
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: quarkus-main
          fetch-depth: 0
      - name: Rebase branch main onto quarkus-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Reclaim Disk Space
        run: .github/reclaim-disk-space.sh
      - name: Set up JDK 21
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '21'
      - name: cd integration-tests && mvn clean verify
        shell: bash
        env:
          TEST_MODULES: ${{matrix.modules}}
        run: |
          cd integration-tests
          ../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
            -pl "${TEST_MODULES// /,}" \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
            --fail-at-end \
            clean verify
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: integration-tests

  integration-tests-alternative-platform:
    runs-on: ${{ matrix.os }}
    needs: initial-mvn-install
    strategy:
      fail-fast: false
      matrix:
        os: [ 'windows-latest' ]
    env:
      MAVEN_OPTS: -Xmx3000m
    steps:
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: quarkus-main
          fetch-depth: 0
      - name: Rebase branch main onto quarkus-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: cd integration-tests && mvn clean verify
        shell: bash
        run: |
          cd integration-tests
          ../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
            -Dskip-testcontainers-tests -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
            --fail-at-end \
            clean verify
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: integration-tests
      - name: Report Build Failure
        if: failure() || cancelled()
        shell: bash
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=quarkus-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  examples-tests:
    name: Examples Tests - ${{matrix.name}}
    needs: initial-mvn-install
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix: ${{ fromJson(needs.initial-mvn-install.outputs.examples-matrix) }}
    steps:
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: quarkus-main
          fetch-depth: 0
      - name: Rebase branch main onto quarkus-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: set CQ_VERSION
        run: echo "CQ_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout -N)" >> $GITHUB_ENV
      - name: clone and verify examples
        env:
          EXAMPLE_MODULES: ${{matrix.examples}}
        shell: '/usr/bin/bash {0}'
        run: |
          EXAMPLES_BRANCH="camel-quarkus-main"

          if [[ ${GITHUB_REF_NAME} =~ [0-9]+.[0-9]+.x ]]; then
              EXAMPLES_BRANCH=${GITHUB_REF_NAME}
          elif [[ ${GITHUB_BASE_REF} =~ [0-9]+.[0-9]+.x ]]; then
              EXAMPLES_BRANCH=${GITHUB_BASE_REF}
          fi

          git clone --depth 1 --branch ${EXAMPLES_BRANCH} https://github.com/apache/camel-quarkus-examples.git \
            && cd camel-quarkus-examples \
            && echo "Current Examples commit:" $(git rev-parse HEAD) \
            && ./mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} org.l2x6.cq:cq-maven-plugin:2.10.0:examples-set-platform -Dcq.camel-quarkus.version=${CQ_VERSION}

          BUILD_FAILURES=()

          for MODULE in ${EXAMPLE_MODULES//,/ }; do
            cd ${MODULE}

            ../mvnw ${CQ_MAVEN_ARGS} clean verify \
              -Dformatter.skip -Dimpsort.skip \
              -Dquarkus.native.builder-image.pull=missing \
              -Pnative,docker,ci

            if [[ $? -ne 0 ]]; then
              BUILD_FAILURES[${#BUILD_FAILURES[@]}]=${MODULE}
            fi

            cd -
          done

          if [[ ${#BUILD_FAILURES[@]} -gt 0 ]]; then
            echo -e "\nBuild errors were encountered in the following projects:\n"
            for FAILURE in ${BUILD_FAILURES[@]}; do
                echo "* ${FAILURE}"
            done
            echo -e "\nCheck build logs for further information."
            exit 1
          fi
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
      - name: Report Build Failure
        if: failure() || cancelled()
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=quarkus-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  handle-build-status:
    needs: native-tests
    runs-on: ubuntu-latest
    steps:
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: quarkus-main
          fetch-depth: 0
      - name: Rebase branch main onto quarkus-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Report build status
        id: report
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=verify -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=quarkus-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)
      - name: Sync branch main to quarkus-main
        if: steps.report.outputs.overall_build_status == 'success'
        run: |
          git push --force-with-lease origin quarkus-main


Daily Build Camel Main branch

#
# 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: Daily Build Camel Main branch

on:
  schedule:
    # Run every day at midnight
    - cron:  '0 0 * * *'

env:
  LANG: en_US.UTF-8
  MAVEN_OPTS: -Xmx3000m
  CQ_MAVEN_ARGS: -V -ntp -e -Daether.connector.http.connectionMaxTtl=120
  TESTCONTAINERS_RYUK_DISABLED: true
  ISSUE_ID: 2927

jobs:
  initial-mvn-install:
    if: github.repository == 'apache/camel-quarkus'
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-native-matrix.outputs.matrix }}
      examples-matrix: ${{ steps.set-examples-matrix.outputs.examples-matrix }}
      alternate-jvm-matrix: ${{ steps.set-alternate-jvm-matrix.outputs.alternate-jvm-matrix }}
    env:
      MAVEN_OPTS: -Xmx4600m
    steps:
      - name: Check free space on disk
        run: |
          df -h /
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: Set Workflow Build ID
        run: |
          [ ! -d ~/build-data ] && mkdir -p ~/build-data
          echo "${{ github.run_id }}-${{ github.run_number }}-$(uuidgen)" > ~/build-data/build-id.txt
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: camel-main
          fetch-depth: 0
      - name: Rebase branch main onto camel-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase origin/main
          git rev-parse origin/main > ~/build-data/main-sha.txt
      - name: Build Camel
        run: |
          cd ../
          git clone --depth 1 --branch main https://github.com/apache/camel.git \
            && cd camel \
            && echo "Current Camel commit:" $(git rev-parse HEAD) \
            && ./mvnw ${CQ_MAVEN_ARGS} clean install -Dquickly -T1C
      - name: Update extension metadata
        run: |
          ./mvnw -N cq:update-quarkus-metadata ${CQ_MAVEN_ARGS}
      - name: mvn clean install -DskipTests
        run: |
          eval ./mvnw ${CQ_MAVEN_ARGS} clean install -DskipTests -Dquarkus.build.skip -Pformat
      - name: Sync Maven properties
        run: |
          ./mvnw cq:sync-versions ${CQ_MAVEN_ARGS} -N
      - name: Fail if there are uncommitted changes
        shell: bash
        run: |
          [[ -z $(git status --porcelain | grep -v antora.yml) ]] || { echo 'There are uncommitted changes'; git status; git diff; exit 1; }
      - name: Tar Maven Repo
        shell: bash
        run: |
          tar -czf ${{ runner.temp }}/maven-repo.tgz -C ~ build-data .m2/repository
          ls -lh ${{ runner.temp }}/maven-repo.tgz
          df -h /
      - name: Persist Maven Repo
        uses: actions/upload-artifact@v4
        with:
          name: maven-repo
          path: ${{ runner.temp }}/maven-repo.tgz
          retention-days: 1
      - name: Setup Native Test Matrix
        id: set-native-matrix
        run: |
          CATEGORIES=$(yq -M -N -I 0 -o=json e 'keys' tooling/scripts/test-categories.yaml | tr '"' "'")
          echo "matrix={'category': ${CATEGORIES}}" >> $GITHUB_OUTPUT
      - name: Setup Alternate JVM Matrix
        id: set-alternate-jvm-matrix
        shell: bash
        run: |
          cd integration-tests
          mvn help:evaluate -Dexpression=project.modules -N -q -DforceStdout | sed -e 's/<[^>]*>//g' -e 's/^[[:space:]]*//' -e '/^$/d' > ${{ runner.temp }}/itest-modules.txt
          GROUP1_MODULES=$(cat ${{ runner.temp }}/itest-modules.txt | grep -E '^[a-m].*' | tr '\n' ',' | sed 's/,$//')
          GROUP2_MODULES=$(cat ${{ runner.temp }}/itest-modules.txt | grep -E '^[n-z].*' | tr '\n' ',' | sed 's/,$//')
          echo "alternate-jvm-matrix={'include': [{'name': 'group-01', 'modules': '${GROUP1_MODULES}'},{'name': 'group-02', 'modules': '${GROUP2_MODULES}'}]}" >> $GITHUB_OUTPUT
      - name: Setup Examples Matrix
        id: set-examples-matrix
        run: |
          EXAMPLES_BRANCH="camel-quarkus-main"
          if [[ ${GITHUB_REF_NAME} =~ [0-9]+.[0-9]+.x ]]; then
              EXAMPLES_BRANCH=${GITHUB_REF_NAME}
          elif [[ ${GITHUB_BASE_REF} =~ [0-9]+.[0-9]+.x ]]; then
              EXAMPLES_BRANCH=${GITHUB_BASE_REF}
          fi

          sudo apt install groovy -y --no-install-recommends
          EXAMPLES_MATRIX=$(groovy -DEXAMPLES_BRANCH=${EXAMPLES_BRANCH} tooling/scripts/generate-examples-matrix.groovy)
          echo "examples-matrix=${EXAMPLES_MATRIX}" >> $GITHUB_OUTPUT
      - name: Report Build Failure
        if: failure() || cancelled()
        run: |
          # Abort rebase in case something went wrong as we may have broken pom.xml files
          if [[ -e ".git/rebase" || -e ".git/rebase-apply" || -e ".git/rebase-merge" ]]; then
            git rebase --abort
          fi

          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=camel-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  native-tests:
    name: Native Tests - ${{matrix.category}}
    needs: initial-mvn-install
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix: ${{ fromJson(needs.initial-mvn-install.outputs.matrix) }}
    steps:
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: camel-main
          fetch-depth: 0
      - name: Reclaim Disk Space
        run: .github/reclaim-disk-space.sh
      - name: Rebase branch main onto camel-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: Integration Tests
        run: |
          for MODULE in $(yq -M -N e ".${{ matrix.category }}" tooling/scripts/test-categories.yaml | grep -vE '^\s*#' | cut -f2 -d' '); do
            if [[ "${MODULE}" == "null" ]]; then
              continue
            fi

            MODULE="integration-tests/$(echo ${MODULE} | sed 's/^[ \t]*//;s/[ \t]*$//')"

            if [[ "x$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=ci.native.tests.skip -DforceStdout -q -f ${MODULE})" == "xtrue" ]]; then
              JVM_MODULES+=("${MODULE}")
            else
              NATIVE_MODULES+=("${MODULE}")
            fi
          done

          if [[ ${#JVM_MODULES[@]} -eq 0 ]] && [[ ${#NATIVE_MODULES[@]} -eq 0 ]]; then
            echo "No test modules were found for category ${{ matrix.category }}"
            exit 1
          fi

          IFS=,
          if [[ ${JVM_MODULES[@]} ]]; then
            eval ./mvnw ${CQ_MAVEN_ARGS} clean test \
              -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
              -Pdocker,ci \
              -pl "${JVM_MODULES[*]}"
          fi

          if [[ ${NATIVE_MODULES[@]} ]]; then
            eval ./mvnw ${CQ_MAVEN_ARGS} clean verify \
              -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
              -Dquarkus.native.builder-image.pull=missing \
              -Pnative,docker,ci \
              --fail-at-end \
              -pl "${NATIVE_MODULES[*]}"
          fi
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: integration-tests
      - name: Fail if there are uncommitted changes
        shell: bash
        run: |
          [[ -z $(git status --porcelain) ]] || { echo 'There are uncommitted changes'; git status; git diff; exit 1; }
      - name: Report Build Failure
        if: failure() || cancelled()
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=camel-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  functional-extension-tests:
    runs-on: ubuntu-latest
    needs: initial-mvn-install
    env:
      MAVEN_OPTS: -Xmx3000m
    steps:
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: camel-main
          fetch-depth: 0
      - name: Rebase branch main onto camel-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: cd extensions-core && mvn test
        run: |
          cd extensions-core
          ../mvnw ${CQ_MAVEN_ARGS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
            --fail-at-end \
            test
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: extensions-core
      - name: cd extensions && mvn test
        run: |
          cd extensions
          ../mvnw ${CQ_MAVEN_ARGS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
            --fail-at-end \
            test
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: extensions
      - name: cd test-framework && mvn test
        run: |
          cd test-framework
          ../mvnw ${CQ_MAVEN_ARGS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip -Dcamel-quarkus.update-extension-doc-page.skip \
            --fail-at-end \
            test
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: test-framework
      - name: cd tooling && mvn verify
        run: |
          cd tooling
          ../mvnw ${CQ_MAVEN_ARGS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
            --fail-at-end \
            verify
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: tooling
      - name: cd catalog && mvn test
        run: |
          cd catalog
          ../mvnw ${CQ_MAVEN_ARGS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
            test
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: catalog
      - name: Report Build Failure
        if: failure() || cancelled()
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=camel-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  extensions-jvm-tests:
    runs-on: ubuntu-latest
    needs: initial-mvn-install
    strategy:
      fail-fast: false
      matrix:
        java: [ '17', '21' ]
    env:
      MAVEN_OPTS: -Xmx3000m
    steps:
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: camel-main
          fetch-depth: 0
      - name: Rebase branch main onto camel-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Set up JDK ${{ matrix.java }}
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: ${{ matrix.java }}
      - name: cd integration-tests-jvm && mvn clean test
        run: |
          cd integration-tests-jvm
          ../mvnw ${CQ_MAVEN_ARGS} \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
            --fail-at-end \
            clean test
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: integration-tests-jvm
      - name: Report Build Failure
        if: failure() || cancelled()
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=camel-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  integration-tests-alternative-jdk:
    runs-on: ubuntu-latest
    needs: initial-mvn-install
    strategy:
      fail-fast: false
      matrix: ${{ fromJson(needs.initial-mvn-install.outputs.alternate-jvm-matrix) }}
    env:
      MAVEN_OPTS: -Xmx3000m
    steps:
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: camel-main
          fetch-depth: 0
      - name: Rebase branch main onto camel-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Reclaim Disk Space
        run: .github/reclaim-disk-space.sh
      - name: Set up JDK 21
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '21'
      - name: cd integration-tests && mvn clean verify
        shell: bash
        env:
          TEST_MODULES: ${{matrix.modules}}
        run: |
          cd integration-tests
          ../mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} \
            -pl "${TEST_MODULES// /,}" \
            -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
            --fail-at-end \
            clean verify
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: integration-tests

  integration-tests-alternative-platform:
    runs-on: ${{ matrix.os }}
    needs: initial-mvn-install
    strategy:
      fail-fast: false
      matrix:
        os: [ 'windows-latest' ]
    env:
      MAVEN_OPTS: -Xmx3000m
    steps:
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: camel-main
          fetch-depth: 0
      - name: Rebase branch main onto camel-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: cd integration-tests && mvn clean verify
        shell: bash
        run: |
          cd integration-tests
          ../mvnw ${CQ_MAVEN_ARGS} \
            -Dskip-testcontainers-tests -Dformatter.skip -Dimpsort.skip -Denforcer.skip \
            --fail-at-end \
            clean verify
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
        with:
          test-report-xml-base-dir: integration-tests
      - name: Report Build Failure
        if: failure() || cancelled()
        shell: bash
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=camel-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  examples-tests:
    name: Examples Tests - ${{matrix.name}}
    needs: initial-mvn-install
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix: ${{ fromJson(needs.initial-mvn-install.outputs.examples-matrix) }}
    steps:
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: camel-main
          fetch-depth: 0
      - name: Rebase branch main onto camel-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: set CQ_VERSION
        run: echo "CQ_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout -N)" >> $GITHUB_ENV
      - name: clone and verify examples
        env:
          EXAMPLE_MODULES: ${{matrix.examples}}
        shell: '/usr/bin/bash {0}'
        run: |
          EXAMPLES_BRANCH="camel-quarkus-main"

          if [[ ${GITHUB_REF_NAME} =~ [0-9]+.[0-9]+.x ]]; then
              EXAMPLES_BRANCH=${GITHUB_REF_NAME}
          elif [[ ${GITHUB_BASE_REF} =~ [0-9]+.[0-9]+.x ]]; then
              EXAMPLES_BRANCH=${GITHUB_BASE_REF}
          fi

          git clone --depth 1 --branch ${EXAMPLES_BRANCH} https://github.com/apache/camel-quarkus-examples.git \
            && cd camel-quarkus-examples \
            && echo "Current Examples commit:" $(git rev-parse HEAD) \
            && ./mvnw ${CQ_MAVEN_ARGS} ${BRANCH_OPTIONS} org.l2x6.cq:cq-maven-plugin:2.10.0:examples-set-platform -Dcq.camel-quarkus.version=${CQ_VERSION}

          BUILD_FAILURES=()

          for MODULE in ${EXAMPLE_MODULES//,/ }; do
            cd ${MODULE}

            ../mvnw ${CQ_MAVEN_ARGS} clean verify \
              -Dformatter.skip -Dimpsort.skip \
              -Dquarkus.native.builder-image.pull=missing \
              -Pnative,docker,ci

            if [[ $? -ne 0 ]]; then
              BUILD_FAILURES[${#BUILD_FAILURES[@]}]=${MODULE}
            fi

            cd -
          done

          if [[ ${#BUILD_FAILURES[@]} -gt 0 ]]; then
            echo -e "\nBuild errors were encountered in the following projects:\n"
            for FAILURE in ${BUILD_FAILURES[@]}; do
                echo "* ${FAILURE}"
            done
            echo -e "\nCheck build logs for further information."
            exit 1
          fi
      - name: Report test failures
        uses: ./.github/actions/test-summary-report
        if: ${{ failure() }}
      - name: Report Build Failure
        if: failure() || cancelled()
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=${{ job.status }} -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=camel-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)

  handle-build-status:
    needs: native-tests
    runs-on: ubuntu-latest
    steps:
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: Download Maven Repo
        uses: actions/download-artifact@v4
        with:
          name: maven-repo
          path: ..
      - name: Extract Maven Repo
        shell: bash
        run: |
          df -h /
          tar -xzf ../maven-repo.tgz -C ~
          rm -f ../maven-repo.tgz
          df -h /
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: camel-main
          fetch-depth: 0
      - name: Rebase branch main onto camel-main
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"
          git fetch origin main
          git rebase $(cat ~/build-data/main-sha.txt)
      - name: Report build status
        id: report
        run: |
          ./mvnw ${CQ_MAVEN_ARGS} verify -N -Pbuild-notification -Dstatus=verify -DissueId=${{ env.ISSUE_ID }} -Dtoken=${{ secrets.GITHUB_TOKEN }} -DbuildId=$(cat ~/build-data/build-id.txt) -Drepo=${GITHUB_REPOSITORY} -Dbranch=camel-main -Dbranch-commit=$(cat ~/build-data/main-sha.txt)
      - name: Sync branch main to camel-main
        if: steps.report.outputs.overall_build_status == 'success'
        run: |
          git push --force-with-lease origin camel-main


Generate JVM Extensions

#
# 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: Generate JVM Extensions

on:
  workflow_dispatch:
    inputs:
      artifactIds:
        description: 'Comma separated list of Camel component artifact ids. E.g activemq,ahc-ws,kafka'
        required: true

jobs:
  generate-jvm-extensions:
    if: github.repository == 'apache/camel-quarkus'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
      - name: Generate JVM Extensions
        id: generate
        if: ${{ steps.generate.outputs.extensions-added }} == "true"
        run: |
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config --local user.name "github-actions[bot]"

          ARTIFACT_IDS=$(echo "${{ github.event.inputs.artifactIds }}" | sed 's/camel-//g')
          BRANCH_NAME="add-jvm-extensions-$(uuidgen | cut -f1 -d'-')"

          git checkout -b ${BRANCH_NAME}

          # Unfortunately the catalog requires all of the extension projects to be built...
          sed -i -e '/<module>integration\-tests\-support<\/module>/d' -e '/<module>integration\-tests<\/module>/d' -e '/<module>docs<\/module>/d' ./pom.xml
          ./mvnw -V -ntp -Dquickly clean install -T1C

          # Remove pom hacks
          git reset --hard HEAD

          OLDIFS=${IFS}
          IFS=,

          for ARTIFACT_ID in ${ARTIFACT_IDS}; do
            # Create extension
            ./mvnw -V -ntp cq:create -N -Dcq.artifactIdBase=${ARTIFACT_ID} -Dcq.nativeSupported=false

            # Verify extension builds, run formatting steps & docs generation
            ./mvnw -V -ntp \
              -pl extensions-jvm/${ARTIFACT_ID} \
              -pl extensions-jvm/${ARTIFACT_ID}/runtime \
              -pl extensions-jvm/${ARTIFACT_ID}/deployment \
              -pl extensions-jvm/${ARTIFACT_ID}/integration-test clean package

            git add .
            git commit -m "${ARTIFACT_ID} JVM support"
          done

          IFS=${OLDIFS}

          git push --set-upstream origin ${BRANCH_NAME}

          GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} gh pr create \
            --title="Add JVM only extensions for ${ARTIFACT_IDS}" \
            --body="This is an auto-generated pull request to add JVM only support for ${ARTIFACT_IDS}.

You can edit the changes by checking out branch ${BRANCH_NAME}." \
            --label="JVM"


Generate SBOM (Camel Quarkus)

#
# 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: Generate SBOM (Camel Quarkus)

on:
  schedule:
  - cron: '30 10 * * 0'
  workflow_dispatch:
env:
  LANG: en_US.UTF-8
  MAVEN_OPTS: -Xmx3000m
  CQ_MAVEN_ARGS: -V -ntp -e -Daether.connector.http.connectionMaxTtl=120

permissions: {}
jobs:
  build:
    if: github.repository == 'apache/camel-quarkus'
    permissions:
      contents: write # to create branch (peter-evans/create-pull-request)
      pull-requests: write # to create a PR (peter-evans/create-pull-request)
    env:
      MAVEN_OPTS: -Xmx4400m

    runs-on: ubuntu-latest
    strategy:
      matrix:
        java: [ '17' ]
    steps:
      - uses: actions/checkout@v4
        with:
          persist-credentials: false
      - name: Set up JDK ${{ matrix.java }}
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: ${{ matrix.java }}
          cache: 'maven'
      - name: mvn build and sbom generation
        run: ./mvnw -V --no-transfer-progress -e -Psbom -Dquickly -DskipTests verify ${CQ_MAVEN_ARGS}
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v6
        with:
          base: main
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: "Regen SBOM from commit ${{ github.sha }}"
          committer: GitHub <noreply@github.com>
          author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
          signoff: true
          branch: regen_bot_sbom
          title: "Generated sources regen for SBOM"
          body: |
            Regen bot :robot: found some uncommitted changes after running build on :camel-quarkus: `main` branch for generating SBOMs.
            Please do not delete `regen_bot_sbom` branch after merge/rebase.
          labels: |
            regen
            automated pr
            camel-quarkus
          assignees: oscerd


Synchronize Dependabot Branch

#
# 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: Synchronize Dependabot Branch

on:
  workflow_run:
    workflows: ["Camel Quarkus CI"]
    types:
      - completed

jobs:
  update:
    runs-on: ubuntu-latest
    outputs:
      branch-ref: ${{ steps.setup-dependabot-patches.outputs.branch-ref }}
      pr-number: ${{ steps.setup-dependabot-patches.outputs.pr-number }}
      pr-updated: ${{ steps.push-changes.outputs.updated }}
    if: github.repository == 'apache/camel-quarkus' && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' && github.actor == 'dependabot[bot]'
    steps:
      - name: Download dependabot pull request changes
        id: download-pr-changes
        uses: actions/github-script@v7
        with:
          result-encoding: string
          script: |
            const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
               owner: context.repo.owner,
               repo: context.repo.repo,
               run_id: ${{github.event.workflow_run.id }},
            });

            const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
              return artifact.name == "dependabot-pr-changeset"
            })[0];

            if (matchArtifact !== undefined) {
              const download = await github.rest.actions.downloadArtifact({
                owner: context.repo.owner,
                repo: context.repo.repo,
                artifact_id: matchArtifact.id,
                archive_format: 'zip',
              });

              const fs = require('fs');
              fs.writeFileSync('/home/runner/work/dependabot-pr.zip', Buffer.from(download.data));
              return true;
            }

            return false;
      - name: Set up dependabot patches
        id: setup-dependabot-patches
        if: steps.download-pr-changes.outputs.result == 'true'
        run: |
          if [[ -f /home/runner/work/dependabot-pr.zip ]]; then
            mkdir -p /home/runner/work/dependabot-pr
            unzip -o /home/runner/work/dependabot-pr.zip -d /home/runner/work/dependabot-pr

            echo "branch-ref=$(cat /home/runner/work/dependabot-pr/BRANCH_REF)" >> $GITHUB_OUTPUT
            echo "pr-number=$(cat /home/runner/work/dependabot-pr/PR_NUMBER)" >> $GITHUB_OUTPUT
          fi
      - name: Checkout dependabot branch
        uses: actions/checkout@v4
        if: steps.setup-dependabot-patches.outputs.branch-ref != ''
        with:
          ref: ${{ steps.setup-dependabot-patches.outputs.branch-ref }}
          fetch-depth: 0
      - name: Push changes to dependabot/maven branch
        id: push-changes
        if: steps.setup-dependabot-patches.outputs.branch-ref != ''
        run: |
          git config --local user.email "49699333+dependabot[bot]@users.noreply.github.com"
          git config --local user.name "dependabot[bot]"

          CHANGES_PATH=/home/runner/work/dependabot-pr/changes.patch
          if [[ -f "${CHANGES_PATH}" ]]; then
            COMMIT_MESSAGE="Auto generated changes for dependabot commit $(git log -1 --pretty=%H)"

            git apply ${CHANGES_PATH}
            git commit -am"${COMMIT_MESSAGE}"
            git push origin ${BRANCH_REF}

            echo "updated=true" >> $GITHUB_OUTPUT
          else
            echo "updated=false" >> $GITHUB_OUTPUT
          fi

  rerun-pr-workflow:
    needs: update
    runs-on: ubuntu-latest
    if: needs.update.outputs.pr-updated == 'true'
    permissions:
      actions: write
      pull-requests: write
    steps:
      - name: Trigger dependabot pull request workflow
        uses: actions/github-script@v7
        with:
          script: |
            await github.rest.actions.reRunWorkflow({
              owner: context.repo.owner,
              repo: context.repo.repo,
              run_id: ${{ github.event.workflow_run.id }},
            });

            await github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: ${{ needs.update.outputs.pr-number }},
              body: ":warning: :warning: :warning:\n\nBranch auto synchronized due to changes in generated files. New workflow run triggered:\n\nhttps://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}\n\nPlease check the workflow result before merging.\n\n:warning: :warning: :warning:"
            });


Assign Issue Milestone

#
# 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: Assign Issue Milestone

on:
  push:
    branches:
      - main
    paths-ignore:
      - 'CHANGELOG.md'
      - 'camel-quarkus-sbom/**'

permissions:
  contents: read
  issues: write

jobs:
  assign-issue-milestone:
    if: github.repository == 'apache/camel-quarkus'
    runs-on: ubuntu-latest
    steps:
      - name: Assign Closed Issues To Latest Milestone
        uses: actions/github-script@v7
        with:
          script: |
            const issueNumberFromCommitCommentRegex = new RegExp(`.*(?:fix(?:e[sd])?|(?:(?:resolve|close)[sd]?)):?\\s(?:https?:\\/\\/github\\.com\\/${context.repo.owner}\\/${context.repo.repo}\\/issues\\/|#)(\\d+)`, 'igm');
            const issueNumbers = new Set();

            // Get the commits that triggered this push event
            const commitComparison = await github.rest.repos.compareCommitsWithBasehead({
              owner: context.repo.owner,
              repo: context.repo.repo,
              basehead: `${context.payload.before}...${context.payload.after}`,
            });

            if (commitComparison && commitComparison.data) {
              // Parse issue number references from commit comments
              commitComparison.data.commits.forEach(commitData => {
                for (const match of commitData.commit.message.matchAll(issueNumberFromCommitCommentRegex)) {
                  let issueNumber = parseInt(match[1]);
                  if (!isNaN(issueNumber)) {
                    issueNumbers.add(issueNumber);
                  }
                }
              });
            }

            // No issues associated with the merged PR so we can exit
            if (issueNumbers.size === 0) {
              return;
            }

            // Get open milestones
            milestoneResults = await github.rest.issues.listMilestones({
              owner: context.repo.owner,
              repo: context.repo.repo,
              sort: "title",
              direction: "desc",
            });

            // Assign the latest milestone to issues associated with the merged PR
            if (milestoneResults && milestoneResults.data.length > 0) {
              const milestones = milestoneResults.data.filter(data => data.title.match("^[0-9]+.[0-9]+.[0-9]+.*"));
              if (milestones && milestones.length > 0) {
                const latestMilestone = milestones[0].number;
                issueNumbers.forEach(issueNumber => {
                  github.rest.issues.update({
                    owner: context.repo.owner,
                    repo: context.repo.repo,
                    issue_number: issueNumber,
                    milestone: latestMilestone,
                  });
                });
              }
            }


Label Issue

#
# 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: Label Issue

on:
  issues:
    types:
      - opened
      - reopened
      - edited

concurrency:
  group: label-issue-${{ github.event.issue.number }}
  cancel-in-progress: true

permissions:
  contents: read
  issues: write

jobs:
  label-issue:
    if: "github.repository == 'apache/camel-quarkus' &&
         !contains(github.event.issue.labels.*.name, 'autolabel/ignore') &&
         !contains(github.event.issue.labels.*.name, 'build/camel-main') &&
         !contains(github.event.issue.labels.*.name, 'build/quarkus-main')"
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
        with:
          ref: main
      - name: Install js-yaml package
        run: |
          npm install js-yaml
      - name: Label Issue
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const yaml = require('js-yaml');

            const issue = context.payload.issue;
            const labels = new Set();

            // Some common words to not directly match against
            const commonWords = ['github', 'http'];

            // Read the auto labelling configuration
            const config = yaml.load(fs.readFileSync(`./.github/auto-label-configuration.yaml`), 'utf8');

            // Lazy way of getting the names of extensions without having to search the Camel catalog etc
            const files = fs.readdirSync(`./docs/modules/ROOT/pages/reference/extensions/`);
            files.forEach(file => {
              if (!file.includes("core")) {
                let extension = file.replace(".adoc", "");

                // Build up regexes for each extension
                let regex = `\\b(?:(?:camel-)(?:quarkus-)?${extension}(?!-))\\b|\\s${extension}\\sextension`
                if (!commonWords.includes(extension)) {
                  regex += `|\\s${extension}\\s|^${extension}(?::)?\\s|\\s${extension}$`;
                }

                config['config']['auto-label'].push({
                  "regex": regex,
                  "labels": ["area/" + extension],
                  "matchOn": "title",
                });
              }
            });

            // Sanitize the issue title and body
            let sanitizedTitle = null;
            if (issue.title) {
              sanitizedTitle = issue.title.toLowerCase();
            }

            let sanitizedBody = null;
            if (issue.body) {
              // Markdown code blocks are removed, as they can provide false positives for label matching
              sanitizedBody = issue.body.toLowerCase().replace(/`{1,3}[\s\S]*?`{1,3}/g, '');
            }

            // Determine which labels should be applied to the issue
            config['config']['auto-label'].forEach(labelCandidate => {
              // Check issue title content matching configured expressions
              if (sanitizedTitle && (labelCandidate.matchOn === "title" || labelCandidate.matchOn === "titleBody")) {
                if (sanitizedTitle.match(new RegExp(labelCandidate.regex, 'gi'))) {
                  labelCandidate.labels.forEach(label => labels.add(label));
                }
              }

              // Check issue body content matching configured expressions
              if (sanitizedBody && (labelCandidate.matchOn === "body" || labelCandidate.matchOn === "titleBody")) {
                if (sanitizedBody.match(new RegExp(labelCandidate.regex, 'gi'))) {
                  labelCandidate.labels.forEach(label => labels.add(label));
                }
              }
            });

            // Filter potentially stale existing issue labels and keep any custom user added ones
            const prefixes = new Set();
            config['config']['auto-label']
              .flatMap(labelConfig => labelConfig.labels)
              .filter(label => label.includes('/'))
              .map(label => label.split('/')[0])
              .forEach(prefix => prefixes.add(prefix));

            const prefixRegex = Array.from(prefixes).join('|');
            issue.labels
              .filter(label => label.name.match("^(?!" + prefixRegex + ").*"))
              .map(label => label.name)
              .forEach(label => labels.add(label));

            // If we are not going to be adding any new labels then just exit the script
            if (labels.size === issue.labels.length) {
              const diffLabels = issue.labels.filter(label => !labels.has(label.name));
              if (diffLabels.length === 0) {
                return;
              }
            }

            // Check to see if labels already exist, and if not, create them so we can set the color
            const labelQuery = `{
              repository(owner: "${context.repo.owner}", name: "${context.repo.repo}") {
                labels(first: 50, query: "name: ${Array.from(labels).join(' || ')}") {
                  nodes {
                    name
                  }
                }
              }
            }`;

            labelQueryResults = await github.graphql(labelQuery);

            if (labelQueryResults && labelQueryResults.repository.labels) {
              const existingLabels = labelQueryResults.repository.labels.nodes.map(node => node.name);

              for (let label of labels) {
                if (!existingLabels.includes(label)) {
                  labelColor = 'ededed';
                  if (label.startsWith("area/")) {
                    labelColor = '283482';
                  }

                  if (label.startsWith("platform/")) {
                    labelColor = '7baaa4';
                  }

                  if (label.startsWith("release/")) {
                    labelColor = '947593'
                  }

                  await github.rest.issues.createLabel({
                    owner: context.repo.owner,
                    repo: context.repo.repo,
                    name: label,
                    color: labelColor,
                  });
                }
              };
            }

            // Update issue labels
            await github.rest.issues.setLabels({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: issue.number,
              labels: Array.from(labels)
            });


Assign Wontfix Issue Milestone

#
# 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: Assign Wontfix Issue Milestone

on:
  issues:
    types:
      - closed

permissions:
  issues: write

jobs:
  assign-wont-fix-issue-milestone:
    if: github.repository == 'apache/camel-quarkus' &&
        github.event_name == 'issues' &&
        github.event.issue.milestone.number != 4 && (contains(github.event.issue.labels.*.name, 'wontfix') || github.event.issue.state_reason == 'not_planned')
    runs-on: ubuntu-latest
    concurrency:
      group: assign-wont-fix-issue-milestone-${{ github.event.issue.number }}
      cancel-in-progress: true
    steps:
      - name: Assign Closed Issue To Wont Fix Milestone
        uses: actions/github-script@v7
        with:
          script: |
            await github.rest.issues.update({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.payload.issue.number,
              // https://github.com/apache/camel-quarkus/milestone/4
              milestone: 4,
            });


Prepare Next Release

name: Prepare Next Release
on:
  workflow_dispatch:
    inputs:
      release_tag:
        description: 'Release Tag'
        required: false
        type: string
env:
  GIT_USER_NAME: amplify-android-dev+ghops
  GIT_USER_EMAIL: amplify-android-dev+ghops@amazon.com
  BASE_BRANCH: ${{ github.ref_name }}
jobs:
  create_pr_for_next_release:
    runs-on: ubuntu-latest
    steps:
    - name: Update git
      run: |
        sudo add-apt-repository -y ppa:git-core/ppa
        sudo apt-get update
        sudo apt-get install git -y
    - uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2
      with:
        ref: ${{ env.BASE_BRANCH }}
        fetch-depth: 0
    - name: Set up Ruby
      uses: ruby/setup-ruby@8575951200e472d5f2d95c625da0c7bec8217c42 # v1.161.0
      with:
        ruby-version: "3.0"
    - name: Install dependencies
      run: |
        cd scripts
        gem install bundler
        bundle install --full-index
    - name: Configure git options
      run: |
        cd scripts
        bundle exec fastlane android configure_git_options git_user_email:$GIT_USER_EMAIL git_user_name:$GIT_USER_NAME
    - name: Create/checkout a branch for the release
      run: |
        branch_name=bump_version_${{ env.BASE_BRANCH }}
        git fetch --all
        (git branch -D $branch_name &>/dev/null) && (echo 'Existing $branch_name branch deleted') || (echo 'No existing $branch_name branch to delete.')
        git checkout -b $branch_name
    - name: Create PR for next release
      env:
        RELEASE_MANAGER_TOKEN: ${{secrets.GITHUB_TOKEN}}
        RELEASE_TAG: ${{ github.event.inputs.release_tag }}
      run: |
        cd scripts
        bundle exec fastlane android create_next_release_pr release_tag:"$RELEASE_TAG" base_branch:"$BASE_BRANCH"
    - name: Check modified file content
      run: |
        cat gradle.properties
        cat CHANGELOG.md
        git status


Notify Amplify Android Release

# This is a basic workflow to help you get started with Actions

name: Notify Amplify Android Release

# Controls when the workflow will run
on:
  # Triggers the workflow on release created (draft) or published (release and prerelease) events but only for the main branch
  release:
    types: [created, published]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "notify"
  notify:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Runs a single command using the runners shell
      - name: Run webhook curl command
        env:
          WEBHOOK_URL: ${{ secrets.SLACK_RELEASE_WEBHOOK_URL }}
          VERSION: ${{github.event.release.html_url}}
          REPO_URL: ${{github.event.repository.html_url}}
          ACTION_NAME: ${{github.event.action}}
        shell: bash
        run: echo $VERSION | xargs -I {} curl -s POST "$WEBHOOK_URL" -H "Content-Type:application/json" --data '{"action":"'$ACTION_NAME'", "repo":"'$REPO_URL'", "version":"{}"}'


Run code coverage

# This is a basic workflow to help you get started with Actions

name: Run code coverage

# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request events but only for the main & dev-preview branch
  push:
    branches:
      - 'main'
      - 'v1'
  pull_request:
    branches:
      - 'main'
      - 'v1'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2
      # Execute unit tests
      - name: Setup Java
        uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3
        with:
          java-version: '11'
          distribution: 'corretto'

      - name: Run test and generate kover report
        run: ./gradlew koverReport

      - name: create temp directory
        run: mkdir /home/runner/work/amplify-android/amplify-android/code-coverage

      - name: copy kover test report to temp directory
        run: cp -r /home/runner/work/amplify-android/amplify-android/**/build/reports/kover/xml/*.xml /home/runner/work/amplify-android/amplify-android/code-coverage/

      - name: Upload Test Report
        uses: codecov/codecov-action@v3
        with:
          name: report
          files: code-coverage/*.xml


Amplify Android Maven Release

name: Amplify Android Maven Release

on:
  workflow_dispatch:

permissions:
  id-token: write

jobs:
  maven-release:
    runs-on: ubuntu-latest
    steps:
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@67fbcbb121271f7775d2e7715933280b06314838 # v1
        with:
          role-to-assume: ${{ secrets.AMPLIFY_ANDROID_RELEASE_PUBLISHER_ROLE }}
          aws-region: us-east-1
      - name: Start Integration Test
        uses: aws-actions/aws-codebuild-run-build@f202c327329cbbebd13f986f74af162a8539b5fd # v1
        with:
          project-name: AmplifyAndroid-IntegrationTest
          env-vars-for-codebuild: |
            ORG_GRADLE_PROJECT_useAwsSdkReleaseBuild,
            NUMBER_OF_DEVICES_TO_TEST
        env:
          ORG_GRADLE_PROJECT_useAwsSdkReleaseBuild: true
          NUMBER_OF_DEVICES_TO_TEST: 3
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@67fbcbb121271f7775d2e7715933280b06314838 # v1
        with:
          role-to-assume: ${{ secrets.AMPLIFY_ANDROID_RELEASE_PUBLISHER_ROLE }}
          aws-region: us-east-1
      - name: Start Maven Release Build
        uses: aws-actions/aws-codebuild-run-build@f202c327329cbbebd13f986f74af162a8539b5fd # v1
        with:
          project-name: AmplifyAndroid-ReleasePublisher


Rollback Release

name: Rollback Release

on:
  workflow_dispatch:
    inputs:
      branch_from:
        description: 'The known good version to re-release (e.g. 2.9.1)'
        required: true
      deprecated_version:
        description: 'The version you are rolling back (e.g. 2.9.2)'
        required: true
      new_version:
        description: 'The new version number (e.g. 2.9.3)'
        required: true

env:
  AWS_REGION: "us-east-1"
  BRANCH_FROM: ${{ inputs.branch_from }}
  DEPRECATED_VERSION: ${{ inputs.deprecated_version }}
  NEW_VERSION: ${{ inputs.new_version }}
  CI_COMMIT_MESSAGE: Re-release v${{ inputs.branch_from }} as v${{ inputs.new_version }}
  ROLLBACK_BRANCH: rollback_${{ inputs.deprecated_version }}
  NEW_TAG: release_v${{ inputs.new_version }}

jobs:
  create-rollback-branch:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: write
    steps:
      - name: Checkout Source Code
        uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
        with:
          ref: ${{ format('release_v{0}', env.BRANCH_FROM) }}
          token: ${{ secrets.GH_WORKFLOW_TOKEN }}
      - name: Create Rollback Branch
        run: git checkout -b ${{ env.ROLLBACK_BRANCH }}
      - name: Update Version
        run: |
          git config --global user.email 41898282+github-actions[bot]@users.noreply.github.com
          git config --global user.name github-actions[bot]
          sed -i 's/VERSION_NAME=${{ env.BRANCH_FROM }}/VERSION_NAME=${{ env.NEW_VERSION }}/g' gradle.properties
          echo -e '## [Release ${{ env.NEW_VERSION }}](https://github.com/${{ github.repository }}/releases/tag/${{ env.NEW_TAG }})\n\nThis is a re-release of version ${{ env.BRANCH_FROM }}. Use this instead of version ${{ env.DEPRECATED_VERSION }}.\n' | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md
          git add gradle.properties
          git add CHANGELOG.md
          git commit -m "${{ env.CI_COMMIT_MESSAGE }}"
      - name: Tag Version
        run: git tag "${{ env.NEW_TAG }}"
      - name: Push Changes
        run: git push --atomic origin ${{ env.ROLLBACK_BRANCH }} ${{ env.NEW_TAG }}

  publish-rollback:
    needs: create-rollback-branch
    runs-on: ubuntu-latest
    permissions:
      id-token: write
    steps:
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 #2.2.0
        with:
          role-to-assume: ${{ secrets.AMPLIFY_ANDROID_RELEASE_PUBLISHER_ROLE }}
          aws-region: ${{ env.AWS_REGION }}
      - name: Start Maven Release Build
        uses: aws-actions/aws-codebuild-run-build@2a49e1faf172677d80ce658678e9ff8bd2737d74 #1.0.15
        with:
          project-name: AmplifyAndroid-ReleasePublisher-V2
          source-version-override: ${{ env.NEW_TAG }}


Notify Pull Request

name: Notify Pull Request

on:
  pull_request:
    types: [opened, ready_for_review, reopened]

jobs:
  notify:
    runs-on: ubuntu-latest
    if: ${{ !github.event.draft }}
    steps:
      - name: Run webhook curl command
        env:
          WEBHOOK_URL: ${{ secrets.SLACK_PR_WEBHOOK_URL }}
          URL: ${{ github.event.pull_request.html_url }}
          TITLE: ${{ github.event.pull_request.title }}
          USER: ${{ github.event.pull_request.user.login }}
        shell: bash
        run: curl -s POST "$WEBHOOK_URL" -H "Content-Type:application/json" --data "{\"url\":\"$URL\", \"title\":\"$TITLE\", \"user\":\"$USER\"}"


Issue Closed

name: Issue Closed

on:
  issues:
    types: [closed]

permissions:
  issues: write

jobs:
  cleanup-labels:
    runs-on: ubuntu-latest
    if: ${{ (contains(github.event.issue.labels.*.name, 'pending-response') || contains(github.event.issue.labels.*.name, 'closing soon') || contains(github.event.issue.labels.*.name, 'pending-release')|| contains(github.event.issue.labels.*.name, 'pending-triage')) }}
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1
      - name: remove unnecessary labels after closing
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          ISSUE_NUMBER: ${{ github.event.issue.number }}
        run: |
          gh issue edit $ISSUE_NUMBER --remove-label "closing soon" --remove-label "pending-response" --remove-label "pending-release" --remove-label "pending-triage"

  comment-visibility-warning:
    runs-on: ubuntu-latest
    steps:
      - uses: aws-actions/closed-issue-message@36b7048ea77bb834d16e7a7c5b5471ac767a4ca1 # v1
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          message: |
              This issue is now closed. Comments on closed issues are hard for our team to see.
              If you need more assistance, please open a new issue that references this one.


Issue Comment

name: Issue Comment

on:
  issue_comment:
    types: [created]

jobs:
  notify:
    runs-on: ubuntu-latest
    permissions: {}
    if: ${{ !github.event.issue.pull_request }}
    steps:
      - name: Run webhook curl command
        env:
          WEBHOOK_URL: ${{ secrets.SLACK_COMMENT_WEBHOOK_URL }}
          BODY: ${{ toJson(github.event.comment.body) }}
          COMMENT_URL: ${{ github.event.comment.html_url }}
          USER: ${{ github.event.comment.user.login }}
        shell: bash
        run: echo $BODY | xargs -I {} curl -s POST "$WEBHOOK_URL" -H "Content-Type:application/json" --data '{"body":"{}", "issue":"'$COMMENT_URL'", "user":"'$USER'"}'

  remove-pending-response-label:
    runs-on: ubuntu-latest
    permissions:
      issues: write
    if: ${{ !github.event.issue.pull_request && contains(github.event.issue.labels.*.name, 'pending-response') }}
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1
      - name: remove unnecessary labels after closing
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          ISSUE_NUMBER: ${{ github.event.issue.number }}
        run: |
          gh issue edit $ISSUE_NUMBER --remove-label "pending-response"


Issue Labeled

name: Issue Labeled
on:
  issues:
    types: [labeled]

jobs:
  remove-pending-triage-label:
    runs-on: ubuntu-latest
    if: ${{ contains(fromJSON('["question", "bug", "feature-request", "improvement"]'), github.event.label.name) }}
    permissions:
      issues: write
    steps:
      - name: Remove the pending-triage label
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          ISSUE_NUMBER: ${{ github.event.issue.number }}
          REPOSITORY_NAME: ${{ github.event.repository.full_name }}
        run: |
          gh issue edit $ISSUE_NUMBER --repo $REPOSITORY_NAME --remove-label "pending-triage"


Issue Opened

name: Issue Opened
on:
  issues:
    types: [opened]

jobs:
  notify:
    runs-on: ubuntu-latest
    permissions: {}
    if: ${{ !contains(fromJSON('["MEMBER", "OWNER"]'), github.event.issue.author_association) }}
    steps:
      - name: Run webhook curl command
        env:
          WEBHOOK_URL: ${{ secrets.SLACK_ISSUE_WEBHOOK_URL }}
          ISSUE: ${{toJson(github.event.issue.title)}}
          ISSUE_URL: ${{github.event.issue.html_url}}
          USER: ${{github.event.issue.user.login}}
        shell: bash
        run: echo $ISSUE | sed 's/[^a-zA-Z0-9 &().,:]//g' | xargs -I {} curl -s POST "$WEBHOOK_URL" -H "Content-Type:application/json" --data '{"issue":"{}", "issueUrl":"'$ISSUE_URL'", "user":"'$USER'"}'

  add-pending-triage-label:
    runs-on: ubuntu-latest
    permissions:
      issues: write
    steps:
      - name: Add the pending-triage label
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          ISSUE_NUMBER: ${{ github.event.issue.number }}
          REPOSITORY_NAME: ${{ github.event.repository.full_name }}
        run: |
          gh issue edit $ISSUE_NUMBER --repo $REPOSITORY_NAME --add-label "pending-triage"

  maintainer-opened:
    runs-on: ubuntu-latest
    permissions:
      issues: write
    if: ${{ contains(fromJSON('["MEMBER", "OWNER"]'), github.event.issue.author_association) }}
    steps:
      - name: Post comment if maintainer opened.
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          ISSUE_NUMBER: ${{ github.event.issue.number }}
          REPOSITORY_NAME: ${{ github.event.repository.full_name }}
        run: |
          gh issue comment $ISSUE_NUMBER --repo $REPOSITORY_NAME -b "This issue was opened by a maintainer of this repository; updates will be posted here. If you are also experiencing this issue, please comment here with any relevant information so that we're aware and can prioritize accordingly."


Close stale issues

name: "Close stale issues"

on:
  schedule:
  - cron: "30 1 * * *"

jobs:
  stale:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/stale@a20b814fb01b71def3bd6f56e7494d667ddf28da # v4
      with:
        repo-token: ${{ secrets.GITHUB_TOKEN }}
        operations-per-run: 200
        stale-issue-message: "This issue is stale since it's been open 30 days with no activity. This will be closed in 7 days unless the `Closing Soon` label is removed or a comment is added. Thank you for your contributions."
        close-issue-message: "This issue was closed since it's been 7 days with no activity."
        stale-issue-label: "closing soon"
        debug-only: true
        days-before-stale: 30
        days-before-close: 7
        # PRs wont go stale
        days-before-pr-stale: -1
        # Issues with any of these labels are checked.
        any-of-labels: "pending-response, closing soon"


PR Title Checker

# Runs a check to verify PRs have a valid title

name: "PR Title Checker"
on:
  pull_request_target:
    types:
      - opened
      - edited
      - synchronize
      - labeled
      - unlabeled

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: thehanimo/pr-title-checker@v1.3.5
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          pass_on_octokit_error: false
          configuration_path: ".github/pr-title-checker-config.json"


GitHub Event Processor

name: GitHub Event Processor

on:
  issues:
    types: [edited, labeled, opened, reopened, unlabeled]
  # issue_comment is used for both issues and pull_requests
  # github.event.issue.pull_request will be non-null on pull request comments
  issue_comment:
    types: [created]
  # synchronize is the pull_request_target event when changes are pushed
  # pull request merged is the closed event with github.event.pull_request.merged = true
  pull_request_target:
    types: [closed, labeled, opened, reopened, review_requested, synchronize, unlabeled]

# This removes all unnecessary permissions, the ones needed will be set below.
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions: {}

jobs:
  # This event requires the Azure CLI to get the LABEL_SERVICE_API_KEY from the vault.
  # Because the azure/login step adds time costly pre/post Az CLI commands to any every job
  # it's used in, split this into its own job so only the event that needs the Az CLI pays
  # the cost.
  event-handler-with-azure:
    permissions:
      issues: write
      pull-requests: write
      # For OIDC auth
      id-token: write
      contents: read
    name: Handle ${{ github.event_name }} ${{ github.event.action }} event with azure login
    runs-on: ubuntu-latest
    if: ${{ github.event_name == 'issues' && github.event.action == 'opened' }}
    steps:
      - name: 'Az CLI login'
        uses: azure/login@v2
        with:
            client-id: ${{ secrets.AZURE_CLIENT_ID }}
            tenant-id: ${{ secrets.AZURE_TENANT_ID }}
            subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

      - name: 'Run Azure CLI commands'
        run: |
          LABEL_SERVICE_API_KEY=$(az keyvault secret show \
            --vault-name issue-labeler \
            -n issue-labeler-func-key \
            -o tsv \
            --query value)

          echo "::add-mask::$LABEL_SERVICE_API_KEY"
          echo "LABEL_SERVICE_API_KEY=$LABEL_SERVICE_API_KEY" >> $GITHUB_ENV

      # To run github-event-processor built from source, for testing purposes, uncomment everything
      # in between the Start/End-Build From Source comments and comment everything in between the
      # Start/End-Install comments
      # Start-Install
      - name: Install GitHub Event Processor
        run: >
          dotnet tool install
          Azure.Sdk.Tools.GitHubEventProcessor
          --version 1.0.0-dev.20240610.2
          --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json
          --global
        shell: bash
      # End-Install

      # Testing checkout of sources from the Azure/azure-sdk-tools repository
      # The ref: is the SHA from the pull request in that repository or the
      # refs/pull/<PRNumber>/merge for the latest on any given PR. If the repository
      # is a fork eg. <User>/azure-sdk-tools then the repository down below will
      # need to point to that fork
      # Start-Build
      # - name: Checkout tools repo for GitHub Event Processor sources
      #   uses: actions/checkout@v3
      #   with:
      #     repository: Azure/azure-sdk-tools
      #     path: azure-sdk-tools
      #     ref: <refs/pull/<PRNumber>/merge> or <sha>

      # - name: Build and install GitHubEventProcessor from sources
      #   run: |
      #     dotnet pack
      #     dotnet tool install --global --prerelease --add-source ../../../artifacts/packages/Debug Azure.Sdk.Tools.GitHubEventProcessor
      #   shell: bash
      #   working-directory: azure-sdk-tools/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor
      # End-Build

      - name: Process Action Event
        run: |
          cat > payload.json << 'EOF'
          ${{ toJson(github.event) }}
          EOF
          github-event-processor ${{ github.event_name }} payload.json
        shell: bash
        env:
          # This is a temporary secret generated by github
          # https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          LABEL_SERVICE_API_KEY: ${{ env.LABEL_SERVICE_API_KEY }}

  event-handler:
    permissions:
      issues: write
      pull-requests: write
    name: Handle ${{ github.event_name }} ${{ github.event.action }} event
    runs-on: ubuntu-latest
    if: ${{ github.event_name != 'issues' || github.event.action != 'opened' }}
    steps:
      # To run github-event-processor built from source, for testing purposes, uncomment everything
      # in between the Start/End-Build From Source comments and comment everything in between the
      # Start/End-Install comments
      # Start-Install
      - name: Install GitHub Event Processor
        run: >
          dotnet tool install
          Azure.Sdk.Tools.GitHubEventProcessor
          --version 1.0.0-dev.20240610.2
          --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json
          --global
        shell: bash
      # End-Install

      # Testing checkout of sources from the Azure/azure-sdk-tools repository
      # The ref: is the SHA from the pull request in that repository or the
      # refs/pull/<PRNumber>/merge for the latest on any given PR. If the repository
      # is a fork eg. <User>/azure-sdk-tools then the repository down below will
      # need to point to that fork
      # Start-Build
      # - name: Checkout tools repo for GitHub Event Processor sources
      #   uses: actions/checkout@v3
      #   with:
      #     repository: Azure/azure-sdk-tools
      #     path: azure-sdk-tools
      #     ref: <refs/pull/<PRNumber>/merge> or <sha>

      # - name: Build and install GitHubEventProcessor from sources
      #   run: |
      #     dotnet pack
      #     dotnet tool install --global --prerelease --add-source ../../../artifacts/packages/Debug Azure.Sdk.Tools.GitHubEventProcessor
      #   shell: bash
      #   working-directory: azure-sdk-tools/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor
      # End-Build

      - name: Process Action Event
        run: |
          cat > payload.json << 'EOF'
          ${{ toJson(github.event) }}
          EOF
          github-event-processor ${{ github.event_name }} payload.json
        shell: bash
        env:
          # This is a temporary secret generated by github
          # https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


Check Enforcer

# NOTE: currently azure-sdk-actions only hosts check enforcer code.
# If further functionality is added, this name should be updated to reflect
# the more generic behavior
name: Check Enforcer

on:
  check_suite:
    types: [completed]
  issue_comment:
    types: [created]

permissions: {}

jobs:
  event-handler:
    permissions:
      statuses: write # to set status (azure/azure-sdk-actions)
      pull-requests: write # to read pull requests and write comments (azure/azure-sdk-actions)
      checks: read # to read check status (azure/azure-sdk-actions)
    name: Handle ${{ github.event_name }} ${{ github.event.action }} event
    runs-on: ubuntu-latest
    steps:
      - uses: azure/azure-sdk-actions@main
        with:
          token: ${{ secrets.GITHUB_TOKEN }}


Javascript SDK Release Tool Pull Request Check