Skip to content

Commit

Permalink
Merges [PR](#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtcoder17 authored Oct 6, 2024
2 parents f5a0bf1 + aa0f863 commit 06b1e4a
Show file tree
Hide file tree
Showing 29 changed files with 2,060 additions and 182 deletions.
138 changes: 138 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Release

on:
workflow_dispatch:

push:
tags:
- 'v*'

branches:
- master

paths:
- "cmd/run/**"
- ".github/**"
- "pkg/**"
- go.* # go.mod, and go.sum
- flake.*

permissions:
contents: write
packages: write

jobs:
build-binary:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-14, macos-13]
arch: [amd64, arm64]
include:
- os: ubuntu-latest
platform: linux

- os: macos-13
platform: darwin

- os: macos-14
platform: darwin
exclude:
- os: macos-14
arch: amd64
- os: macos-13
arch: arm64

name: Building run-${{ matrix.platform }}-${{ matrix.arch }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- uses: nxtcoder17/actions/setup-cache-go@v1
with:
cache_key: "run-${{ matrix.platform }}-${{ matrix.arch }}"
working_directory: .

- uses: nxtcoder17/actions/generate-image-tag@v1

- uses: nxtcoder17/actions/setup-nix-cachix@v1
with:
flake_lock: "./flake.lock"
nix_develop_arguments: ".#default"
cachix_cache_name: ${{ secrets.CACHIX_CACHE_NAME }}
cachix_auth_token: ${{ secrets.CACHIX_AUTH_TOKEN }}

- name: Build Binary
shell: bash
env:
CGO_ENABLED: 0
run: |+
binary=bin/run-${{ matrix.platform }}-${{ matrix.arch }}
go build -o $binary -ldflags="-s -w" -tags urfave_cli_no_docs cmd/run/main.go
if [ "${{ matrix.platform }}" = "linux" ]; then
upx $binary
fi
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: run-${{ matrix.platform }}-${{ matrix.arch }}
path: bin/*

release:
needs: build-binary
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/binaries
pattern: "run-*"

- name: flattening all the executable artifacts
shell: bash
run: |+
ls -R ${{ github.workspace }}/binaries
mkdir -p ${{ github.workspace }}/upload/binaries
shopt -s globstar
file ./** | grep 'executable,' | awk -F: '{print $1}' | xargs -I {} cp {} ${{ github.workspace }}/upload/binaries
shopt -u globstar
- uses: nxtcoder17/actions/generate-image-tag@v1

- name: running for master branch
if: startsWith(github.ref, 'refs/heads/master')
run: |+
echo "IMAGE_TAG=nightly" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
- name: ensure github release exists
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |+
set +e
gh release list -R ${{ github.repository }} | grep -i $IMAGE_TAG
exit_code=$?
if [ $exit_code -ne 0 ]; then
gh release create $IMAGE_TAG -R ${{ github.repository }} --generate-notes --prerelease --draft=false
fi
- name: upload to github release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |+
extra_args=""
if [ "$IMAGE_TAG" = "nightly" ]; then
extra_args="--clobber"
fi
gh release upload $IMAGE_TAG -R ${{github.repository}} $extra_args ${{github.workspace}}/upload/binaries/*
- name: mark release as latest
if: startsWith(github.ref, 'refs/tags/')
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |+
gh release edit $IMAGE_TAG -R ${{ github.repository }} --latest
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ Create a `Runfile` in the root of your project, and add tasks to it.
- [x] Run tasks with Key-Value environment variables
- [x] Run tasks with dynamic environment variables (by shell execution)
- [x] Run tasks with dotenv files as their environment variables
- [ ] Running tasks in different working directory [reference](https://taskfile.dev/reference/schema/#task)
- [x] Running tasks in different working directory [reference](https://taskfile.dev/reference/schema/#task)
- [x] Running tasks in parallel
- [ ] Running tasks with watch mode
- [ ] Running tasks in parallel
- [x] Requirements prior to running a target
- [x] Environment validations and default value

### Example

Expand Down
7 changes: 6 additions & 1 deletion Runfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ tasks:
echo "DONE"
example:
dir: ./examples
cmd:
- |+
run -f ./examples/Runfile cook
run cook clean
test:
cmd:
- go test -json ./pkg/runfile | gotestfmt
139 changes: 117 additions & 22 deletions cmd/run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@ package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"

"github.com/nxtcoder17/runfile/pkg/logging"
"github.com/nxtcoder17/runfile/pkg/runfile"
"github.com/nxtcoder17/runfile/pkg/runfile/errors"
"github.com/urfave/cli/v3"
)

var Version string = "0.0.1"
var Version string = "nightly"

var runfileNames []string = []string{
"Runfile",
"Runfile.yml",
"Runfile.yaml",
}

func main() {
cmd := cli.Command{
Expand All @@ -26,6 +34,23 @@ func main() {
Aliases: []string{"f"},
Value: "",
},

&cli.BoolFlag{
Name: "parallel",
Aliases: []string{"p"},
Value: false,
},

&cli.BoolFlag{
Name: "watch",
Aliases: []string{"w"},
Value: false,
},

&cli.BoolFlag{
Name: "debug",
Value: false,
},
},
EnableShellCompletion: true,
ShellComplete: func(ctx context.Context, c *cli.Command) {
Expand All @@ -38,35 +63,92 @@ func main() {
panic(err)
}

runfile, err := runfile.ParseRunFile(runfilePath)
runfile, err := runfile.Parse(runfilePath)
if err != nil {
panic(err)
}

for k := range runfile.Tasks {
fmt.Fprintf(c.Root().Writer, "%s\n", k)
}

m, err := runfile.ParseIncludes()
if err != nil {
panic(err)
}

for k, v := range m {
for tn := range v.Runfile.Tasks {
fmt.Fprintf(c.Root().Writer, "%s:%s\n", k, tn)
}
}
},
Action: func(ctx context.Context, c *cli.Command) error {
if c.Args().Len() > 1 {
return fmt.Errorf("too many arguments")
}
if c.Args().Len() != 1 {
return fmt.Errorf("missing argument")
parallel := c.Bool("parallel")
watch := c.Bool("watch")
debug := c.Bool("debug")

if c.NArg() == 0 {
c.Command("help").Run(ctx, nil)
return nil
}

runfilePath, err := locateRunfile(c)
if err != nil {
return err
}

runfile, err := runfile.ParseRunFile(runfilePath)
rf, err := runfile.Parse(runfilePath)
if err != nil {
panic(err)
}

s := c.Args().First()
return runfile.Run(ctx, s)
kv := make(map[string]string)

// INFO: for supporting flags that have been suffixed post arguments
args := make([]string, 0, len(c.Args().Slice()))
for _, arg := range c.Args().Slice() {
if arg == "-p" || arg == "--parallel" {
parallel = true
continue
}

if arg == "-w" || arg == "--watch" {
watch = true
continue
}

if arg == "--debug" {
debug = true
continue
}

sp := strings.SplitN(arg, "=", 2)
if len(sp) == 2 {
kv[sp[0]] = sp[1]
continue
}

args = append(args, arg)
}

if parallel && watch {
return fmt.Errorf("parallel and watch can't be set together")
}

logger := logging.NewSlogLogger(logging.SlogOptions{
ShowCaller: debug,
ShowDebugLogs: debug,
SetAsDefaultLogger: true,
})

return rf.Run(runfile.NewContext(ctx, logger), runfile.RunArgs{
Tasks: args,
ExecuteInParallel: parallel,
Watch: watch,
Debug: debug,
KVs: kv,
})
},
}

Expand All @@ -82,29 +164,42 @@ func main() {
}()

if err := cmd.Run(ctx, os.Args); err != nil {
log.Fatal(err)
errm, ok := err.(errors.Message)
if ok {
errm.Log()
}
os.Exit(1)
}
}

func locateRunfile(c *cli.Command) (string, error) {
var runfilePath string
switch {
case c.IsSet("file"):
runfilePath = c.String("file")
return c.String("file"), nil
default:
dir, err := os.Getwd()
if err != nil {
return "", err
}
for {
_, err := os.Stat(filepath.Join(dir, "Runfile"))
if err != nil {
dir = filepath.Dir(dir)
continue

oldDir := ""

for oldDir != dir {
for _, fn := range runfileNames {
if _, err := os.Stat(filepath.Join(dir, fn)); err != nil {
if !os.IsNotExist(err) {
return "", err
}
continue
}

return filepath.Join(dir, fn), nil
}
runfilePath = filepath.Join(dir, "Runfile")
break

oldDir = dir
dir = filepath.Dir(dir)
}

return "", fmt.Errorf("failed to locate your nearest Runfile")
}
return runfilePath, nil
}
10 changes: 10 additions & 0 deletions docs/includes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Includes one runfile into another

```yaml
includes:
file1:
runfile: ./run1/Runfile
# dir: ../
run2:
runfile: ./run2/Runfile
```
Loading

0 comments on commit 06b1e4a

Please sign in to comment.