|
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | 17 |
|
18 | | -# This workflow will build a Java project with Maven |
19 | | -# See also: |
20 | | -# https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven |
21 | | - |
22 | 18 | name: CI |
23 | 19 |
|
24 | 20 | on: |
25 | 21 | push: |
26 | | - branches: [ '*' ] |
| 22 | + branches: ['develop/**', 'release/**', 'master'] |
27 | 23 | pull_request: |
28 | | - branches: [ '*' ] |
| 24 | + branches: ['develop/**', 'release/**', 'master'] |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 28 | + cancel-in-progress: true |
| 29 | + |
| 30 | +permissions: |
| 31 | + packages: write |
| 32 | + |
| 33 | +env: |
| 34 | + IMAGE: ghcr.io/${{ github.repository }}/ci |
29 | 35 |
|
30 | 36 | jobs: |
31 | | - mvn: |
32 | | - strategy: |
33 | | - matrix: |
34 | | - profile: |
35 | | - - name: 'full-build-jdk8' |
36 | | - jdk: 8 |
37 | | - args: '-Pfull-build apache-rat:check verify -DskipTests spotbugs:check checkstyle:check' |
38 | | - - name: 'full-build-jdk11' |
39 | | - jdk: 11 |
40 | | - args: '-Pfull-build apache-rat:check verify -DskipTests spotbugs:check checkstyle:check' |
41 | | - - name: 'full-build-java-tests' |
42 | | - jdk: 11 |
43 | | - args: '-Pfull-build verify -Dsurefire-forkcount=1 -DskipCppUnit -Dsurefire.rerunFailingTestsCount=5' |
44 | | - - name: 'full-build-cppunit-tests' |
45 | | - jdk: 11 |
46 | | - args: '-Pfull-build verify -Dtest=_ -DfailIfNoTests=false' |
47 | | - fail-fast: false |
48 | | - timeout-minutes: 360 |
| 37 | + ci-image: |
| 38 | + name: CI Image |
49 | 39 | runs-on: ubuntu-latest |
| 40 | + outputs: |
| 41 | + image: ${{ steps.result.outputs.image }} |
50 | 42 | steps: |
51 | 43 | - uses: actions/checkout@v4 |
52 | | - - name: Set up JDK ${{ matrix.profile.jdk }} |
53 | | - uses: actions/setup-java@v4 |
| 44 | + |
| 45 | + - id: tag |
| 46 | + name: Compute image tag |
| 47 | + run: | |
| 48 | + TAG=$(sha256sum .github/Dockerfile.ci | cut -c1-12) |
| 49 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 50 | + echo "image=${{ env.IMAGE }}:$TAG" >> "$GITHUB_OUTPUT" |
| 51 | +
|
| 52 | + - uses: docker/login-action@v3 |
54 | 53 | with: |
55 | | - java-version: ${{ matrix.profile.jdk }} |
56 | | - distribution: temurin |
57 | | - cache: 'maven' |
58 | | - - name: Show the first log message |
59 | | - run: git log -n1 |
60 | | - - name: Install C Dependencies |
| 54 | + registry: ghcr.io |
| 55 | + username: ${{ github.actor }} |
| 56 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
| 58 | + - name: Check if image exists |
| 59 | + id: check |
61 | 60 | run: | |
62 | | - sudo apt update |
63 | | - sudo apt install -y libcppunit-dev libsasl2-dev |
64 | | - - name: Build with Maven (${{ matrix.profile.name }}) |
65 | | - run: mvn -B -V -e -ntp "-Dstyle.color=always" ${{ matrix.profile.args }} |
66 | | - env: |
67 | | - MAVEN_OPTS: -Djansi.force=true |
| 61 | + if docker manifest inspect ${{ steps.tag.outputs.image }} > /dev/null 2>&1; then |
| 62 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 63 | + else |
| 64 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 65 | + fi |
| 66 | +
|
| 67 | + - if: steps.check.outputs.exists == 'false' |
| 68 | + uses: docker/build-push-action@v6 |
| 69 | + with: |
| 70 | + context: .github |
| 71 | + file: .github/Dockerfile.ci |
| 72 | + push: true |
| 73 | + tags: | |
| 74 | + ${{ steps.tag.outputs.image }} |
| 75 | + ${{ env.IMAGE }}:latest |
| 76 | +
|
| 77 | + - id: result |
| 78 | + run: echo "image=${{ steps.tag.outputs.image }}" >> "$GITHUB_OUTPUT" |
| 79 | + |
| 80 | + compile: |
| 81 | + name: Compile + Checkstyle |
| 82 | + runs-on: ubuntu-latest |
| 83 | + needs: ci-image |
| 84 | + container: ${{ needs.ci-image.outputs.image }} |
| 85 | + timeout-minutes: 30 |
| 86 | + steps: |
| 87 | + - uses: actions/checkout@v4 |
| 88 | + - name: Cache Maven repository |
| 89 | + uses: actions/cache@v4 |
| 90 | + with: |
| 91 | + path: ~/.m2/repository |
| 92 | + key: maven-${{ hashFiles('**/pom.xml') }} |
| 93 | + restore-keys: maven- |
| 94 | + - name: Compile and check style |
| 95 | + run: mvn -B -V -e -ntp -Pfull-build verify -DskipTests checkstyle:check |
| 96 | + |
| 97 | + java-tests: |
| 98 | + name: Java Tests |
| 99 | + runs-on: ubuntu-latest |
| 100 | + needs: [ci-image, compile] |
| 101 | + container: ${{ needs.ci-image.outputs.image }} |
| 102 | + timeout-minutes: 120 |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + - name: Cache Maven repository |
| 106 | + uses: actions/cache@v4 |
| 107 | + with: |
| 108 | + path: ~/.m2/repository |
| 109 | + key: maven-${{ hashFiles('**/pom.xml') }} |
| 110 | + restore-keys: maven- |
| 111 | + - name: Run Java tests |
| 112 | + run: mvn -B -V -e -ntp -Pfull-build verify -Dsurefire-forkcount=1 -DskipCppUnit |
68 | 113 | - name: Upload unit test results |
69 | 114 | if: ${{ failure() }} |
70 | 115 | uses: actions/upload-artifact@v4 |
71 | 116 | with: |
72 | | - name: surefire-reports-${{ matrix.profile.name }} |
| 117 | + name: surefire-reports |
73 | 118 | path: ./**/target/surefire-reports/ |
74 | 119 | if-no-files-found: ignore |
75 | 120 | - name: Upload integration test results |
76 | 121 | if: ${{ failure() }} |
77 | 122 | uses: actions/upload-artifact@v4 |
78 | 123 | with: |
79 | | - name: failsafe-reports-${{ matrix.profile.name }} |
| 124 | + name: failsafe-reports |
80 | 125 | path: ./**/target/failsafe-reports/ |
81 | 126 | if-no-files-found: ignore |
| 127 | + |
| 128 | + c-tests: |
| 129 | + name: C Tests |
| 130 | + runs-on: ubuntu-latest |
| 131 | + needs: [ci-image, compile] |
| 132 | + container: ${{ needs.ci-image.outputs.image }} |
| 133 | + timeout-minutes: 30 |
| 134 | + steps: |
| 135 | + - uses: actions/checkout@v4 |
| 136 | + - name: Cache Maven repository |
| 137 | + uses: actions/cache@v4 |
| 138 | + with: |
| 139 | + path: ~/.m2/repository |
| 140 | + key: maven-${{ hashFiles('**/pom.xml') }} |
| 141 | + restore-keys: maven- |
| 142 | + - name: Run C tests |
| 143 | + run: mvn -B -V -e -ntp -Pfull-build verify -Dtest=_ -Dsurefire.failIfNoSpecifiedTests=false |
82 | 144 | - name: Upload cppunit test logs |
83 | 145 | if: ${{ failure() }} |
84 | 146 | uses: actions/upload-artifact@v4 |
85 | 147 | with: |
86 | | - name: cppunit-logs-${{ matrix.profile.name }} |
| 148 | + name: cppunit-logs |
87 | 149 | path: ./zookeeper-client/zookeeper-client-c/target/c/TEST-*.txt |
88 | 150 | if-no-files-found: ignore |
0 commit comments