ADD: Run unit tests for all pushes and PRs to develop/em using Github Actions#132
Conversation
4172fb6 to
55de1f7
Compare
|
I removed the caching for now (can still look into it), but this is the first time I actually got things running. I saw that the unit tests depend on the local time of the machine running the tests, so we might want to update |
|
For updating |
|
I rebased this PR to include the changes from #159 and plan to run this action twice (once "from scratch", and then re-run to see how well the caching is doing). |
|
Ok, with caching we're down to ~3min for the whole workflow! I think is actually becoming viable now. |
a0d35bc to
6e597c5
Compare
|
For some reason, it doesn't work on |
|
Last push is just a rebase after merging #161 |
|
The caching seems to have been successful: |
develop/em using Github Actions
|
The one digit change is a clipping or rounding error, which is not good... |
|
So, how should we deal with this? 😅 |
|
Do you know more about the system it is run on? |
|
I can look it up. But FYI: |
|
The GitHub actions tests are run on |
|
Let me try on these which also runs Ubuntu 24.04 |
|
OK. I can confirm - I will change MunitTest to allow a one digit +-1 difference due to numerical accuracy differences. |
|
Issue should be fixed with PR 164 |
|
Yes, PR #164 fixes this, so I can undo my last commit of adjusting the file. Thanks! |
|
Rebasing (and removing my last commit to correct the TRA file) to include the changes from PR #164 |
|
Seems to work, let me re-run the tests to see if the caching also does its thing :) |
|
Looks good from my side: ~19min30s when building "from scratch" and ~4min when using cached builds. |
|
I am not very versed in GitHub actions, so I am not the best reviewer. Maybe ask Israel too? I did copy and paste it into Claude and ChatGPT. Here is their review: ChatGPT: Biggest issues I see
Your workflow name says develop/em, but this runs on any tag push: push: Branch and tag filters are separate: branch filters apply to branch refs, tag filters apply to tag refs. So tags: '*' means every tag in the repo, not only tags reachable from develop/em. GitHub’s docs also confirm that if only branches or only tags are defined, the undefined ref type won’t run; when both are defined, both can trigger independently. Also, release: with no types is too broad for a test workflow. I would usually write: release: GitHub supports event activity filtering via types. If you keep both push.tags and release, publishing a release/tag can cause duplicate test runs, depending on how the tag/release is created.
For a large C++/ROOT/Geant4 build, I’d avoid: runs-on: ubuntu-latest Use: runs-on: ubuntu-24.04 or ubuntu-22.04 if that is what you have validated. GitHub’s hosted images and preinstalled tools are updated regularly, and -latest is a moving stable label.
The current official setup-micromamba examples use @V3, and the action documents the micromamba-shell {0} wrapper you are using. I would change: uses: mamba-org/setup-micromamba@v1 to: uses: mamba-org/setup-micromamba@v3 or pin to a full commit SHA if you want supply-chain hardening. GitHub’s own docs say commit SHA pins are the safest for stability/security.
This part is probably the highest build-failure risk: Libs: -L${libdir} -lhdf5 -lhdf5_cpp For HDF5 C++, the safer order is usually: -lhdf5_cpp -lhdf5 Also, your CCfits.pc probably should include cfitsio either directly or through Requires, e.g.: Libs: -L${libdir} -lCCfits -lcfitsio Right now you only check that pkg-config can find the files: pkg-config --print-errors --exists hdf5 That does not prove the linker can actually link a small program. I’d add a real compile/link probe.
You cache: ${{ hashFiles('megalib/src/**', 'megalib/configure') }} That misses possible build-affecting inputs such as headers, makefiles, config templates, scripts, data used by configure, etc. If a header changes but src/** and configure do not, you could restore a stale MEGAlib build and skip rebuilding. I’d use a broader key, for example: ${{ hashFiles('megalib/**') }} or a curated list that includes headers, makefiles, config files, and scripts.
This step copies files: rsync -a --ignore-existing ... but the name says symlink. More importantly, both commands end with || true, which hides real problems. If this copy is required for tests, let it fail. If it is optional, make that explicit. I’d change the name and remove || true:
on: permissions: concurrency: jobs: Then update micromamba:
And strengthen the pkg-config step: cat > "$CONDA_PREFIX/lib/pkgconfig/hdf5.pc" <<EOF Name: hdf5 cat > "$CONDA_PREFIX/lib/pkgconfig/CCfits.pc" <<EOF Name: CCfits export PKG_CONFIG_PATH="$CONDA_PREFIX/lib/pkgconfig:$CONDA_PREFIX/share/pkgconfig:${PKG_CONFIG_PATH:-}" pkg-config --print-errors --exists hdf5 echo 'int main(){return 0;}' | g++ -x c++ - $(pkg-config --cflags --libs hdf5 CCfits) -o /tmp/pkgconfig-link-test I’d call this workflow close, but not fully robust yet. The main fixes are: narrow the release trigger, pin the runner, update setup-micromamba, make the pkg-config stubs link-tested, broaden the MEGAlib cache key, and stop hiding rsync failures. Claude: Split into actions/cache/restore (with your restore-keys) at the start and actions/cache/save at the end, and gate the save to pushes only (if: github.event_name == 'push') so PRs don't each spawn a 5 GB entry. The develop-em ccache fallback is dead. Your branch is develop/em (slash), so caches are saved under keys like ccache-Linux-develop/em-. But the second restore-key is ccache-Linux-develop-em- (dash). It never matches. The third key ccache-Linux- will still catch those caches, so it's not fatal, but the intended branch-specific fallback isn't doing anything. Change it to ccache-${{ runner.os }}-develop/em-. make -j2 underutilizes the GitHub-hosted Linux runner (4 vCPUs). -j$(nproc) or -j4 should meaningfully cut build time, especially on a ccache miss. Nothing here is breaking your builds today; the ccache-budget and cache-pollution items are the ones most likely to cause confusing "why did MEGAlib rebuild from scratch again" slowdowns over time. Want me to produce a revised version of the YAML with these applied? |
|
Thanks, I'll have a look at this in more detail later today :) |
|
@zoglauer @fhagemann I took a look at this as requested. I looks good, nothing weird that I can see. Last time I had to do this (use MEGAlib for CI pipeline) I decided to go with a Docker image. I was using GitLab at that time, and that was the recommended method, but I found it very convenient and I know GitHub also supports it. It seems a little bit easier to control than the GitHub cache. But either option should be OK, just something to consider in the future, |
|
@israelmcmc Thanks so much! |
|
The image is the starting point of the test. It can be whatever you want. I'd create an image with a version of megalib and nuclearizer compiled, and then, during the actual test, pull the code from the pull request, recompile both of them, and run the tests. You would follow the same step as you do in your local machine. The Docker image doesn't need to change, but it would be good to do so from time to time. |
|
@israelmcmc I might probably leave the current PR as is, now that it's working, but this is definitely something I would like to look into in the future. Do you have some example GitHub repo that has this already implemented that I could use as reference to see how they're doing it? :) |
|
Yes, that makes sense. I have this one. It's in GitLab, but it should be similar for GitHub: It loads the image The Dockerfile that produced the image above is here: https://gitlab.com/burstcube/bc-tools/-/blob/develop/ci.Dockerfile?ref_type=heads All of this likely outdated, but it should give you an idea. |
|
That's perfect, I'll have a look! Thanks |
|
In the latest commit, I addressed all of Andreas' points:
|
|
Test still pass (and are even slightly faster, probably because of the |
|
Merge it! |

This is my first attempt of adding a testing environment to be used with GitHub Actions, created by building
zoglauer/megalib:develop-cosiand the newest commit oncositools/nuclearizer:develop/em.This GitHub Action is triggered with every
pushtodevelop/emor everyPRontodevelop/em.Some description of what was added:
A new filetest/unit_tests.cppwhich right now only checks that1 == 1and2 == 2. This will then become the file to be populated with actual unit tests.A new targettestin theMakefileto run the tests usingcatch.hpp.github/workflows/tests.yamlis the Github Actions workflow file, buildingmegalibandnuclearizerand then executing the tests viamake test. I tried to make it cache the builds ofmegalib(seems to work, massive speed-up starting with the second run) andnuclearizer(which does not seem to be caching much, still takes more than 30min to build). The build ofmegalibseem to take ~11min, andnuclearizermore than 30min.Feedback is very welcome, as well as help with how to properly cache the
nuclearizerbuild to avoid building that "from scratch" in every new push.