Skip to content

Commit 7ca254a

Browse files
committed
chore: init
0 parents  commit 7ca254a

File tree

17 files changed

+979
-0
lines changed

17 files changed

+979
-0
lines changed

.github/workflows/homebrew.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Update Homebrew Tap
2+
3+
# on:
4+
# release:
5+
# types: [published]
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
jobs:
12+
update-tap:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout Tap Repository
17+
uses: actions/checkout@v3
18+
with:
19+
repository: yosev/homebrew-coda
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
22+
- name: Set Release Name
23+
run: echo "RELEASE_NAME=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
24+
25+
- name: Download Release Assets
26+
run: |
27+
curl -L -o coda-darwin-amd64.tar.gz https://github.com/yosev/coda-cli/releases/download/${RELEASE_NAME}/coda-darwin-amd64.tar.gz
28+
curl -L -o coda-darwin-arm64.tar.gz https://github.com/yosev/coda-cli/releases/download/${RELEASE_NAME}/coda-darwin-arm64.tar.gz
29+
30+
- name: Compute SHA256 Sums
31+
run: |
32+
echo "AMD64_SHA256=$(shasum -a 256 coda-darwin-amd64.tar.gz | awk '{print $1}')" >> $GITHUB_ENV
33+
echo "ARM64_SHA256=$(shasum -a 256 coda-darwin-arm64.tar.gz | awk '{print $1}')" >> $GITHUB_ENV
34+
35+
- name: Update Homebrew Cask
36+
run: |
37+
sed -i "s|^ version \".*\"| version \"${RELEASE_NAME}\"|" Casks/coda.rb
38+
sed -i "/on_intel/,/sha256/s|sha256 \".*\"|sha256 \"${AMD64_SHA256}\"|" Casks/coda.rb
39+
sed -i "/on_arm/,/sha256/s|sha256 \".*\"|sha256 \"${ARM64_SHA256}\"|" Casks/coda.rb
40+
41+
- name: Debug Updated Cask File
42+
run: |
43+
echo "Contents of Casks/coda.rb after update:"
44+
cat Casks/coda.rb
45+
46+
- name: Commit Changes
47+
run: |
48+
git config --local user.name "github-actions[bot]"
49+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
50+
git add Casks/coda.rb
51+
git commit -m "Update Cask for version ${RELEASE_NAME}"
52+
git push

.github/workflows/release.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Cross-platform Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Cache Go modules & build cache
21+
uses: actions/cache@v3
22+
with:
23+
path: |
24+
~/.cache/go-build
25+
~/go/pkg/mod
26+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27+
restore-keys: |
28+
${{ runner.os }}-go-
29+
30+
- name: Set up Go
31+
uses: actions/setup-go@v5
32+
with:
33+
go-version: "1.24.3"
34+
35+
- name: Test unit
36+
run: |
37+
make test
38+
39+
build:
40+
needs: test
41+
continue-on-error: false
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- uses: actions/checkout@v4
46+
47+
- name: Cache Go modules & build cache
48+
uses: actions/cache@v3
49+
with:
50+
path: |
51+
~/.cache/go-build
52+
~/go/pkg/mod
53+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
54+
restore-keys: |
55+
${{ runner.os }}-go-
56+
57+
- name: Set up Go
58+
uses: actions/setup-go@v5
59+
with:
60+
go-version: "1.24.3"
61+
62+
- name: Build
63+
run: |
64+
make build+all
65+
66+
- name: Upload artifact
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: coda
70+
path: _bin/*
71+
retention-days: 1
72+
73+
release:
74+
needs: build
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v4
78+
79+
- name: Download artifacts
80+
uses: actions/download-artifact@v4
81+
with:
82+
path: _bin
83+
84+
- name: Install unzip
85+
run: sudo apt-get update && sudo apt-get install -y unzip
86+
87+
- name: Create tar.gz and zip files
88+
run: |
89+
mkdir -p _dist
90+
mv _bin/coda/ _bin/coda-binaries
91+
cp _bin/coda-binaries/coda-darwin-amd64 _bin/coda && tar -czf _dist/coda-darwin-amd64.tar.gz -C _bin coda && rm _bin/coda
92+
cp _bin/coda-binaries/coda-darwin-arm64 _bin/coda && tar -czf _dist/coda-darwin-arm64.tar.gz -C _bin coda && rm _bin/coda
93+
cp _bin/coda-binaries/coda-linux-amd64 _bin/coda && tar -czf _dist/coda-linux-amd64.tar.gz -C _bin coda && rm _bin/coda
94+
cp _bin/coda-binaries/coda-linux-arm64 _bin/coda && tar -czf _dist/coda-linux-arm64.tar.gz -C _bin coda && rm _bin/coda
95+
96+
cp _bin/coda-binaries/coda-windows-amd64.exe _bin/coda.exe && zip -j _dist/coda-windows-amd64.zip _bin/coda.exe && rm _bin/coda.exe
97+
cp _bin/coda-binaries/coda-windows-arm64.exe _bin/coda.exe && zip -j _dist/coda-windows-arm64.zip _bin/coda.exe && rm _bin/coda.exe
98+
99+
- name: Generate CHANGELOG.md
100+
run: |
101+
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null \
102+
|| git rev-list --max-parents=0 HEAD)
103+
echo "## Changelog" > CHANGELOG.md
104+
git log $PREV_TAG..HEAD --pretty=format:"* %h %s" >> CHANGELOG.md
105+
cat CHANGELOG.md
106+
107+
- name: Publish GitHub Release
108+
uses: softprops/action-gh-release@v1
109+
with:
110+
body_path: CHANGELOG.md
111+
draft: false
112+
tag_name: ${{ github.ref_name }}
113+
make_latest: "true"
114+
files: _dist/**/*
115+
env:
116+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_STORE
2+
_bin/
3+
.vscode/

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
test:
2+
go test -race ./...
3+
4+
build+darwin+amd64:
5+
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -extldflags "-static"" -o _bin/coda-darwin-amd64 main.go
6+
build+darwin+arm64:
7+
GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -extldflags "-static"" -o _bin/coda-darwin-arm64 main.go
8+
build+linux+amd64:
9+
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -extldflags "-static"" -o _bin/coda-linux-amd64 main.go
10+
build+linux+arm64:
11+
GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -extldflags "-static"" -o _bin/coda-linux-arm64 main.go
12+
build+windows+amd64:
13+
GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -extldflags "-static"" -o _bin/coda-windows-amd64.exe main.go
14+
build+windows+arm64:
15+
GOOS=windows GOARCH=arm64 go build -ldflags "-s -w -extldflags "-static"" -o _bin/coda-windows-arm64.exe main.go
16+
17+
build+all: clean build+darwin+amd64 build+darwin+arm64 build+linux+amd64 build+linux+arm64 build+windows+amd64 build+windows+arm64
18+
19+
clean:
20+
rm -rf _bin
21+
mkdir _bin

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# coda-cli
2+
3+
command line interface for [coda workflow engine](https://github.com/yosev/coda)

cmd/.version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1

cmd/docs.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
"github.com/yosev/coda"
8+
)
9+
10+
var docsCmd = &cobra.Command{
11+
Use: "docs",
12+
DisableFlagsInUseLine: true,
13+
Short: "coda operations documentation",
14+
Run: docs,
15+
}
16+
17+
func init() {
18+
rootCmd.AddCommand(docsCmd)
19+
}
20+
21+
func docs(cmd *cobra.Command, args []string) {
22+
c := coda.New()
23+
for _, operation := range c.GetOperations() {
24+
fmt.Printf("Action: %s\nDescription: %s\nCategory: %s\n", operation.Name, operation.Description, operation.Category)
25+
if len(operation.Parameters) > 0 {
26+
fmt.Printf("Parameters:\n")
27+
}
28+
for _, v := range operation.Parameters {
29+
name := v.Name
30+
if v.Mandatory {
31+
name = "(*)" + name
32+
}
33+
fmt.Printf(" - %s: %s\n", name, v.Description)
34+
}
35+
fmt.Printf("\n")
36+
}
37+
}

cmd/init.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
_ "embed"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
//go:embed .version
13+
var VERSION string
14+
15+
var rootCmd = &cobra.Command{
16+
Use: "coda",
17+
Args: cobra.ExactArgs(1),
18+
Short: "coda-cli is a wrapper for the coda workflow engine",
19+
Long: "coda-cli is a wrapper for the coda workflow engine",
20+
CompletionOptions: cobra.CompletionOptions{
21+
DisableDefaultCmd: true,
22+
},
23+
}
24+
25+
func Execute(args []string) {
26+
rootCmd.SetHelpCommand(&cobra.Command{
27+
Use: "help",
28+
Hidden: true,
29+
})
30+
31+
rootCmd.ParseFlags(args)
32+
33+
if err := rootCmd.Execute(); err != nil {
34+
fmt.Fprintln(os.Stderr, err)
35+
os.Exit(1)
36+
}
37+
}

cmd/json.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"os"
7+
"strings"
8+
9+
"github.com/spf13/cobra"
10+
"github.com/yosev/coda"
11+
)
12+
13+
var jsonCmd = &cobra.Command{
14+
Use: "j <coda script as json>",
15+
Args: cobra.ExactArgs(1),
16+
DisableFlagsInUseLine: true,
17+
Short: "coda script as json",
18+
Run: jsonS,
19+
}
20+
21+
var jsonFileCmd = &cobra.Command{
22+
Use: "jj <coda script as json file>",
23+
Args: cobra.ExactArgs(1),
24+
DisableFlagsInUseLine: true,
25+
Example: `coda jj script.coda.json`,
26+
Short: "coda script as json file",
27+
Run: jsonF,
28+
}
29+
30+
func init() {
31+
rootCmd.AddCommand(jsonCmd)
32+
rootCmd.AddCommand(jsonFileCmd)
33+
}
34+
35+
func jsonS(cmd *cobra.Command, args []string) {
36+
input := args[0]
37+
if args[0] == "-" {
38+
b, err := io.ReadAll(os.Stdin)
39+
if err != nil {
40+
fmt.Printf("failed to read from stdin: %v\n", err)
41+
os.Exit(1)
42+
}
43+
input = string(b)
44+
}
45+
executeJ(input)
46+
}
47+
48+
func jsonF(cmd *cobra.Command, args []string) {
49+
f, err := os.ReadFile(args[0])
50+
if err != nil {
51+
fmt.Printf("failed to read json file: %v\n", err)
52+
os.Exit(1)
53+
}
54+
55+
script := string(f)
56+
57+
// remove shebang if present
58+
if strings.HasPrefix(script, "#!") {
59+
script = strings.SplitN(script, "\n", 2)[1]
60+
}
61+
62+
executeJ(script)
63+
}
64+
65+
func executeJ(j string) {
66+
c, err := coda.New().FromJson(j)
67+
if err != nil {
68+
fmt.Fprintf(os.Stderr, "failed to initiate coda from json file: %v\n", err)
69+
os.Exit(1)
70+
}
71+
72+
err = c.Run()
73+
if err != nil {
74+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
75+
os.Exit(1)
76+
}
77+
78+
b, err := c.Marshal()
79+
if err != nil {
80+
fmt.Fprintf(os.Stderr, "failed to marshal coda script: %v\n", err)
81+
os.Exit(1)
82+
}
83+
84+
fmt.Println(string(b))
85+
}

cmd/schema.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
"github.com/yosev/coda"
8+
)
9+
10+
var schemaCmd = &cobra.Command{
11+
Use: "schema",
12+
DisableFlagsInUseLine: true,
13+
Short: "coda json schema",
14+
Run: schema,
15+
}
16+
17+
func init() {
18+
rootCmd.AddCommand(schemaCmd)
19+
}
20+
21+
func schema(cmd *cobra.Command, args []string) {
22+
fmt.Println(coda.New().Schema())
23+
}

0 commit comments

Comments
 (0)