|
| 1 | +name: Build and Package Service |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - 'main' |
| 6 | + - 'devOps' |
| 7 | + - 'dev' |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - 'main' |
| 11 | + - 'devOps' |
| 12 | + - 'dev' |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + packages: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + build-test: |
| 20 | + name: Install and Build (Tests Skipped) |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up JDK 17 |
| 28 | + uses: actions/setup-java@v4 |
| 29 | + with: |
| 30 | + java-version: '17' |
| 31 | + distribution: 'temurin' |
| 32 | + cache: maven |
| 33 | + |
| 34 | + - name: Cache Maven packages |
| 35 | + uses: actions/cache@v4 |
| 36 | + with: |
| 37 | + path: ~/.m2/repository |
| 38 | + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} |
| 39 | + restore-keys: | |
| 40 | + ${{ runner.os }}-maven- |
| 41 | +
|
| 42 | + - name: Build with Maven (Skip Tests) |
| 43 | + run: mvn -B clean package -DskipTests --file project-service/pom.xml |
| 44 | + |
| 45 | + - name: Upload Build Artifact (JAR) |
| 46 | + uses: actions/upload-artifact@v4 |
| 47 | + with: |
| 48 | + name: project-service-jar |
| 49 | + path: project-service/target/*.jar |
| 50 | + |
| 51 | + build-and-push-docker: |
| 52 | + name: Build & Push Docker Image |
| 53 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/devOps' || github.ref == 'refs/heads/dev' |
| 54 | + runs-on: ubuntu-latest |
| 55 | + needs: build-test |
| 56 | + |
| 57 | + steps: |
| 58 | + - name: Checkout code |
| 59 | + uses: actions/checkout@v4 |
| 60 | + |
| 61 | + - name: Download JAR Artifact |
| 62 | + uses: actions/download-artifact@v4 |
| 63 | + with: |
| 64 | + name: project-service-jar |
| 65 | + path: project-service/target/ |
| 66 | + |
| 67 | + - name: Docker meta |
| 68 | + id: meta |
| 69 | + uses: docker/metadata-action@v5 |
| 70 | + with: |
| 71 | + images: ghcr.io/techtorque-2025/project_service |
| 72 | + tags: | |
| 73 | + type=sha,prefix= |
| 74 | + type=raw,value=latest,enable={{is_default_branch}} |
| 75 | +
|
| 76 | + - name: Log in to GHCR |
| 77 | + uses: docker/login-action@v3 |
| 78 | + with: |
| 79 | + registry: ghcr.io |
| 80 | + username: ${{ github.actor }} |
| 81 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + |
| 83 | + - name: Build and push Docker image |
| 84 | + uses: docker/build-push-action@v5 |
| 85 | + with: |
| 86 | + context: . |
| 87 | + push: true |
| 88 | + tags: ${{ steps.meta.outputs.tags }} |
| 89 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments