-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
84 lines (67 loc) · 1.53 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"container/list"
"io/ioutil"
"strconv"
"strings"
"github.com/rhysd/actionlint"
)
var Memory = list.New()
var OutputString = []byte{}
type block struct {
ptr *[]byte
value []byte
}
//export WasmAlloc
func WasmAlloc(size int) *[]byte {
slice := make([]byte, size)
block := block{
ptr: &slice,
value: slice,
}
Memory.PushBack(block)
return block.ptr
}
//export WasmFree
func WasmFree(ptr *[]byte) {
for e := Memory.Front(); e != nil; e = e.Next() {
block := e.Value.(block)
if block.ptr == ptr {
Memory.Remove(e)
return
}
}
}
func serialize(errors []*actionlint.Error, target *[]byte) {
*target = []byte("[")
for i, err := range errors {
*target = append(*target, `{
"file":"`+err.Filepath+`",
"line":`+strconv.FormatInt(int64(err.Line), 10)+`,
"column":`+strconv.FormatInt(int64(err.Column), 10)+`,
"message":"`+strings.ReplaceAll(err.Message, `"`, `\"`)+`",
"kind":"`+strings.ReplaceAll(err.Kind, `"`, `\"`)+`"
}`...)
if i < len(errors)-1 {
*target = append(*target, ',')
}
}
*target = append(*target, ']', 0)
}
//export RunActionlint
func RunActionlint(input []byte, path []byte) *byte {
opts := actionlint.LinterOptions{}
linter, err := actionlint.NewLinter(ioutil.Discard, &opts)
if err != nil {
OutputString = []byte(err.Error())
return &OutputString[0]
}
errs, err := linter.Lint(string(path), input, nil)
if err != nil {
OutputString = []byte(err.Error())
return &OutputString[0]
}
serialize(errs, &OutputString)
return &OutputString[0]
}
func main() {}