Skip to content
Open
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
61 changes: 42 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,72 @@
name: Build & Deploy Spring app

on:
name: Build & Deploy spring app
on:
push:
branches:
- main
- '**'
pull_request:
branches:
- '**'


jobs:

build-deploy:
name: Build and Deploy Spring boot for beginner
name: Build and Deploy Spring Boot App
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup JDK 17
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 17

- name: Unit Tests
- name : Unit Tests
run: mvn -B test --file pom.xml

- name: Build the application
- name : Build with Maven
run: |
mvn clean
mvn -B package --file pom.xml

- name: Build Docker Image
uses: docker/build-push-action@v2

- name: Run Checkstyle
run: mvn checkstyle:check

- name: set image tags
id: vars
run: |
echo "TIMESTAMP=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT


- name : Build & push Docker image
uses : docker/build-push-action@v2
with:
context: .
dockerfile: Dockerfile
push: false
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/spring-boot-for-beginners:today
- name: Login to Docker Hub
uses: docker/login-action@v1
tags: |
${{ secrets.DOCKER_HUB_USERNAME }}/spring-boot-for-beginners:${{ steps.vars.outputs.TIMESTAMP }}
${{ secrets.DOCKER_HUB_USERNAME }}/spring-boot-for-beginners:${{ steps.vars.outputs.SHORT_SHA }}
${{ secrets.DOCKER_HUB_USERNAME }}/spring-boot-for-beginners:latest

- name : Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Push to Docker Hub
uses: docker/build-push-action@v2

- name : Push to Docker Hub
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses : docker/build-push-action@v2
with:
context: .
dockerfile: Dockerfile
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/spring-boot-for-beginners:today
tags: |
${{ secrets.DOCKER_HUB_USERNAME }}/spring-boot-for-beginners:${{ steps.vars.outputs.TIMESTAMP }}
${{ secrets.DOCKER_HUB_USERNAME }}/spring-boot-for-beginners:${{ steps.vars.outputs.SHORT_SHA }}
${{ secrets.DOCKER_HUB_USERNAME }}/spring-boot-for-beginners:latest
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ public Student update(Student s) {
public void delete(String email) {
repository.deleteByEmail(email);
}

}