mirror of
https://codeberg.org/woodpecker-plugins/go-plugin.git
synced 2024-10-10 00:01:21 +02:00
67b6cdf4a6
Reviewed-on: https://codeberg.org/woodpecker-plugins/go-plugin/pulls/29 Reviewed-by: Patrick Schratz <pat-s@noreply.codeberg.org> Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de>
100 lines
2.3 KiB
Go
100 lines
2.3 KiB
Go
// Copyright 2023 Woodpecker Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// System defines runtime metadata for a ci/cd system.
|
|
type System struct {
|
|
Name string `json:"name,omitempty"`
|
|
Host string `json:"host,omitempty"`
|
|
Platform string `json:"arch,omitempty"`
|
|
Version string `json:"version,omitempty"`
|
|
URL string `json:"url,omitempty"`
|
|
|
|
// Deprecated: Please use URL instead.
|
|
Link string `json:"link,omitempty"`
|
|
}
|
|
|
|
func systemFlags() []cli.Flag {
|
|
return []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "system.name",
|
|
Usage: "system name",
|
|
Sources: cli.EnvVars(
|
|
"CI_SYSTEM_NAME",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "system.host",
|
|
Usage: "system host",
|
|
Sources: cli.EnvVars(
|
|
"CI_SYSTEM_HOST",
|
|
"DRONE_SYSTEM_HOST",
|
|
"DRONE_SYSTEM_HOSTNAME",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "system.url",
|
|
Aliases: []string{"system.link"},
|
|
Usage: "system url",
|
|
Sources: cli.EnvVars(
|
|
"CI_SYSTEM_URL",
|
|
"CI_SYSTEM_LINK",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "system.arch",
|
|
Usage: "system arch",
|
|
Sources: cli.EnvVars(
|
|
"CI_SYSTEM_PLATFORM",
|
|
"DRONE_STAGE_ARCH",
|
|
),
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "system.version",
|
|
Usage: "system version",
|
|
Sources: cli.EnvVars(
|
|
"CI_SYSTEM_VERSION",
|
|
"DRONE_SYSTEM_VERSION",
|
|
),
|
|
},
|
|
}
|
|
}
|
|
|
|
func systemFromContext(c *cli.Command) System {
|
|
url := c.String("system.url")
|
|
host := c.String("system.host")
|
|
if url == "" && host != "" {
|
|
// Alternative url format used by Drone.
|
|
proto := os.Getenv("DRONE_SYSTEM_PROTO")
|
|
if proto != "" {
|
|
url = proto + "://" + host
|
|
}
|
|
}
|
|
return System{
|
|
Name: c.String("system.name"),
|
|
Host: host,
|
|
URL: url,
|
|
Link: url,
|
|
Platform: c.String("system.arch"),
|
|
Version: c.String("system.version"),
|
|
}
|
|
}
|