Skip to content

Commit bf6f37d

Browse files
committed
initial release.
1 parent 4769f0c commit bf6f37d

6 files changed

Lines changed: 161 additions & 0 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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

‎.github/workflows/cleanup.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Delete Old Snpashot Package # on every push
2+
on: [push]
3+
jobs:
4+
cleanup:
5+
# The tags on the runner
6+
runs-on: [self-hosted, Linux]
7+
steps:
8+
- uses: smartsquaregmbh/delete-old-packages@v0.5.0
9+
with:
10+
keep: 1
11+
names: |
12+
fr.univtln.bruno.demos.archetypes.demomavenarchetype

‎checkVersions.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mvn versions:display-dependency-updates
2+
mvn versions:display-plugin-updates
3+
mvn versions:display-property-updates

‎ci-settings.xml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!-- A MAVEN SETTINGS FILE TO BE USED IN CI -->
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
4+
https://maven.apache.org/xsd/settings-1.0.0.xsd">
5+
6+
<servers>
7+
<server>
8+
<id>github</id>
9+
<username>${env.GITHUBLOGIN}</username>
10+
<password>${env.GITHUBPASSWORD}</password>
11+
</server>
12+
<server>
13+
<id>dockerhub</id>
14+
<username>${env.DOCKER_USERNAME}</username>
15+
<password>${env.DOCKER_PASSWORD}</password>
16+
</server>
17+
<server>
18+
<id>github.pages</id>
19+
<username>git</username>
20+
<configuration>
21+
<scmVersionType>branch</scmVersionType>
22+
<scmVersion>gh-pages</scmVersion>
23+
</configuration>
24+
</server>
25+
</servers>
26+
27+
<profiles>
28+
<profile>
29+
<id>sonar</id>
30+
<properties>
31+
<sonar.host.url>${env.SONAR_URL}</sonar.host.url>
32+
<sonar.login>${env.SONAR_TOKEN}</sonar.login>
33+
</properties>
34+
</profile>
35+
</profiles>
36+
37+
</settings>

‎mvn.sh‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
export MAVEN_IMAGE=brunoe/maven:3.8.6-eclipse-temurin-17
3+
docker run \
4+
--env GITHUBLOGIN=$GITHUBLOGIN \
5+
--env GITHUBPASSWORD=$GITHUBPASSWORD \
6+
--mount type=bind,source=${HOME}/.m2,target=/var/maven/.m2 \
7+
--mount type=bind,source=${HOME}/.ssh,target=/home/user/.ssh \
8+
--mount type=bind,source=${HOME}/.gitconfig,target=/home/user/.gitconfig,readonly \
9+
--mount type=bind,source="$(pwd)",target=/usr/src/mymaven \
10+
--workdir /usr/src/mymaven \
11+
--rm \
12+
--env PUID=`id -u` -e PGID=`id -g` \
13+
--env MAVEN_CONFIG=/var/maven/.m2 \
14+
$MAVEN_IMAGE \
15+
runuser --user user --group user -- mvn -B -e -T 1C -Duser.home=/var/maven --settings /usr/src/mymaven/CI_Java/ci-settings.xml "$@"

‎sonar.sh‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
./mvn.sh sonar:sonar \
2+
-D sonar.branch.name=$(git rev-parse --abbrev-ref HEAD|tr / _ ) \
3+
-DskipTests=true \
4+
-Dsonar.language=java \
5+
-Dsonar.report.export.path=sonar-report.json \
6+
-Dsonar.host.url=http://localhost:9000 \
7+
--activate-profiles sonar

0 commit comments

Comments
 (0)