Skip to content

Instantly share code, notes, and snippets.

View orphefs's full-sized avatar

Orfeas Kypris orphefs

  • Oxford, UK
View GitHub Profile

Tutorial: How to improve development speed by running Github workflows on your local machine

Introduction

Do you rely on test workflows for upholding a high level of code quality? Have you ever been frustrated at the fact that every time you want to make changes to your github workflow .yml you have to commit changes which may lead to failed builds, again and again? have you ever been frustrated that this leads to "commit pollution"? I have. And this is why I decided to use act, which is a superb tool that spawns a docker instance to run the workflow locally. It is user friendly, but still requires some configuration to get it up and running, especially if you want fancy things like authenticating and connecting to external services.

Objective

The objective of this short tutorial is to run a Github test workflow on our local machine to speed up development iterations. This is of particular importance when you don't want to pollute Git history by committing a lot

tail -f ci-logs/run.log
[Github action to run tests/Run-tests] 🐳 docker volume rm act-Github-action-to-run-tests-Run-tests
tail: ci-logs/run.log: file truncated
[Github action to run tests/Run-tests] 🚀 Start image=ubuntu:act-20.04
[Github action to run tests/Run-tests] 🐳 docker pull image=ubuntu:act-20.04 platform= username= forcePull=false
[Github action to run tests/Run-tests] 🐳 docker pull ubuntu:act-20.04
[Github action to run tests/Run-tests] 🐳 docker create image=ubuntu:act-20.04 platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[Github action to run tests/Run-tests] Created container name=act-Github-action-to-run-tests-Run-tests id=570bea46dc1532498dbb04cdf972b67613407f44b25b0f128dd5970b06d504c9 from image ubuntu:act-20.04 (platform: )
[Github action to run tests/Run-tests] ENV ==> [RUNNER_TOOL_CACHE=/opt/hostedtoolcache RUNNER_OS=Linux RUNNER_TEMP=/tmp]
[Github action to run tests/Run-tests] 🐳 docker run image=ubuntu:act-20.04 platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
.
sudo docker run -d --rm \ # delete container when finished
-v /var/run/docker.sock:/var/run/docker.sock \ # need to pass on the Docker daemon unix socket
-v $(pwd)/my-repo:/project \ # mount my-repo into /project inside container
-v $(pwd)/ci-logs:/logs \ # logs directory
-v $(pwd)/secret:/secret \ # mount secret/ directory into /secret directory inside container
-e ACTION=pull_request \ # our action (could be push, or something else)
github-actions-pipeline
docker build -t ubuntu:act-20.04 .
FROM docker:dind
RUN apk add curl
RUN curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sh
COPY .actrc /
RUN mv /.actrc ~/.actrc
RUN mkdir /secret
docker build -t github-actions-pipeline .
-P ubuntu-latest=ubuntu:act-20.04
FROM ghcr.io/catthehacker/ubuntu:act-20.04
# The following installs azure-cli (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt)
RUN apt-get update
RUN apt-get install -y ca-certificates curl apt-transport-https lsb-release gnupg
RUN curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null
$ tree -a
.
├── .actrc
├── ci-logs
│   ├── dry-run.log
│   └── run.log
├── Dockerfile
├── my-repo
│   ├── .git
│   ├── .github