GitHub Actions


GitHub Actions

As you can see we’re now using GitHub actions to perform automated testing of several g2forge projects. While the workflows have needed customization to allow testing across projects which are maintained as linked maven SNAPSHOT versions, the results are impressive and the setup trivial. We have also automated this customization to ease life for future projects. However, this does mean that we all need to learn to debug when tests pass locally and fail under GitHub actions.

Testing

One of the benefits of using github actions, or any good testing server, is that it runs the (maven/junit) tests in a standardized environment. This prevents any special configuration on your development machine from causing tests to pass solely due to local issues, but it requires some effort to debug when local and automated tests produce different results. For testing we recommend docker, EC2, etc, and we outline the necessary steps below. Setting up an AWS account is beyond the scope of this little blurb, but we’ll walk through the instructions assuming docker, with notes on how they’ll apply to other systems.

Setup

If you’re going to use docker, you’ll want to install docker desktop, Once this is complete, start a container by running docker run -p 5005:5005 -it ubuntu /bin/bash, which will provide you with a bash prompt on an ubuntu machine, with port 5005 mapped from localhost to the container. Take note of the port as it will be used for remote Java debugging, and if you’re using docker you must expose it when starting the container.

In your test environment, run the following to configure your environment:

cd ~/
apt update
apt install openjdk-8-jdk git maven
update-alternatives --set java $(update-alternatives --display java | grep "java-8" | grep -v "^ " | sed -e 's/ - .*//')
ssh-keygen

Debugging

At this point you will want to add ~/.ssh/id_rsa.pub to your github.com account so that you can use SSH to clone git repositories. From there, you can clone, build and test code by manually following the steps in the the gh actions workflow config. During debugging you may want to know the following maven arguments:

  • -DskipTests is helpful when installing an upstream project that you don’t wish to test.
  • -Dgpg.skip will skip GPG signing, allowing you to use release profiles as needed without moving secure keys to your test environment.
  • Most importantly: -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 -Xnoagent -Djava.compiler=NONE" will enable remote debugging for the JVM being used to run unit tests.

Wrap Up

GitHub provides simple, powerful CI testing which is well integrated with pull requests. We’ve given a rough outline of how you might want to replicate that testing when local testing differs.