-
Notifications
You must be signed in to change notification settings - Fork 0
CI Build
The workflow file is available in the dev-ci
branch at /.github/workflows/CI-CD-Workflow.yml
The GitHub Actions documentation
Commit and push changes to any branch. The CI Worflow is automatically triggered and starts the building process. An Ubuntu based container is created where all our commands will setup the process. A container is dedicated to only 1 job which has multiple steps. Therefore, the build process has its own job as described in the .yml. The same goes for the test and deploy jobs.
jobs:
build:
runs-on: ubuntu-latest
We download all required repositories to build the image. This is done using a GitHub provided actions that checkouts (clones and switches) to specified repositories inside our container. The benefits of using this action is that GitHub uses its own ressources to (nearly) instantly clone the repository, whereas cloning would take a few minutes.
A checkout action looks like the following:
- name: Checkout riseclipse-metamodel-nsd2016
uses: actions/checkout@v2
with:
path: riseclipse-metamodel-nsd2016
repository: RiseClipse/riseclipse-metamodel-nsd2016
ref: use-up-to-date-components
-
path
is the location of the folder inside the github action container. -
repository
is the name of the github repository in the form<owner>/<repository_name>
-
ref
is the branch name
Once again, GitHub provides a specific action that automatically setups a maven environment for us using this:
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
cache: maven
Now that everything is setup, we can start the build using a simple maven command: mvn install
. Priorly, we just ensure our current working directory is at the right place, which for this project is:
riseclipse-developer/fr.centralesupelec.edf.riseclipse.developer.maven.validator.scl
This corresponds to this step in the job:
- name: Build with Maven
run: |
cd riseclipse-developer
cd fr.centralesupelec.edf.riseclipse.developer.maven.validator.scl
mvn install
The maven plugin is configured to generate some .jar
artefacts which are our usable RiseClipse tools.
In order to distribute the .jar
files, they need to be formatted. The Rename artefacts and zip them all
renames the files to more friendly names and places to deal with in the CI, and create a ZIP of them.
We now have to ensure the artefacts are available for the nexts jobs of our workflow using a GitHub provided actions that uploads the artifact.
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: RiseClipse-cli.jar
path: ${{ github.workspace }}/RiseClipse-Validator-SCL-CLI.jar
The previous action is used for each artifact.
At this step which is the end of the build job, the .jar
files can be downloaded as artefacts of this workflow in the Actions section of the repository, and are also available for next jobs.
Note that every changes should be apply inside the
.github/workflow/CI-CD-Workflow.yml
file.
Currently, the workflow is triggered whenever you commit to any branch that has the workflow setup (in other words, it has the .github/workflow folder).
If you wish to change this behaviour, you have to modify the on
attribute to add events that will trigger the workflow.
For instance, you can only trigger the workflow when you commit to a specific branch using the branches
attribute. You can also trigger only when you do pull_request
, push
or tag
commits
on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- main
pull_request:
branches:
- main
# Also trigger on page_build, as well as release created events
page_build:
release:
types: # This configuration does not affect the page_build event above
- created
You can learn more about how to use events at GitHub's official documentation for Events and triggers
If you need to update or change the maven tool version, just change the version number in the action that setups the maven environment:
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11' # <== YOUR VERSION HERE
distribution: 'adopt' # <== YOUR DISTRIBUTION SOURCE HERE
cache: maven
If you want a specific image of the container that builds the image, change the based-on
attribute:
runs-on: ubuntu-latest # <== YOUR IMAGE HERE
If you made changes in the maven config that generates the .jar
to another folder, just change the path in the upload artifact step:
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: RiseClipse-cli.jar
# YOUR NEW PATH BELOW
path: ${{ github.workspace }}/RiseClipse-Validator-SCL-CLI.jar
Please note that by default, all path are relative to
$GITHUB_WORKSPACE
.
If the maven building process requires new repositories to generate the image, just add a checkout action targeting your repository:
- name: Checkout riseclipse-main
uses: actions/checkout@v2
with:
path: riseclipse-main # <== FOLDER NAME IN THE CONTAINER
repository: RiseClipse/riseclipse-main # <== REPOSITORY NAME (don't forget to specify the owner)
ref: use-up-to-date-components # <== BRANCH NAME