Skip to content

Commit 0544a08

Browse files
committed
Task 19 : Implement Github Actions through CI/CD process
1 parent 5722af8 commit 0544a08

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

.github/workflows/ci-cd.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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@v3
16+
17+
- name: Set up JDK 21 # Set up Java Development Kit version 21
18+
uses: actions/setup-java@v3
19+
with:
20+
java-version: '21'
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: # Job to Build and Push Docker Image
38+
name: Build and Push
39+
runs-on: ubuntu-latest
40+
needs: [test] # Runs only after tests
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v3
44+
45+
- name: Set up JDK 21
46+
uses: actions/setup-java@v3
47+
with:
48+
java-version: '21'
49+
distribution: 'temurin'
50+
cache: 'maven'
51+
52+
- name: Build with Maven
53+
run: mvn -B package --file pom.xml
54+
55+
- name: Dockerize & Push Docker Image
56+
uses: mr-smithers-excellent/docker-build-push@v6
57+
with:
58+
image: noyandocker/livebetting
59+
tags: latest
60+
registry: docker.io
61+
dockerfile: Dockerfile
62+
username: ${{ secrets.DOCKER_USERNAME }}
63+
password: ${{ secrets.DOCKER_PASSWORD }}

0 commit comments

Comments
 (0)