|
| 1 | +name: Reusable Workflow |
| 2 | + |
| 3 | +env: |
| 4 | + MAVEN_VERSION: '3.9.12' |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_call: |
| 8 | + inputs: |
| 9 | + deploy-snapshot: |
| 10 | + required: true |
| 11 | + type: boolean |
| 12 | + default: false |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + name: Build (Java ${{ matrix.java-version }}) |
| 17 | + runs-on: ubuntu-latest |
| 18 | + timeout-minutes: 30 |
| 19 | + strategy: |
| 20 | + matrix: |
| 21 | + java-version: [ 17, 21 ] |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v6 |
| 25 | + with: |
| 26 | + # For internal PRs (same repo), checkout PR head to test actual changes |
| 27 | + # For external PRs (forks), checkout base branch for security |
| 28 | + ref: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.sha || github.sha }} |
| 29 | + |
| 30 | + - name: Spotless check |
| 31 | + run: mvn spotless:check -Dspotless.check.skip=false |
| 32 | + |
| 33 | + - name: Build |
| 34 | + uses: ./.github/actions/build |
| 35 | + with: |
| 36 | + java-version: ${{ matrix.java-version }} |
| 37 | + maven-version: ${{ env.MAVEN_VERSION }} |
| 38 | + |
| 39 | + - name: Upload build artifacts |
| 40 | + uses: actions/upload-artifact@v7 |
| 41 | + with: |
| 42 | + name: build-artifacts-java-${{ matrix.java-version }} |
| 43 | + path: | |
| 44 | + **/target/*.jar |
| 45 | + **/pom.xml |
| 46 | + .mvn/ |
| 47 | + retention-days: 1 |
| 48 | + |
| 49 | + integration-tests: |
| 50 | + name: Integration Tests (Java ${{ matrix.java-version }}, ${{ matrix.test-type }}) |
| 51 | + runs-on: ubuntu-latest |
| 52 | + timeout-minutes: 30 |
| 53 | + needs: build |
| 54 | + #env: |
| 55 | + # cf login for tests against aicore |
| 56 | + strategy: |
| 57 | + fail-fast: false |
| 58 | + matrix: |
| 59 | + java-version: [ 17, 21 ] |
| 60 | + test-type: [ build-version, latest-version, oss ] |
| 61 | + steps: |
| 62 | + - name: Checkout |
| 63 | + uses: actions/checkout@v6 |
| 64 | + with: |
| 65 | + ref: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.sha || github.sha }} |
| 66 | + |
| 67 | + - name: Download build artifacts |
| 68 | + uses: actions/download-artifact@v8 |
| 69 | + with: |
| 70 | + name: build-artifacts-java-${{ matrix.java-version }} |
| 71 | + |
| 72 | + sonarqube-scan: |
| 73 | + name: SonarQube Scan |
| 74 | + runs-on: ubuntu-latest |
| 75 | + timeout-minutes: 30 |
| 76 | + needs: build |
| 77 | + steps: |
| 78 | + - name: Checkout |
| 79 | + uses: actions/checkout@v6 |
| 80 | + with: |
| 81 | + ref: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.sha || github.sha }} |
| 82 | + - name: SonarQube Scan |
| 83 | + uses: ./.github/actions/scan-with-sonar |
| 84 | + with: |
| 85 | + java-version: 17 |
| 86 | + maven-version: ${{ env.MAVEN_VERSION }} |
| 87 | + sonarq-token: ${{ secrets.SONARQ_TOKEN }} |
| 88 | + github-token: ${{ secrets.GH_TOKEN }} |
| 89 | + |
| 90 | + codeql: |
| 91 | + name: CodeQL Analysis |
| 92 | + runs-on: ubuntu-latest |
| 93 | + needs: build |
| 94 | + timeout-minutes: 30 |
| 95 | + permissions: |
| 96 | + security-events: write |
| 97 | + packages: read |
| 98 | + actions: read |
| 99 | + contents: read |
| 100 | + steps: |
| 101 | + - name: Checkout repository |
| 102 | + uses: actions/checkout@v6 |
| 103 | + with: |
| 104 | + ref: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.sha || github.sha }} |
| 105 | + |
| 106 | + - name: Set up Java |
| 107 | + uses: actions/setup-java@v5 |
| 108 | + with: |
| 109 | + java-version: '17' |
| 110 | + distribution: 'sapmachine' |
| 111 | + cache: 'maven' |
| 112 | + |
| 113 | + - name: Initialize CodeQL |
| 114 | + uses: github/codeql-action/init@v4 |
| 115 | + with: |
| 116 | + languages: java-kotlin |
| 117 | + build-mode: manual |
| 118 | + |
| 119 | + - name: Build Java code |
| 120 | + run: mvn clean compile -DskipTests -B -ntp |
| 121 | + |
| 122 | + - name: Perform CodeQL Analysis |
| 123 | + uses: github/codeql-action/analyze@v4 |
| 124 | + with: |
| 125 | + category: "/language:java-kotlin" |
| 126 | + |
| 127 | + deploy-snapshot: |
| 128 | + name: Deploy snapshot to Artifactory |
| 129 | + runs-on: ubuntu-latest |
| 130 | + timeout-minutes: 30 |
| 131 | + if: ${{ inputs.deploy-snapshot == true }} |
| 132 | + needs: [build, integration-tests, codeql] |
| 133 | + steps: |
| 134 | + - name: Checkout |
| 135 | + uses: actions/checkout@v6 |
| 136 | + with: |
| 137 | + ref: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.sha || github.sha }} |
| 138 | + |
| 139 | + - name: Set up Java |
| 140 | + uses: actions/setup-java@v5 |
| 141 | + with: |
| 142 | + java-version: '17' |
| 143 | + distribution: 'sapmachine' |
| 144 | + cache: 'maven' |
| 145 | + server-id: artifactory |
| 146 | + server-username: DEPLOYMENT_USER |
| 147 | + server-password: DEPLOYMENT_PASS |
| 148 | + |
| 149 | + - name: Set up Maven ${{ env.MAVEN_VERSION }} |
| 150 | + uses: stCarolas/setup-maven@v5 |
| 151 | + with: |
| 152 | + maven-version: ${{ env.MAVEN_VERSION }} |
| 153 | + |
| 154 | + - name: Set Dry Run for Pull Request |
| 155 | + if: github.event_name == 'pull_request_target' |
| 156 | + run: echo "DRY_RUN_PARAM=-DaltDeploymentRepository=local-repo::default::file:./local-repo" >> $GITHUB_ENV |
| 157 | + shell: bash |
| 158 | + |
| 159 | + - name: Get Revision |
| 160 | + id: get-revision |
| 161 | + run: | |
| 162 | + echo "REVISION=$(mvn help:evaluate -Dexpression=revision -q -DforceStdout)" >> $GITHUB_OUTPUT |
| 163 | + shell: bash |
| 164 | + |
| 165 | + - name: Print Revision |
| 166 | + run: echo "Current revision ${{ steps.get-revision.outputs.REVISION }}" |
| 167 | + shell: bash |
| 168 | + |
| 169 | + - name: Deploy snapshot |
| 170 | + if: ${{ endsWith(steps.get-revision.outputs.REVISION, '-SNAPSHOT') }} |
| 171 | + run: mvn -B -ntp -fae -pl !integration-tests,!integration-tests/db,!integration-tests/generic,!integration-tests/mtx-local/srv -Dmaven.install.skip=true -Dmaven.test.skip=true -DdeployAtEnd=true deploy |
| 172 | + env: |
| 173 | + DEPLOYMENT_USER: ${{ secrets.DEPLOYMENT_USER }} |
| 174 | + DEPLOYMENT_PASS: ${{ secrets.DEPLOYMENT_PASS }} |
| 175 | + shell: bash |
0 commit comments