Skip to content

Commit 091e258

Browse files
committed
Task 16 : Define CI/CD process for ci-cd.yml
1 parent 9c77efc commit 091e258

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

.github/workflows/ci-cd.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: CI/CD Pipeline # Define the name of the workflow.
2+
3+
on:
4+
push:
5+
branches: [ "main" ] # Trigger the workflow on push events to the 'main' branch.
6+
pull_request:
7+
branches: [ "main" ] # Trigger the workflow when a pull request is made targeting the 'main' branch.
8+
9+
jobs:
10+
test: # Job for Unit Testing
11+
name: Unit Test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code # Checkout the source code from the repository
15+
uses: actions/checkout@v5
16+
17+
- name: Set up JDK 25 # Set up Java Development Kit version 25
18+
uses: actions/setup-java@v5
19+
with:
20+
java-version: '25'
21+
distribution: 'temurin'
22+
cache: 'maven' # Cache Maven dependencies
23+
24+
- name: Cache Maven packages # Cache dependencies
25+
uses: actions/cache@v3
26+
with:
27+
path: ~/.m2
28+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
29+
restore-keys: ${{ runner.os }}-m2
30+
31+
- name: Build with Maven # Build the project
32+
run: mvn -B package --file pom.xml
33+
34+
- name: Run Tests # Run Unit Tests
35+
run: mvn -B test
36+
37+
build-and-push:
38+
name: Build & Push Docker Image
39+
runs-on: ubuntu-latest
40+
needs: [ test ]
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v5
44+
45+
- name: Set up Temurin JDK 25
46+
uses: actions/setup-java@v5
47+
with:
48+
distribution: temurin
49+
java-version: '25'
50+
cache: maven
51+
52+
- name: Cache Maven packages # Cache dependencies
53+
uses: actions/cache@v3
54+
with:
55+
path: ~/.m2
56+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
57+
restore-keys: ${{ runner.os }}-m2
58+
59+
- name: Build with Maven
60+
run: mvn -B package --file pom.xml
61+
62+
- name: Log in to Docker Hub
63+
uses: docker/login-action@v3
64+
with:
65+
username: ${{ secrets.DOCKER_USERNAME }}
66+
password: ${{ secrets.DOCKER_PASSWORD }}
67+
68+
- name: Build and push
69+
uses: docker/build-push-action@v6
70+
with:
71+
context: .
72+
file: ./Dockerfile
73+
push: true
74+
tags: ${{ secrets.DOCKER_USERNAME }}/cryptoexchangeapi:latest

0 commit comments

Comments
 (0)