-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_integration_and_code_analysis.yml
More file actions
111 lines (100 loc) · 3.52 KB
/
build_integration_and_code_analysis.yml
File metadata and controls
111 lines (100 loc) · 3.52 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
name: Integration and code analysis
on:
workflow_dispatch: null
push:
branches:
- main
- master
- develop
- v1.1.0-preview.6
pull_request:
types: [opened, synchronize, reopened]
jobs:
Sonar-Cloud:
name: Static Code Analysis - Sonar Cloud
outputs:
job-status: ${{ job.status }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: '17'
distribution: 'corretto'
cache: 'maven'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -Dsonar.coverage.jacoco.xmlReportPaths=./target/site/jacoco/jacoco.xml -B verify sonar:sonar -Dsonar.projectKey=AnswerConsulting_AnswerKing-Java -Dsonar.projectName=AnswerKing-Java
Build-Test:
name: Integration Test
outputs:
job-status: ${{ job.status }}
runs-on: ubuntu-latest
permissions:
checks: write
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
cache: 'maven'
- name: Build with Maven
run: mvn install -DskipTests
- name: Run tests with Maven
run: mvn test
- name: Run code coverage report
run: mvn jacoco:report
- name: Run code coverage check
run: mvn clean verify
- name: Publish test coverage results
id: jacoco_reporter
uses: PavanMudigonda/jacoco-reporter@v4.9
with:
coverage_results_path: 'target/site/jacoco/jacoco.xml'
coverage_report_title: 'Test coverage results'
coverage_report_name: 'Test coverage results'
github_token: ${{ secrets.GITHUB_TOKEN }}
Notify-Slack:
if: ${{ always() }}
needs: [ Build-Test ]
runs-on: ubuntu-latest
name: Send Slack Notification
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Send GitHub trigger payload to Slack Workflow Builder
if: github.event_name == 'pull_request' && github.event.action == 'opened'
id: slack
uses: slackapi/slack-github-action@v1.23.0
with:
payload: |
{
"PR_URL": "${{ github.event_name == 'push' && github.event.repository.html_url || github.event.pull_request.html_url }}",
"Test_Status": "${{ needs.Build-Test.outputs.job-status }}",
"Title": "${{ github.event_name == 'push' && github.event.commits[0].message || github.event.pull_request.title }}",
"Type": "${{ github.event_name == 'push' && 'Merged' || github.event.action }}",
"Author": "${{ github.actor }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}