|
| 1 | +name: OnMergeRelease |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'main' |
| 7 | + - 'release/*' |
| 8 | + tags: |
| 9 | + - '**' |
| 10 | + |
| 11 | +permissions: read-all |
| 12 | + |
| 13 | +jobs: |
| 14 | + setup: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + runner: ${{ steps.step1.outputs.runner }} |
| 18 | + steps: |
| 19 | + - name: Check repository |
| 20 | + id: step1 |
| 21 | + run: | |
| 22 | + if [ ${{ github.repository }} == 'intel/trustauthority-client-for-java' ]; then |
| 23 | + echo "runner=ubuntu-latest" >> $GITHUB_OUTPUT |
| 24 | + else |
| 25 | + echo "runner=self-hosted" >> $GITHUB_OUTPUT |
| 26 | + fi |
| 27 | +
|
| 28 | + build-test: |
| 29 | + needs: [setup] |
| 30 | + runs-on: ${{ needs.setup.outputs.runner }} |
| 31 | + env: |
| 32 | + http_proxy: ${{ secrets.HTTP_PROXY }} |
| 33 | + https_proxy: ${{ secrets.HTTPS_PROXY }} |
| 34 | + no_proxy: ${{ secrets.NO_PROXY }} |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 |
| 37 | + with: |
| 38 | + fetch-depth: 0 |
| 39 | + |
| 40 | + - name: Setup Java JDK |
| 41 | + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 |
| 42 | + with: |
| 43 | + distribution: 'temurin' |
| 44 | + java-version: '17' |
| 45 | + |
| 46 | + - name: Install Maven manually |
| 47 | + run: | |
| 48 | + curl -LO https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz |
| 49 | + tar -xzf apache-maven-3.6.3-bin.tar.gz |
| 50 | +
|
| 51 | + - name: Update Maven proxy settings |
| 52 | + run: | |
| 53 | + # Fetch MAVEN_PROXY_HOST and MAVEN_PROXY_PORT from secrets.HTTP_PROXY |
| 54 | + export HTTP_PROXY_VALUE=$(echo "${{ secrets.HTTP_PROXY }}" | sed 's|^http://||;s|^https://||') |
| 55 | + export MAVEN_PROXY_HOST=$(echo $HTTP_PROXY_VALUE | cut -d':' -f1) |
| 56 | + export MAVEN_PROXY_PORT=$(echo $HTTP_PROXY_VALUE | cut -d':' -f2 | sed 's/\///') |
| 57 | +
|
| 58 | + # Update Maven with the proxy settings |
| 59 | + if [ -n "${MAVEN_PROXY_HOST}" -a -n "${MAVEN_PROXY_PORT}" ]; then \ |
| 60 | + mkdir -p ~/.m2 && \ |
| 61 | + echo "<settings><proxies><proxy><id>example-proxy</id><active>true</active><protocol>http</protocol><host>${MAVEN_PROXY_HOST}</host><port>${MAVEN_PROXY_PORT}</port></proxy></proxies></settings>" > ~/.m2/settings.xml; \ |
| 62 | + fi |
| 63 | +
|
| 64 | + - name: Unit Test Coverage |
| 65 | + run: | |
| 66 | + # Add maven binary location to PATH |
| 67 | + export PATH="$PWD/apache-maven-3.6.3/bin:$PATH" |
| 68 | + # Compile, build and install the package |
| 69 | + # This also runs the unit tests internally |
| 70 | + mvn -X -e clean compile install package |
| 71 | + if [ $? -ne 0 ]; then |
| 72 | + echo "Build failed..." |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | +
|
| 76 | + # Fetch coverage for unit tests |
| 77 | + COVERAGE=$(cd connector && \ |
| 78 | + awk -F, \ |
| 79 | + '{ instructions += $4 + $5; covered += $5 } END \ |
| 80 | + { print covered, "/", instructions, " instructions covered"; \ |
| 81 | + print 100*covered/instructions, "% covered" }' \ |
| 82 | + target/site/jacoco/jacoco.csv) |
| 83 | + result=$(echo "$COVERAGE" | grep -oE "[0-9]+\.[0-9]+") |
| 84 | + echo "Unit test coverage for Client is - $result%" |
| 85 | + if (( $(echo "$result < 80" | bc -l) )); then |
| 86 | + echo "Unit test coverage must be above 80%" |
| 87 | + exit 1 |
| 88 | + fi |
0 commit comments