This repository was archived by the owner on Nov 23, 2025. It is now read-only.
Merge pull request #13 from TechTorque-2025/dev #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # .github/workflows/build.yml | |
| # This workflow builds the JAR, then packages it as a Docker image. | |
| name: Build and Package Service | |
| on: | |
| push: | |
| branches: | |
| - 'main' | |
| - 'devOps' | |
| - 'dev' | |
| pull_request: | |
| branches: | |
| - 'main' | |
| - 'devOps' | |
| - 'dev' | |
| # Permissions needed to push Docker images to your org's GitHub packages | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| # JOB 1: Your original job, unchanged | |
| build-test: | |
| name: Install and Build (Tests Skipped) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: maven | |
| - name: Cache Maven packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.m2/repository | |
| key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-maven- | |
| - name: Build with Maven (Skip Tests) | |
| # As requested, we are keeping -DskipTests for now | |
| run: mvn -B clean package -DskipTests --file auth-service/pom.xml | |
| - name: Upload Build Artifact (JAR) | |
| # We upload the JAR so the next job can use it | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: auth-service-jar | |
| path: auth-service/target/*.jar | |
| # JOB 2: New job to package the service as a Docker image | |
| build-and-push-docker: | |
| name: Build & Push Docker Image | |
| # This job only runs on pushes to 'main', not on PRs | |
| # Ensures you only publish final images for merged code | |
| if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/devOps' || github.ref == 'refs/heads/dev' | |
| runs-on: ubuntu-latest | |
| # This job runs *after* the build-test job succeeds | |
| needs: build-test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| # We need the JAR file that the 'build-test' job created | |
| - name: Download JAR Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: auth-service-jar | |
| path: auth-service/target/ | |
| # This action generates smart tags for your Docker image | |
| # e.g., 'ghcr.io/your-org/auth-service:latest' | |
| # e.g., 'ghcr.io/your-org/auth-service:a1b2c3d' (from the commit SHA) | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} # e.g., ghcr.io/randitha/Authentication | |
| tags: | | |
| type=sha,prefix= | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| # Logs you into the GitHub Container Registry (GHCR) | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} # This token is auto-generated | |
| # Builds the Docker image and pushes it to GHCR | |
| # This assumes you have a 'Dockerfile' in the root of 'Authentication' | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . # Assumes Dockerfile is in the root of this repo | |
| # The Dockerfile build will copy the JAR from auth-service/target/ | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} |