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.
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.
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 9000:9000 -it ubuntu:latest /bin/bash, which will provide you with a bash prompt on an ubuntu container, with port
9000 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 ~/ export DEBIAN_FRONTEND=noninteractive; \ export DEBCONF_NONINTERACTIVE_SEEN=true; \ echo 'tzdata tzdata/Areas select US' | debconf-set-selections; \ echo 'tzdata tzdata/Zones/US select Pacific' | debconf-set-selections; \ apt-get update -y && apt-get install -y openjdk-11-jdk-headless git maven nano ssh-keygen
Alternatively you can use the following dockerfile if you want to create an image.
FROM ubuntu:latest RUN export DEBIAN_FRONTEND=noninteractive; \ export DEBCONF_NONINTERACTIVE_SEEN=true; \ echo 'tzdata tzdata/Areas select US' | debconf-set-selections; \ echo 'tzdata tzdata/Zones/US select Pacific' | debconf-set-selections; \ apt-get update -y && apt-get install -y openjdk-11-jdk-headless git maven nano
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:
-DskipTestsis helpful when installing an upstream project that you don’t wish to test.
-Dgpg.skipwill skip GPG signing, allowing you to use release profiles as needed without moving secure keys to your test environment.
- Most importantly you’ll need to enable Java debugging. There are two options for client/server, one of which may be easier than the other depending on your networking environment.
-Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9000"will cause JVM for testing to be a TCP server for debugging.
-Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=localhost:9001"will cause the JVM for testing to connect to
9001where you will need to have a debugger running as a server.
Node & NPM
Additionally, if you are building or debugging node, npm, or angular applications in a docker container, you may need run into issues while running the build as “root”. Once npm is installed and you have considered the security implications, you can run the following commands to enable npm to run as root.
npm config set user 0 npm config set unsafe-perm true
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.