|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 2 | +# contributor license agreements. See the NOTICE file distributed with |
| 3 | +# this work for additional information regarding copyright ownership. |
| 4 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 5 | +# (the "License"); you may not use this file except in compliance with |
| 6 | +# the License. You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# This reusable workflow executes a single check from `dev-support/checks/`. |
| 17 | +# Before and after the check, it performs various steps based on workflow inputs. |
| 18 | + |
| 19 | +name: ci-check |
| 20 | + |
| 21 | +on: |
| 22 | + workflow_call: |
| 23 | + inputs: |
| 24 | + # REQUIRED |
| 25 | + script: |
| 26 | + type: string |
| 27 | + description: "Test script to run from dev-support/checks, without .sh extension" |
| 28 | + required: true |
| 29 | + |
| 30 | + # OPTIONAL (ordered alphabetically) |
| 31 | + java-version: |
| 32 | + type: string |
| 33 | + description: "Java version to set up (default: 8)" |
| 34 | + default: '8' |
| 35 | + required: false |
| 36 | + |
| 37 | + needs-binary-tarball: |
| 38 | + type: boolean |
| 39 | + description: "Whether to download Ratis binary tarball created by build (default: no)" |
| 40 | + default: false |
| 41 | + required: false |
| 42 | + |
| 43 | + needs-maven-repo: |
| 44 | + type: boolean |
| 45 | + description: "Whether to download Ratis jars created by build (default: no)" |
| 46 | + default: false |
| 47 | + required: false |
| 48 | + |
| 49 | + needs-source-tarball: |
| 50 | + type: boolean |
| 51 | + description: "Whether to download Ratis source tarball created by build (default: no)" |
| 52 | + default: false |
| 53 | + required: false |
| 54 | + |
| 55 | + runner: |
| 56 | + type: string |
| 57 | + description: "GitHub Actions runner to use" |
| 58 | + default: 'ubuntu-20.04' |
| 59 | + required: false |
| 60 | + |
| 61 | + script-args: |
| 62 | + type: string |
| 63 | + description: "Arguments for the test script" |
| 64 | + default: '' |
| 65 | + required: false |
| 66 | + |
| 67 | + split: |
| 68 | + type: string |
| 69 | + description: "Name of split for matrix jobs, only used in display name" |
| 70 | + default: '' |
| 71 | + required: false |
| 72 | + |
| 73 | + timeout-minutes: |
| 74 | + type: number |
| 75 | + description: "Job timeout in minutes (default: 30)" |
| 76 | + default: 30 |
| 77 | + required: false |
| 78 | + |
| 79 | +env: |
| 80 | + MAVEN_ARGS: --batch-mode --show-version |
| 81 | + MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 |
| 82 | + WITH_COVERAGE: true |
| 83 | + |
| 84 | +jobs: |
| 85 | + check: |
| 86 | + name: ${{ (inputs.split && format('{0} ({1})', inputs.script, inputs.split)) || inputs.script }} |
| 87 | + runs-on: ${{ inputs.runner }} |
| 88 | + timeout-minutes: ${{ inputs.timeout-minutes }} |
| 89 | + steps: |
| 90 | + - name: Checkout project |
| 91 | + if: ${{ !inputs.needs-source-tarball }} |
| 92 | + uses: actions/checkout@v4 |
| 93 | + |
| 94 | + - name: Download source tarball |
| 95 | + if: ${{ inputs.needs-source-tarball }} |
| 96 | + uses: actions/download-artifact@v4 |
| 97 | + with: |
| 98 | + name: ratis-src |
| 99 | + |
| 100 | + - name: Extract source tarball |
| 101 | + if: ${{ inputs.needs-source-tarball }} |
| 102 | + run: | |
| 103 | + tar --strip-components 1 -xzvf ratis*-src.tar.gz |
| 104 | +
|
| 105 | + - name: Create cache for Maven dependencies |
| 106 | + if: ${{ inputs.script == 'build' }} |
| 107 | + uses: actions/cache@v4 |
| 108 | + with: |
| 109 | + path: | |
| 110 | + ~/.m2/repository/*/*/* |
| 111 | + !~/.m2/repository/org/apache/ratis |
| 112 | + key: maven-repo-${{ hashFiles('**/pom.xml') }} |
| 113 | + restore-keys: | |
| 114 | + maven-repo- |
| 115 | +
|
| 116 | + - name: Restore cache for Maven dependencies |
| 117 | + if: ${{ inputs.script != 'build' }} |
| 118 | + uses: actions/cache/restore@v4 |
| 119 | + with: |
| 120 | + path: | |
| 121 | + ~/.m2/repository/*/*/* |
| 122 | + !~/.m2/repository/org/apache/ratis |
| 123 | + key: maven-repo-${{ hashFiles('**/pom.xml') }} |
| 124 | + restore-keys: | |
| 125 | + maven-repo- |
| 126 | +
|
| 127 | + - name: Download Maven repo |
| 128 | + id: download-maven-repo |
| 129 | + if: ${{ inputs.needs-maven-repo }} |
| 130 | + uses: actions/download-artifact@v4 |
| 131 | + with: |
| 132 | + name: maven-repo |
| 133 | + path: | |
| 134 | + ~/.m2/repository/org/apache/ratis |
| 135 | +
|
| 136 | + - name: Download binary tarball |
| 137 | + if: ${{ inputs.needs-binary-tarball }} |
| 138 | + uses: actions/download-artifact@v4 |
| 139 | + with: |
| 140 | + name: ratis-bin |
| 141 | + |
| 142 | + - name: Extract binary tarball |
| 143 | + if: ${{ inputs.needs-binary-tarball }} |
| 144 | + run: | |
| 145 | + mkdir -p ratis-assembly/target |
| 146 | + tar xzvf ratis-*-bin.tar.gz -C ratis-assembly/target |
| 147 | +
|
| 148 | + - name: Setup java ${{ inputs.java-version }} |
| 149 | + if: ${{ inputs.java-version }} |
| 150 | + uses: actions/setup-java@v4 |
| 151 | + with: |
| 152 | + distribution: 'temurin' |
| 153 | + java-version: ${{ inputs.java-version }} |
| 154 | + |
| 155 | + - name: Execute tests |
| 156 | + run: | |
| 157 | + dev-support/checks/${{ inputs.script }}.sh ${{ inputs.script-args }} |
| 158 | + env: |
| 159 | + WITH_COVERAGE: ${{ inputs.with-coverage }} |
| 160 | + |
| 161 | + - name: Summary of failures |
| 162 | + if: ${{ failure() }} |
| 163 | + run: | |
| 164 | + if [[ -s "target/${{ inputs.script }}/summary.txt" ]]; then |
| 165 | + cat target/${{ inputs.script }}/summary.txt |
| 166 | + fi |
| 167 | +
|
| 168 | + - name: Archive build results |
| 169 | + if: ${{ !cancelled() }} |
| 170 | + uses: actions/upload-artifact@v4 |
| 171 | + with: |
| 172 | + name: ${{ (inputs.split && format('{0}-{1}', inputs.script, inputs.split)) || inputs.script }} |
| 173 | + path: target/${{ inputs.script }} |
| 174 | + continue-on-error: true |
| 175 | + |
| 176 | + # The following steps are hard-coded to be run only for 'build' check, |
| 177 | + # to avoid the need for 3 more inputs. |
| 178 | + - name: Store binaries for tests |
| 179 | + if: ${{ inputs.script == 'build' && !cancelled() }} |
| 180 | + uses: actions/upload-artifact@v4 |
| 181 | + with: |
| 182 | + name: ratis-bin |
| 183 | + path: | |
| 184 | + ratis-assembly/target/ratis-assembly-*-bin.tar.gz |
| 185 | + retention-days: 1 |
| 186 | + |
| 187 | + - name: Store source tarball for compilation |
| 188 | + if: ${{ inputs.script == 'build' && !cancelled() }} |
| 189 | + uses: actions/upload-artifact@v4 |
| 190 | + with: |
| 191 | + name: ratis-src |
| 192 | + path: | |
| 193 | + ratis-assembly/target/ratis-assembly-*-src.tar.gz |
| 194 | + retention-days: 1 |
| 195 | + |
| 196 | + - name: Store Maven repo for tests |
| 197 | + if: ${{ inputs.script == 'build' && !cancelled() }} |
| 198 | + uses: actions/upload-artifact@v4 |
| 199 | + with: |
| 200 | + name: maven-repo |
| 201 | + path: | |
| 202 | + ~/.m2/repository/org/apache/ratis |
| 203 | + retention-days: 1 |
0 commit comments