-
Notifications
You must be signed in to change notification settings - Fork 206
106 lines (92 loc) · 3.65 KB
/
main.yml
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
name: Hprofile Actions
#on: workflow_dispatch # [push, workflow_dispatch]
on:
pull_request:
types:
- closed # Trigger the workflow when a pull request is closed
env:
AWS_REGION: us-east-1
jobs:
If_merged:
if: github.event.pull_request.merged == true # Check if the pull request was merged
runs-on: ubuntu-latest # Specify the runner
steps:
- run: |
echo The PR was merged # Print a message if the pull request was merged
Testing:
if: false # This condition effectively skips the job
needs: If_merged
runs-on: ubuntu-latest
steps:
- name: code checkout
uses: actions/checkout@v4
- name: Maven test
run: mvn test
- name: Checkstyle
run: mvn checkstyle:checkstyle
- name: Set Java 11
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
- name: Setup SonarQube
uses: warchant/setup-sonar-scanner@v7
# Run sonar-scanner
- name: SonarQube Scan
run: sonar-scanner
-Dsonar.host.url=${{ secrets.SONAR_URL }}
-Dsonar.login=${{ secrets.SONAR_TOKEN }}
-Dsonar.organization=${{ secrets.SONAR_ORGANIZATION }}
-Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY }}
-Dsonar.sources=src/
-Dsonar.junit.reportsPath=target/surefire-report/
-Dsonar.jacoco.reportsPath=target/jacoco.exec
-Dsonar.java.checkstyle.reportsPath=target/checkstyle-result.xml
-Dsonar.java.binaries=target/test-classes/com/visualpathit/account
# Check the Quality Gate status.
- name: SonarQube Quality Gate check
id: sonarqube-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
# Force to fail step after specific time.
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_URL }} #OPTIONAL
BUILD_AND_PUBLISH:
# if: false # This condition effectively skips the job
needs: If_merged
# needs: Testing
runs-on: ubuntu-latest
steps:
- name: code checkout
uses: actions/checkout@v4
# - name: Update application.properties file
# run: |
# sed -i "s/^jdbc.username.*$/jdbc.username\=${{ secrets.RDS_USER }}/" src/main/resources/application.properties
# sed -i "s/^jdbc.password.*$/jdbc.password\=${{ secrets.RDS_PASS }}/" src/main/resources/application.properties
# sed -i "s/db01/${{ secrets.RDS_ENDPOINT }}/" src/main/resources/application.properties
- name: upload image to ECR
uses: appleboy/docker-ecr-action@master
with:
access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
registry: ${{ secrets.REGISTRY }}
repo: docker
region: ${{ env.AWS_REGION }}
tags: ${{ github.run_number }} #latest,${{ github.run_number }}
daemon_off: false
# dockerfile: ./Dockerfile
# context: ./
run: |
docker build -t $registry:$repo:$tags .
docker push $registry:$repo:$tags
- name: Update Image tag
run: |
sed -i "s|image:.*|image: 637423293208.dkr.ecr.us-east-1.amazonaws.com/docker:${{ github.run_number }} |" ./java.yaml
- name: Commit changes
run: |
git config --global user.name ${{ secrets.USER_NAME }}
git config --global user.email ${{ secrets.USER_MAIL }}
git add java.yaml
git commit -m "Update image to ${{ github.run_number }}"
git push