Testing Mavens

Fluent CI/CD Pipeline – Not just a pipe dream any more thanks to GitHub actions

Wed Jun 05 2024

Soumya S Menon

GitHub Action Tool for setting up CI/CD pipelines

GitHub Actions was launched in 2018 to help developers automate their workflows within GitHub. Instead of automated testing, building, and deploying, GitHub Actions automates any webhook, unlike other automation tools and features. It also brings CI/CD (continuous integration/continuous deployment) to the GitHub experience. As part of the implementation, GitHub also offers continuous Integration and continuous deployment (CI/CD).

What is the CI/CD pipeline?

The pipeline process also known as Continuous Integration and Continuous Delivery is a method of driving software development through the process of building, testing, and deploying tools. By automating the software release process human error is minimized and consistency is maintained.

What are GitHub Actions? How does it work?

By leveraging event-driven triggers, GitHub Actions automates software development on GitHub directly. An event trigger can range from creating a pull request to creating a new brand in a repository.

Create an example workflow

You can create an example workflow in your repository that automatically triggers a series of commands whenever code is pushed. In your repository, create the .github/workflows/ directory to store your workflow files.

The pom file is used to configure the maven project. The project should be packaged with its dependencies as configured. This is done to simplify the execution of the jar file once we add library dependencies. Preconfigured tests are triggered each time a maven build is run by using the surefire plugin in the pom file.

Initial Setup for a Java/Maven project using Action Tool

  1. Sign in to GitHub

  2. Select your repository

  3. Under your repository name, click Actions.

  4. In the left sidebar, click on the New workflow button in order to select the workflow for our project.

  5. Select the Java with Maven workflow from the suggested workflows.

  6. After selecting the Java with Maven workflow you will be taken to this screen.

  7. Replace the pre-populated workflow code with the one below

    The first part in the workflow means that it is triggered every time a push request is made to the master branch and on: [workflow_dispatch] means this action triggers another GitHub Actions workflow using the workflow_dispatch event.

    The workflow must be configured for this event type. We then have the jobs keyword which will state the name of all the different jobs we would like to run. In this case, we start off by stating the build. The first thing we then declare is in which OS environment these jobs should run. In this example, we declare that it should run on windows-latest.

    Under steps, a sequence of steps is declared. The first step uses another action called checkout. This gives our job access to the code in our repository. The third step also uses another action called setup-java whose purpose is to set up a Java environment in which our job can run. We also use the with keyword to tell setup-java to use a specific version of the JDK, which in this case is JDK-11. Lastly, we create a final step that will build our project using the maven package. This is done by using the run keyword. This will execute its arguments in the command line of the current job machine.

  8. Commit your new workflow file once all the workflow configuration is in place.

GitHub Action result

As a result of our actions, we can now see the result. Whenever the workflow is run, you can see its status on the action tab.

The last commit of your workflow should have resulted in a successful run. The action log should be investigated if that is not the case. The commit text can be found in the list of executed workflows by clicking on it. You will be taken to this page.

Other automation platforms, such as Docker and third-party CI/CD tools, can also be integrated with GitHub Actions.

Hope you have got a quick understanding of how to use the Actions tool to create Java with Maven Projects.


Your Quality Gatekeepers,

Partner with us today.