-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (118 loc) · 4 KB
/
Copy pathmain.yml
File metadata and controls
120 lines (118 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#Workflow name
name: CI/CD Pipeline
on:
#Manually trigger workflow runs
workflow_dispatch:
#Trigger the workflow on push from the main branch
push:
branches:
- master
jobs:
#Test's job
tests:
name: Unit tests
#Run on Ubuntu using the latest version
runs-on: ubuntu-latest
#Job's steps
steps:
#Check-out your repository under $GITHUB_WORKSPACE, so your workflow can access it
- uses: actions/checkout@v1
#Set up JDK 11
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: '11'
#Set up Maven cache
- name: Cache Maven packages
#This action allows caching dependencies and build outputs to improve workflow execution time.
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
#Run Tests
- name: Run Tests
run: mvn -B test
#Sonar's Job
#Sonar's Job
sonar:
#Depends on test's job
needs: tests
name: SonarCloud analysis
#Run on Ubuntu using the latest version
runs-on: ubuntu-latest
#Job's steps
steps:
#Check-out your repository under $GITHUB_WORKSPACE, so your workflow can access it
- uses: actions/checkout@v1
#Set up JDK 17
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: '17'
#Set up SonarCloud cache
- name: Cache SonarCloud packages
#This action allows caching dependencies and build outputs to improve workflow execution time.
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
#Set up Maven cache
- name: Cache Maven packages
#This action allows caching dependencies and build outputs to improve workflow execution time.
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
#Analyze project with SonarCloud
- name: Analyze with SonarCloud
run: mvn -B verify sonar:sonar -Dsonar.projectKey=davidc-garciae_LabCICD -Dsonar.organization=davidc-garciae -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONARTOKEN
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARTOKEN }}
#Build's job
build:
#Depends on sonar's job
needs: sonar
name: Build
#Run on Ubuntu using the latest version
runs-on: ubuntu-latest
steps:
#Check-out your repository under $GITHUB_WORKSPACE, so your workflow can access it
- uses: actions/checkout@v1
#Set up JDK 11
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: '11'
#Set up Maven cache
- name: Cache Maven packages
#This action allows caching dependencies and build outputs to improve workflow execution time.
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
#Build the application using Maven
- name: Build with Maven
run: mvn -B package -DskipTests --file pom.xml
#Build the application using Maven
- name: Upload JAR
#This uploads artifacts from your workflow allowing you to share data between jobs and store data once a workflow is complete.
uses: actions/upload-artifact@v3
with:
#Set artifact name
name: artifact
#From this path
path: target/labcicd-0.0.1-SNAPSHOT.jar
- name: Build & push Docker image
uses: mr-smithers-excellent/docker-build-push@v6
with:
image: rec0very/labcicd
tags: latest
registry: docker.io
dockerfile: Dockerfile
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}