Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: CICD
on:
push:
branches:
- dev
- main
pull_request:
branches:
- dev
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
name: Set up JDK 17
- uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: maven
- name: Java version
run: java --version

- name: Build with Maven
run: mvn -B -DskipTests clean package

- name: mvn test
run: mvn test

security-scan:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Trivy Installation
run: |
sudo apt-get install wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy

- name: Trivy scan
run: trivy fs --format table -o fs-report.json .

- name: gitleaks scan
run: sudo apt install gitleaks -y

- name: Gitleaks Code Scan
run: gitleaks detect source . -r gitleaks-report.json -f json

sonar-quality-gate:
runs-on: ubuntu-latest
needs: security-scan
steps:
- name: checkout the 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 SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=devopslearnc_Github-Actions-Examples

buils_docker_image_and_push:
runs-on: ubuntu-latest
needs: sonar-quality-gate
steps:
- uses: actions/checkout@v4
4 changes: 2 additions & 2 deletions .github/workflows/multi-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
- dev
pull_request:
branches:
- main
- dev
jobs:
push_event_check:
runs-on: ubuntu-latest
steps:
- name: check the dev
run: echo "matched to dev branch"
run: echo "matched to dev branch date"
77 changes: 77 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>https://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.12.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.organization>murali-sonar-practice</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mycompany.app.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>[3.9.2,)</version>
</requireMavenVersion>
<requireJavaVersion>
<version>[17,)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3 changes: 3 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sonar.projectKey=devopslearnc_Github-Actions-Examples
sonar.organization=devopslearnc
sonar.host.url=https://sonarcloud.io
15 changes: 15 additions & 0 deletions src/com/mycompany/app/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mycompany.app;
public class App {

private static final String MESSAGE = "Hello World!";

public App() {}

public static void main(String[] args) {
System.out.println(MESSAGE);
}

public String getMessage() {
return MESSAGE;
}
}
22 changes: 22 additions & 0 deletions src/com/mycompany/app/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mycompany.app;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;


public class AppTest
{
@Test
public void testAppConstructor() {
App app1 = new App();
App app2 = new App();
assertEquals(app1.getMessage(), app2.getMessage());
}

@Test
public void testAppMessage()
{
App app = new App();
assertEquals("Hello World!", app.getMessage());
}
}