Every repository within the CoMPAS GitHub organization need a default set of GitHub Actions. GitHub Actions are CI/CD steps within a GitHub Repository that you can configure. This way, you can ensure that certain steps (like building) are always triggered on for example a commit push.
Within CoMPAS, we define the following ‘must have’ GitHub Actions:
More to follow.
GitHub Actions are configured using YAML files. These files are stored in the .github/workflows
directory of a specific repository.
During multiple GitHub Actions (like building and SonarCloud analysis), the custom settings.xml
file is needed because it needs access to the GitHub Packages
to download certain artifacts. We can do this by adding the following step before the GitHub Packages repository is needed.
- name: Create custom Maven Settings.xml
uses: whelk-io/maven-settings-xml-action@v18
with:
output_file: custom_maven_settings.xml
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "$" }]'
This basically creates a custom settings.xml
at location custom_maven_settings.xml
. This file can be passed to maven in the next step
by using mvn -s custom_maven_settings.xml
and perhaps some extra parameters you wish for.
For the servers
part, we again have the github-packages-compas
ID that needs to be the same. We have an OWNER
username (this is the default, because
it needs to have a username) and a password which is the GITHUB_TOKEN that’s always available.
All source code repositories need some kind of building step. By default, all source code repositories use Maven as the build tool.
This building step is pretty easy to configure. Just create a maven_build.yml
file in the .github/workflows
directory containing the following source code:
name: Maven Build
on: push #(1)
jobs:
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.11
uses: actions/setup-java@v2.3.0
with:
distribution: 'zulu'
java-version: '11'
- name: Create custom Maven Settings.xml #(2)
uses: whelk-io/maven-settings-xml-action@v18
with:
output_file: custom_maven_settings.xml
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "$" }]'
- name: Build with Maven
run: mvn -s custom_maven_settings.xml -B clean verify #(3)
A few points to remember:
For keeping our copyright and licensing information up to date and correct, we use REUSE to check this. This is also configured for every separate repository in an easy manner: just create a reuse.yml
file in the .github/workflows
directory containing the following source code:
name: REUSE Compliance Check
on: push #(1)
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: REUSE Compliance Check
uses: fsfe/reuse-action@v1
A few points to remember:
This is the only thing that has to be done. After this, it will be checked on every push.
For transparency, CoMPAS repositories also include a REUSE badge in their README for fast checking the REUSE compliance.
Two steps are needed to get a REUSE badge to work:
[![REUSE status](https://api.reuse.software/badge/github.com/com-pas/repoName)](https://api.reuse.software/info/github.com/com-pas/repoName)
There is one steps left: Replace repoName
with the name of the specific repository (as stated in the URL).
After doing all these steps, everything is set up for the REUSE check.
For static code analysis, CoMPAS is using SonarCloud. To configure this, there are several steps that needs to be done.
sonarcloud_analysis.yml
file in the .github/workflows
directory containing the following source code running.name: SonarCloud Analysis
on: push #(1)
jobs:
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 1.11
uses: actions/setup-java@v2.3.0
with:
distribution: 'zulu'
java-version: '11'
- name: Cache SonarCloud packages
uses: actions/cache@v2.1.6
with:
path: ~/.sonar/cache
key: $-sonar
restore-keys: $-sonar
- name: Cache Maven packages
uses: actions/cache@v2.1.6
with:
path: ~/.m2
key: $-m2-$
restore-keys: $-m2
- name: Create custom Maven Settings.xml #(2)
uses: whelk-io/maven-settings-xml-action@v18
with:
output_file: custom_maven_settings.xml
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "$" }]'
- name: Build and analyze
env:
SONAR_TOKEN: $
run: | #(3)
mvn -s custom_maven_settings.xml -B -Psonar \
-Dsonar.projectKey=<insert project key> \
-Dsonar.organization=com-pas \
-Dsonar.host.url=https://sonarcloud.io \
verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
A few points to remember:
settings.xml
having the credentials for the GitHub Packages.
For more information, check our Contributing.<insert project key>
with the project key you copied.Once this is set, it’s all done!
For automatic deployment of our microservices, CoMPAS uses Docker Hub as the central docker image repository. This way, all Docker images can be pulled from a central image repository.
This step is easy to configure. Just create a dockerhub_deployment.yml
file in the .github/workflows
directory containing the following source code:
name: Docker Hub Deployment
on:
release:
types: [released] #(1)
jobs:
push_to_registry:
name: Build and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to Docker Hub #(2)
uses: docker/login-action@v1
with:
username: $
password: $
- name: Extract tag name #(3)
id: extract_tagname
shell: bash
# Extra the tagname form the git reference, value of GITHUB_REF will be something like refs/tags/<tag_name>.
run: echo "##[set-output name=tagname;]$(echo ${GITHUB_REF##*/})"
- name: Set up JDK 11
uses: actions/setup-java@v2.3.0
with:
distribution: 'zulu'
java-version: '11'
- name: Create custom Maven Settings.xml
uses: whelk-io/maven-settings-xml-action@v18
with:
output_file: custom_maven_settings.xml #(4)
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "$" }]'
- name: Set version with Maven
run: mvn -B versions:set -DprocessAllModules=true -DnewVersion=$
- name: Deploy with Maven to GitHub Packages and Docker Hub #(5)
run: ./mvnw -B -s custom_maven_settings.xml -Prelease,native clean deploy
A few points to remember:
DOCKER_HUB_USERNAME
and DOCKER_HUB_PASSWORD
are used, which are secrets stored at CoMPAS organization. For more information about the username and password, ask in the the Slack channel.settings.xml
having the credentials for the GitHub Packages.
For more information, check our Contributing.quarkus-profile
parameter instead of including all the parameters. This way, we can define profile specific properties in our application.properties
file (For more information about this, check our Docker Hub Deployment page):%publishNativeImage.quarkus.native.container-build=true
%publishNativeImage.quarkus.container-image.build=true
%publishNativeImage.quarkus.container-image.group=lfenergycompas
%publishNativeImage.quarkus.container-image.name=compas-scl-data-service
%publishNativeImage.quarkus.container-image.push=true