4b0fb92fba
- provides support for compiling Boards directly into the Mattermost suite server - a ServicesAPI interface replaces the PluginAPI to allow for implementations coming from pluginAPI and suite server. - a new product package provides a place to register Boards as a suite product and handles life-cycle events - a new boards package replaces much of the mattermost-plugin logic, allowing this to be shared between plugin and product - Boards now uses module workspaces; run make setup-go-work
93 lines
1.7 KiB
Go
93 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
filename = "go.work"
|
|
)
|
|
|
|
func main() {
|
|
force := false
|
|
if len(os.Args) == 2 && strings.ToLower(os.Args[1]) == "-f" {
|
|
force = true
|
|
}
|
|
|
|
if _, err := os.Stat(filename); err == nil && !force {
|
|
// go.work already exists and force flag not specified
|
|
fmt.Fprintln(os.Stdout, "go.work already exists and -f (force) not specified; nothing to do.")
|
|
os.Exit(0)
|
|
}
|
|
|
|
f, err := os.Create(filename)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "error creating %s: %s", filename, err.Error())
|
|
os.Exit(-1)
|
|
}
|
|
defer f.Close()
|
|
|
|
isCI := isCI()
|
|
content := makeGoWork(isCI)
|
|
|
|
_, err = f.WriteString(content)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "error writing %s: %s", filename, err.Error())
|
|
os.Exit(-1)
|
|
}
|
|
|
|
fmt.Fprintln(os.Stdout, "go.work written successfully.")
|
|
}
|
|
|
|
func makeGoWork(ci bool) string {
|
|
var b strings.Builder
|
|
|
|
b.WriteString("go 1.18\n\n")
|
|
b.WriteString("use ./mattermost-plugin\n")
|
|
b.WriteString("use ./server\n")
|
|
|
|
if ci {
|
|
b.WriteString("use ./linux\n")
|
|
} else {
|
|
b.WriteString("use ../mattermost-server\n")
|
|
b.WriteString("use ../enterprise\n")
|
|
}
|
|
|
|
return b.String()
|
|
}
|
|
|
|
func isCI() bool {
|
|
vars := map[string]bool{
|
|
// var name: must_be_true (false means being defined is enough)
|
|
"CIRCLECI": true,
|
|
"GITHUB_ACTIONS": true,
|
|
"GITLAB_CI": false,
|
|
"TRAVIS": true,
|
|
}
|
|
|
|
for name, mustBeTrue := range vars {
|
|
if isEnvVarTrue(name, mustBeTrue) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func isEnvVarTrue(name string, mustBeTrue bool) bool {
|
|
val, ok := os.LookupEnv(name)
|
|
if !ok {
|
|
return false
|
|
}
|
|
|
|
if !mustBeTrue {
|
|
return true
|
|
}
|
|
|
|
switch strings.ToLower(val) {
|
|
case "t", "1", "true", "y", "yes":
|
|
return true
|
|
}
|
|
return false
|
|
}
|