Skip to content

Instantly share code, notes, and snippets.

@sweetlilmre
Last active May 10, 2023 08:01
Show Gist options
  • Save sweetlilmre/758818d0b2a0fdfd79595e396d1e608d to your computer and use it in GitHub Desktop.
Save sweetlilmre/758818d0b2a0fdfd79595e396d1e608d to your computer and use it in GitHub Desktop.
Using act to build / test Github actions locally
  1. Install Act
    • Scoop:
      • Scoop
      • Install act: scoop install act
    • winget:
      • winget install nektos.act
  2. Install Docker Desktop, or Rancher Desktop if you can't install Docker Desktop due to the change in licensing
  3. If installing Rancher, ensure that you choose dockerd not containerd
  4. Install WSL2 support if you don't have it: Install WSL2
    • This is very simple on newer windows builds: wsl --install in a powershell shell.
    • Suggest using the Ubuntu image when it asks.
    • Notes: ensure that you have hardware virtualisation on in your bios and that your WSL system is set to default to version 2!
  5. Now we need a repo to test against, so choose one of your repos and add a .github/workflows directory tree to the root of the project.
  6. Create a workflow yaml file in that folder e.g. build.yaml
  7. Add some initial content to your file e.g.
name: TestCI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch and tags
on:
  push:
    branches:
      - '**'
    tags:
      - '**'
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
 
  1. Commit and push the changes.
  2. Open the root of your project in powershell and type act
  3. Select an image for act to use. Suggested is Medium
  4. Wait while act pulls down the required docker image
  5. If successful you should see something like this:
[TestCI/build] 🚀  Start image=catthehacker/ubuntu:act-latest
[TestCI/build]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=false
[TestCI/build]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[TestCI/build]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[TestCI/build] ⭐ Run Main Checkout
[TestCI/build]   🐳  docker cp src=C:\temp\act-test\. dst=/mnt/c/temp/act-test
[TestCI/build]   ✅  Success - Main Checkout
[TestCI/build] 🏁  Job succeeded
  1. Act developement and updates are frequent. To update scoop update act. You may want to update scoop every now and then as well: scoop update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment