Task 28 : Revise README.md #13
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
| name: CI/CD Pipeline # Define the name of the workflow. | |
| on: | |
| push: | |
| branches: [ "main" ] # Trigger the workflow on push events to the 'main' branch. | |
| pull_request: | |
| branches: [ "main" ] # Trigger the workflow when a pull request is made targeting the 'main' branch. | |
| jobs: | |
| test: # Job for Unit Testing | |
| name: Unit Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code # Checkout the source code from the repository | |
| uses: actions/checkout@v5 | |
| - name: Set up JDK 25 # Set up Java Development Kit version 25 | |
| uses: actions/setup-java@v5 | |
| with: | |
| java-version: '25' | |
| distribution: 'temurin' | |
| cache: 'maven' # Cache Maven dependencies | |
| - name: Cache Maven packages # Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: ${{ runner.os }}-m2 | |
| - name: Build with Maven # Build the project | |
| run: mvn -B package --file pom.xml | |
| - name: Run Tests # Run Unit Tests | |
| run: mvn -B test | |
| build-and-push: | |
| name: Build & Push Docker Image | |
| runs-on: ubuntu-latest | |
| needs: [ test ] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Set up Temurin JDK 25 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: temurin | |
| java-version: '25' | |
| cache: maven | |
| - name: Cache Maven packages # Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.m2 | |
| key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
| restore-keys: ${{ runner.os }}-m2 | |
| - name: Build with Maven | |
| run: mvn -B package --file pom.xml | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: ${{ secrets.DOCKER_USERNAME }}/cryptoexchangeapi:latest |