|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +# contributor license agreements. See the NOTICE file distributed with |
| 4 | +# this work for additional information regarding copyright ownership. |
| 5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +# (the "License"); you may not use this file except in compliance with |
| 7 | +# the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +name: Build Kroxylicious Operator |
| 18 | + |
| 19 | +on: |
| 20 | + push: |
| 21 | + branches: [ main ] |
| 22 | + pull_request: |
| 23 | + types: [ opened, synchronize, reopened ] |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 27 | + cancel-in-progress: true |
| 28 | + |
| 29 | +jobs: |
| 30 | + build: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: 'Test for Sonar secret' |
| 35 | + env: |
| 36 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 37 | + run: | |
| 38 | + echo "SONAR_TOKEN_SET=$(test ${SONAR_TOKEN} && echo true)" >> $GITHUB_ENV |
| 39 | + - name: 'Check out repository' |
| 40 | + uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + submodules: 'true' |
| 43 | + fetch-depth: 0 |
| 44 | + - name: Set up QEMU |
| 45 | + uses: docker/setup-qemu-action@v3 |
| 46 | + - name: 'Set up Java' |
| 47 | + uses: actions/setup-java@v4 |
| 48 | + with: |
| 49 | + java-version: 21 |
| 50 | + distribution: 'temurin' |
| 51 | + - name: Setup Minikube |
| 52 | + uses: manusa/actions-setup-minikube@v2.13.1 |
| 53 | + with: |
| 54 | + "minikube version": 'v1.35.0' |
| 55 | + "kubernetes version": 'v1.32.0' |
| 56 | + "github token": ${{ secrets.GITHUB_TOKEN }} |
| 57 | + driver: docker |
| 58 | + - name: Cache SonarCloud packages |
| 59 | + uses: actions/cache@v4 |
| 60 | + if: github.ref_name == 'main' || env.SONAR_TOKEN_SET == 'true' |
| 61 | + with: |
| 62 | + path: ~/.sonar/cache |
| 63 | + key: ${{ runner.os }}-sonar |
| 64 | + restore-keys: ${{ runner.os }}-sonar |
| 65 | + - name: 'Cache Maven packages' |
| 66 | + uses: actions/cache@v4 |
| 67 | + with: |
| 68 | + path: ~/.m2 |
| 69 | + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} |
| 70 | + restore-keys: ${{ runner.os }}-m2 |
| 71 | + - name: 'Build & unit test Kroxylicious operator' |
| 72 | + env: |
| 73 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 74 | + run: | |
| 75 | + GIT_HASH="$(git rev-parse HEAD)" |
| 76 | + IMAGE_TAG="dev-git-${GIT_HASH}" |
| 77 | + KROXYLICIOUS_VERSION="$(mvn org.apache.maven.plugins:maven-help-plugin:3.4.0:evaluate -Dexpression=project.version -q -DforceStdout)" |
| 78 | + KROXYLICIOUS_IMAGE="quay.io/kroxylicious/kroxylicious:${IMAGE_TAG}" |
| 79 | + echo "KROXYLICIOUS_VERSION=${KROXYLICIOUS_VERSION}" >> "$GITHUB_ENV" |
| 80 | + # KROXYLICIOUS_IMAGE env var is used by the Operator ITs |
| 81 | + echo "KROXYLICIOUS_IMAGE=${KROXYLICIOUS_IMAGE}" >> "$GITHUB_ENV" |
| 82 | + # make sure everything is built and compiles |
| 83 | + mvn -B install -DskipTests -Pci -Djapicmp.skip=${REFERENCE_RELEASE_UNPUBLISHED} -pl ':kroxylicious-operator' -am |
| 84 | + # now run just the operator unit tests. |
| 85 | + mvn -B verify -DskipITs -Pci -Djapicmp.skip=${REFERENCE_RELEASE_UNPUBLISHED} -pl ':kroxylicious-operator' |
| 86 | + - name: 'Set up Docker Buildx' |
| 87 | + uses: docker/setup-buildx-action@v3 |
| 88 | + - name: 'Build tagged Docker image' |
| 89 | + uses: docker/build-push-action@v6 |
| 90 | + with: |
| 91 | + file: Dockerfile |
| 92 | + context: . |
| 93 | + build-args: |
| 94 | + KROXYLICIOUS_VERSION=${{ env.KROXYLICIOUS_VERSION }} |
| 95 | + tags: ${{ env.KROXYLICIOUS_IMAGE }} |
| 96 | + push: false |
| 97 | + cache-from: type=gha |
| 98 | + cache-to: type=gha,mode=max,compression=zstd |
| 99 | + load: 'true' |
| 100 | + - name: 'Load Kroxylicious Image in Minikube' |
| 101 | + run: minikube image load ${{ env.KROXYLICIOUS_IMAGE }} |
| 102 | + - name: 'Run Kroxylicious operator integration tests' |
| 103 | + if: github.ref_name != 'main' || env.SONAR_TOKEN_SET != 'true' |
| 104 | + env: |
| 105 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + run: mvn -B verify -Pci -Djapicmp.skip=${REFERENCE_RELEASE_UNPUBLISHED} -DskipUTs -pl ':kroxylicious-operator' |
| 107 | + - name: 'Build Kroxylicious maven project on main with Sonar' |
| 108 | + if: github.event_name == 'push' && github.ref_name == 'main' && env.SONAR_TOKEN_SET == 'true' |
| 109 | + env: |
| 110 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 111 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + run: mvn -B verify -Pci -Djapicmp.skip=${REFERENCE_RELEASE_UNPUBLISHED} org.sonarsource.scanner.maven:sonar-maven-plugin:5.0.0.4389:sonar -Dsonar.projectKey=kroxylicious_kroxylicious -pl ':kroxylicious-operator' |
0 commit comments