Skip to content

Commit bdcbd07

Browse files
authored
Create running-github-actions-locally.md
1 parent 20ba533 commit bdcbd07

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
+++
2+
ShowToc = false
3+
date = 2023-10-01T12:00:00Z
4+
description = "A guide on using act to run GitHub Actions locally."
5+
tags = ["github", "actions", "docker", "development"]
6+
title = "Running GitHub Actions Locally with act"
7+
8+
+++
9+
10+
Hey there! Let’s talk about something that’s been a game changer for me:
11+
`act`. It basically lets you run your GitHub Actions on your machine
12+
without a whole lot of configuration—none for me!
13+
14+
So if you're too excited to check this out on your own, check out
15+
`act` [here](https://github.com/nektos).
16+
17+
OR if you want a personalized tutorial on how I went about it, there
18+
you go...
19+
20+
I wanted this for a `loooong time`. If you’re like me, you’ve probably
21+
spent way too much time pushing commits with names like “testing action
22+
1” to “testing action 1001” because I can't get these configs right
23+
the first time. 😭 It’s a drag, right?
24+
25+
## Why Use `act`?
26+
27+
`act` lets you run your GitHub Actions locally using Docker. This means
28+
you can test your workflows without waiting for them to run on GitHub.
29+
It’s a huge time-saver and a life-saver if you're writing complex
30+
workflows!
31+
32+
## Getting Started
33+
34+
- Install it however you like; follow the instructions
35+
[here](https://nektosact.com/installation/index.html). I installed it
36+
using GitHub CLI (don't hate me for using it).
37+
38+
```bash
39+
gh extension install https://github.com/nektos/gh-act
40+
```
41+
42+
- Create your workflow in the `.github/workflows` directory, however
43+
you want it.
44+
45+
- Run `act` to execute every action, or you can do something specific
46+
like `act push` to run all the actions triggered by a push. You can
47+
do a lot [more](https://nektosact.com/usage/index.html).
48+
49+
- If you installed it using GitHub CLI like me, just do `gh act ...`.
50+
51+
NOW HERE'S a problem I faced on my machine: if you don't get this,
52+
you're done!
53+
54+
If Docker on your machine needs `sudo` access (like mine does), you
55+
might hit a snag. When you try to run `gh act`, it won’t have access
56+
to Docker. So, what do you do?
57+
58+
### The Simple Hack
59+
60+
Here’s a quick fix: use `sudo -E` to run commands while keeping your
61+
user context. This way, you can run `gh act` with Docker access
62+
without any hassle.
63+
64+
- **Run Your Workflow**: Use this command:
65+
66+
```bash
67+
sudo -E gh act push
68+
```
69+
70+
The first run might take a bit since it downloads everything (images),
71+
but after that, it’s smooth sailing. No more endless commits just to
72+
test your actions!
73+
74+
So there you have it! With `act`, you can save time and avoid the
75+
hassle of pushing multiple commits just to test your actions. If you
76+
want to learn more, check out the official documentation for `act`
77+
[here](https://nektosact.com/usage/index.html).

0 commit comments

Comments
 (0)