1+ # # A simple example to use Github Actions for Java CI with docker and maven
2+ # We build the project using maven.
3+ # Maven is run in a dedicated docker container
4+ # The credentials are set as env variables in a specific ci-settings.xml
5+ # The ENV variables are stored as Github Secrets
6+ #
7+ # The secrets are set in CLI with the github client.
8+ # The following examples set them at organisation level (GITHUB_ORG variable)
9+ # bash -c 'for secret in GITHUBLOGIN GITHUBPASSWORD DOCKER_USERNAME DOCKER_PASSWORD SONAR_URL SONAR_TOKEN; do \
10+ # eval gh secret set $secret --app actions --body ${!secret} --org $GITHUB_ORG --visibility all; \
11+ # done'
12+ name : Java CI
13+
14+ # on every push
15+ on : [push]
16+
17+ env :
18+ GITHUBLOGIN : ${{secrets.GITHUBLOGIN}}
19+ GITHUBPASSWORD : ${{secrets.GITHUBPASSWORD}}
20+ DOCKER_USERNAME : ${{secrets.DOCKER_USERNAME}}
21+ DOCKER_PASSWORD : ${{secrets.DOCKER_PASSWORD}}
22+ SONAR_URL : ${{secrets.SONAR_URL}}
23+ SONAR_TOKEN : ${{secrets.SONAR_TOKEN}}
24+
25+ jobs :
26+ # This job build, test, package and deploy the artefact
27+ maven-build :
28+ # The tags on the runner
29+ runs-on : [self-hosted, Linux]
30+
31+ steps :
32+ # we get the content of the repository
33+ - uses : actions/checkout@v3
34+
35+ # build the project in a docker container with a specific maven settings.xml
36+ # it uses env variables from github secrets for the credentials
37+ # to github, dockerhub and sonar.
38+ - name : Build and test with Maven in docker
39+ run : ./CI_Java/mvn.sh clean verify
40+ - name : Deploy Maven Artifacts
41+ run : ./CI_Java/mvn.sh deploy
42+ - name : Notify dedicated teams channel of Success
43+ uses : dragos-cojocari/ms-teams-notification@v1.0.0
44+ if : ${{ success() }}
45+ with :
46+ github-token : ${{ github.token }} # this will use the runner's token.
47+ ms-teams-webhook-uri : ${{ secrets.MSTEAMS_WEBHOOK }}
48+ notification-summary : Build and Deploy success.
49+ notification-color : 28a745
50+ timezone : Europe/Paris
51+ - name : Notify dedicated teams channel of Failure
52+ uses : dragos-cojocari/ms-teams-notification@v1.0.0
53+ if : ${{ failure() }}
54+ with :
55+ github-token : ${{ github.token }} # this will use the runner's token.
56+ ms-teams-webhook-uri : ${{ secrets.MSTEAMS_WEBHOOK }}
57+ notification-summary : Build and Deploy failure.
58+ notification-color : dc3545
59+ timezone : Europe/Paris
60+
61+ # This job publish the successsite for develop branch
62+ maven-site :
63+ runs-on : [self-hosted, Linux]
64+ needs : maven-build
65+ # Develop branch only
66+ if : github.ref == 'refs/heads/develop'
67+ steps :
68+ - name : Build and deploy site with Maven
69+ run : ./CI_Java/mvn.sh site:site site-deploy
70+ - name : Notify dedicated teams channel of Success
71+ uses : dragos-cojocari/ms-teams-notification@v1.0.0
72+ if : ${{ success() }}
73+ with :
74+ github-token : ${{ github.token }} # this will use the runner's token.
75+ ms-teams-webhook-uri : ${{ secrets.MSTEAMS_WEBHOOK }}
76+ notification-summary : Web site deployed.
77+ notification-color : 28a745
78+ timezone : Europe/Paris
79+ - name : Notify dedicated teams channel of Failure
80+ uses : dragos-cojocari/ms-teams-notification@v1.0.0
81+ if : ${{ failure() }}
82+ with :
83+ github-token : ${{ github.token }} # this will use the runner's token.
84+ ms-teams-webhook-uri : ${{ secrets.MSTEAMS_WEBHOOK }}
85+ notification-summary : Failed to deploy web site.
86+ notification-color : dc3545
87+ timezone : Europe/Paris
0 commit comments