generated from jacobtomlinson/go-container-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
45 lines (39 loc) · 693 Bytes
/
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
package main
import (
"github.com/sethvargo/go-githubactions"
"golang.org/x/mod/modfile"
"os"
)
const (
MODFILE = "modfile"
)
var (
version string
module string
)
func main() {
action := githubactions.New()
mod := action.GetInput(MODFILE)
if mod == "" {
mod = "go.mod"
}
action.Debugf("Using %s file", mod)
data, err := os.ReadFile(mod)
if err != nil {
action.Fatalf("%e", err)
return
}
m, err := modfile.Parse(mod, data, nil)
if err != nil {
action.Fatalf("%e", err)
return
}
if m.Go != nil {
version = m.Go.Version
}
if m.Module != nil {
module = m.Module.Mod.Path
}
action.SetOutput("go_version", version)
action.SetOutput("go_module", module)
}