## Debugging GitHub Actions locally Pascal Führlich
notes: https://rsecon2022.society-rse.org/walkthroughs/ 30 min presentation, 15 min questions -- ### storytime - repo on GitHub with CI - CI = continuous integration - CI ~ checks run on server on each push - CI checks fail, locally checks succeed - workflow ```python while CI fails: come up with idea implement potential fix push to GitHub wait 20 minutes ``` notes: - then you run out of ideas and start putting `print` statements everywhere, push again... - this trial & error approach reminds you of the time when you just started learning to program - nothing seemed to work and it was frustrating as hell --
notes: - at the end of your workday your history on GitHub shows 20 commits each with a red "failed" cross - and the worst thing: you still have no idea what's going wrong - luckily, there's a better way, and we'll take a look at that now -- ### Requirements - Windows, Mac, Linux - git - repo on GitHub --- ## Motivation -- ### why CI testing? - run checks/tests on PR/push - prevent broken projects, especially problematic if many devs/users - ensure setup works on fresh machine - code quality standard -- ### why GitHub Actions? - Actions are easy to setup & free - Actions = code -> will break eventually, and then? - debugging! - is quite tricky here :( notes: shoutout to GitHub, amazing service for free! -- ### why is debugging Actions tricky? - Action runs on a GitHub server -> non-interactive - trial & error? upload tons of commits + print debugging? - instead use act by Casey Lee --- ## Setup repo - create [repo](https://github.com/pfuehrlich-pik/GitHub-Action-Example) - add GitHub Action - follow Action running in browser notes: - using R, but works with any language - github action failed on GitHub - ok, let's fix this locally... -> cannot reproduce! -- ## Setup act - install [docker](https://www.docker.com/) - install [act](https://github.com/nektos/act#installation) - optional: download [GitHub Actions docker image](https://github.com/nektos/act#runners) ```sh docker pull ghcr.io/catthehacker/ubuntu:full-latest ``` notes: - when Action runs on GitHub server, runs in sandbox/virtual ubuntu system - want to reproduce locally -> need same system -> docker image - use to create container: virtual system, can have different tools/OS running there --- ## Debug Action locally ### run Action locally ```sh act -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:full-latest ``` 1. creates docker container 1. copies local files from the git repo into container 1. runs Actions -- ### open bash in container ```sh docker ps # show running containers docker exec -it {container-name-or-id} bash ``` notes: - compare local vs in docker: interactive R session, `source("script.R")`, `str(x)` - difference = `factor` vs `chr` -> explicitly set `stringsAsFactors = TRUE` - upload to GitHub - push fix to GitHub - open running Action in browser - back to presentation, next slide --- ## Wrap-up - GitHub Actions are great, trial & error debugging is terrible - recreated server environment locally - ran Action locally - solved problem interactively - much faster feedback loop - also helpful for developing new Action! notes: - switch back to succeeded Action - then next slide -- ## final slide [pascal.fuehrlich@pik-potsdam.de](mailto:pascal.fuehrlich@pik-potsdam.de) [github.com/pfuehrlich-pik](https://github.com/pfuehrlich-pik) [pfuehrlich-pik.github.io/Debugging-GitHub-Actions-locally](https://pfuehrlich-pik.github.io/Debugging-GitHub-Actions-locally/) [presentation created with reveal.js by Hakim El Hattab](https://revealjs.com/) [like act? sponsor Casey Lee](https://github.com/sponsors/cplee)