Skip to content

Commit ca50632

Browse files
committed
docs: README updates with more examples
1 parent 3418357 commit ca50632

File tree

3 files changed

+97
-51
lines changed

3 files changed

+97
-51
lines changed

.github/workflows/release.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ jobs:
104104
- name: running for master branch
105105
if: startsWith(github.ref, 'refs/heads/master')
106106
run: |+
107-
echo "IMAGE_TAG=nightly" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
107+
echo "running for master branch, will delete nightly release, and recreate in case it exists"
108+
IMAGE_TAG=nightly
109+
echo "IMAGE_TAG=$IMAGE_TAG" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
110+
gh release list -R ${{ github.repository }} | grep -i $IMAGE_TAG
111+
exit_code=$?
112+
if [ $exit_code -eq 0 ]; then
113+
gh release delete $IMAGE_TAG -y --cleanup-tag -R ${{ github.repository }}
114+
fi
108115
109116
- name: ensure github release exists
110117
shell: bash

README.md

+86-46
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,27 @@
22

33
All it does is run some pre-configured tasks for you, like running your applications, tests, building binaries, or some other scripts.
44

5-
It is inspired by other task runners like Taskfile, Make etc.
5+
It is inspired by other task runners like [Taskfile](https://taskfile.dev), [Make](https://www.gnu.org/software/make/manual/make.html) etc.
6+
I decided to build my version of it, accounting the experiences that i want to see in a task runner.
67

7-
But source code of those tools are like super big, and complex. So I decided to make a simpler one.
8+
### Features
9+
10+
- [x] Run tasks (commands)
11+
- [x] Run tasks with Key-Value environment variables
12+
- [x] Run tasks with dynamic environment variables (referencing values by shell execution)
13+
- [x] Run tasks with dotenv files as their environment variables
14+
- [x] Importing tasks from different working directory (must in a monorepo) [reference](https://taskfile.dev/reference/schema/#task)
15+
- [x] Running tasks in parallel (e.g. css generation and build in parallel)
16+
- [x] Running tasks with watch mode (e.g. like hot reload)
17+
- [x] Requirements prior to running a target (e.g. sanity tests)
18+
- [x] Environment validations and default value
19+
20+
### Installation
21+
22+
| Tool | Command |
23+
| :---: | :---: |
24+
| Go | `go install github.com/nxtcoder17/runfile/cmd/run@latest` |
825

9-
## Installation
1026

1127
```bash
1228
go install github.com/nxtcoder17/runfile/cmd/run@latest
@@ -18,66 +34,90 @@ go install github.com/nxtcoder17/runfile/cmd/run@latest
1834

1935
Create a `Runfile` in the root of your project, and add tasks to it.
2036

21-
### Features
37+
### Examples
2238

23-
- [x] Run tasks
24-
- [x] Run tasks with Key-Value environment variables
25-
- [x] Run tasks with dynamic environment variables (by shell execution)
26-
- [x] Run tasks with dotenv files as their environment variables
27-
- [x] Running tasks in different working directory [reference](https://taskfile.dev/reference/schema/#task)
28-
- [x] Running tasks in parallel
29-
- [ ] Running tasks with watch mode
30-
- [x] Requirements prior to running a target
31-
- [x] Environment validations and default value
39+
1. simple tasks
40+
41+
```yaml
42+
tasks:
43+
example:
44+
cmd:
45+
- echo "example"
46+
```
47+
48+
![Output](https://github.com/user-attachments/assets/37e33c94-bd3d-407a-8cbe-e62f6e3e2411)
3249
33-
### Example
50+
2. using environment variables
3451
3552
```yaml
36-
version: 0.0.1
53+
tasks:
54+
example:
55+
env:
56+
key: "hello world"
57+
cmd:
58+
- echo $key
59+
```
60+
61+
![Output](https://github.com/user-attachments/assets/3a0979e6-53a4-4979-bc93-de6adc36fe74)
62+
63+
3. using dynamic environment variables
3764
65+
```yaml
3866
tasks:
39-
test:
67+
example:
4068
env:
41-
key1: value1
42-
key2: value2
43-
key3:
44-
sh: echo -n "hello"
45-
dotenv:
46-
- .secrets/env # load dotenv file
69+
key:
70+
sh: echo $HOME
4771
cmd:
48-
- echo "value of key1 is '$key1'"
49-
- echo "value of key2 is '$key2'"
50-
- echo "value of key3 is '$key3'"
51-
- echo "value of key4 is '$key4'" # assuming key4 is defined in .secrets/env
72+
- echo $key
5273
```
5374
54-
## Updates with example runfile with all the features
75+
![Image](https://github.com/user-attachments/assets/f9ca3ae6-4a49-46e4-a07b-66ba84ba14a3)
76+
77+
4. using dotenv based environment variables
5578
5679
```yaml
57-
version: 0.0.1
80+
tasks:
81+
example:
82+
dotenv:
83+
- .env
84+
cmd:
85+
- echo $key
86+
```
87+
88+
```bash
89+
# file: .env
90+
key="my-dotenv-secret"
91+
```
92+
93+
![Image](https://github.com/user-attachments/assets/941b6a9d-57ae-46f1-a320-e76278d6b1e2)
94+
95+
5. validating required environment variable
5896

97+
```yaml
5998
tasks:
60-
test:
99+
example:
61100
env:
62-
key1: value1
63-
key2: value2
64-
key3:
65-
sh: echo -n "hello"
66-
key4:
101+
key:
67102
required: true
68-
dotenv:
69-
- .secrets/env # load dotenv file
70103
cmd:
71-
- echo "value of key1 is '$key1'"
72-
- echo "value of key2 is '$key2'"
73-
- echo "value of key3 is '$key3'"
74-
- echo "value of key4 is '$key4'" # assuming key4 is defined in .secrets/env
75-
build:
76-
dir: cmd/app
104+
- echo $key
105+
```
106+
![Image](https://github.com/user-attachments/assets/b900d81a-0eae-4ef6-ac30-8b50cf4ce292)
107+
108+
6. referencing other tasks
109+
110+
```yaml
111+
tasks:
112+
script1:
77113
cmd:
78-
- go build -o app
79-
run:
80-
dir: cmd/app
114+
- echo "i am script 1 (key=$key)"
115+
116+
example:
81117
cmd:
82-
- go run .
118+
- run: script1
119+
env:
120+
key: "hello"
121+
- echo this is example (key=$key)
83122
```
123+
![Image](https://github.com/user-attachments/assets/8e7c2d4b-b9e1-4e0e-9b07-e012adc86d64)

parser/parse-task.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ func isAbsPath(p string) bool {
2222
func ParseTask(ctx types.Context, prf *types.ParsedRunfile, task types.Task) (*types.ParsedTask, error) {
2323
taskCtx := ctx
2424
taskCtx.TaskName = task.Name
25-
workingDir := filepath.Dir(prf.Metadata.RunfilePath)
26-
if task.Metadata.RunfilePath != nil {
27-
workingDir = filepath.Dir(*task.Metadata.RunfilePath)
25+
if task.Metadata.RunfilePath == nil {
26+
task.Metadata.RunfilePath = &prf.Metadata.RunfilePath
2827
}
28+
workingDir := filepath.Dir(*task.Metadata.RunfilePath)
2929

3030
taskEnv := prf.Env
3131

@@ -38,7 +38,6 @@ func ParseTask(ctx types.Context, prf *types.ParsedRunfile, task types.Task) (*t
3838
de := task.DotEnv[i]
3939
if !filepath.IsAbs(de) {
4040
result := filepath.Join(filepath.Dir(*task.Metadata.RunfilePath), de)
41-
// fmt.Println("HERE", "runfilepath", prf.Metadata.RunfilePath, "dotenv", de, "result", result)
4241
de = result
4342
}
4443

0 commit comments

Comments
 (0)