|
| 1 | +name: ci-cd-java.yml |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + tags: |
| 7 | + - "v*" |
| 8 | + pull_request: |
| 9 | + merge_group: |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-check-test-push: |
| 13 | + name: Build, check, test, push |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + clean: 'true' |
| 20 | + fetch-depth: 2 |
| 21 | + |
| 22 | + - name: Setup JDK |
| 23 | + uses: actions/setup-java@v4 |
| 24 | + with: |
| 25 | + distribution: 'temurin' |
| 26 | + java-version: '21' |
| 27 | + cache: 'maven' |
| 28 | + |
| 29 | + - name: Check code format and lint |
| 30 | + run: | |
| 31 | + mvn spotless:check |
| 32 | +
|
| 33 | + - name: Run tests |
| 34 | + run: mvn test |
| 35 | + |
| 36 | + - name: Build artifact |
| 37 | + run: mvn package -Dmaven.test.skip |
| 38 | + |
| 39 | + - name: Build Docker Image |
| 40 | + uses: docker/build-push-action@v6 |
| 41 | + with: |
| 42 | + context: . |
| 43 | + push: 'false' |
| 44 | + tags: 'hsldevcom/${{ github.repository }}:${{ github.sha }}' |
| 45 | + |
| 46 | + - name: Setup Docker Buildx |
| 47 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' |
| 48 | + uses: docker/setup-buildx-action@v3 |
| 49 | + |
| 50 | + - name: Extract Docker metadata |
| 51 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' |
| 52 | + id: meta |
| 53 | + uses: docker/metadata-action@v5 |
| 54 | + with: |
| 55 | + images: ${{ github.repository }} |
| 56 | + tags: | |
| 57 | + type=ref,event=branch |
| 58 | + type=sha |
| 59 | + type=semver,pattern={{version}} |
| 60 | + labels: | |
| 61 | + org.opencontainers.image.title=${{ github.repository }} |
| 62 | + org.opencontainers.image.vendor=hsldevcom |
| 63 | +
|
| 64 | + - name: Login to Github Container Registry |
| 65 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' |
| 66 | + uses: docker/login-action@v3 |
| 67 | + with: |
| 68 | + registry: hsldevcom |
| 69 | + username: ${{ github.actor }} |
| 70 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + |
| 72 | + - name: Build & Push Docker image |
| 73 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' |
| 74 | + uses: docker/build-push-action@v6 |
| 75 | + with: |
| 76 | + context: . |
| 77 | + push: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' }} |
| 78 | + tags: ${{ steps.meta.outputs.tags }} |
| 79 | + labels: ${{ steps.meta.outputs.labels }} |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
0 commit comments