2023-01-08 03:53:03 +01:00
|
|
|
// 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"
|
|
|
|
|
2024-07-23 01:32:14 +02:00
|
|
|
"github.com/urfave/cli/v3"
|
2023-01-08 03:53:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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"`
|
2024-02-15 19:53:26 +01:00
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
|
|
|
|
// Deprecated: Please use URL instead.
|
|
|
|
Link string `json:"link,omitempty"`
|
2023-01-08 03:53:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func systemFlags() []cli.Flag {
|
|
|
|
return []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "system.name",
|
|
|
|
Usage: "system name",
|
2024-07-23 01:32:14 +02:00
|
|
|
Sources: cli.EnvVars(
|
2023-01-08 03:53:03 +01:00
|
|
|
"CI_SYSTEM_NAME",
|
2024-07-23 01:32:14 +02:00
|
|
|
),
|
2023-01-08 03:53:03 +01:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "system.host",
|
|
|
|
Usage: "system host",
|
2024-07-23 01:32:14 +02:00
|
|
|
Sources: cli.EnvVars(
|
2023-01-08 03:53:03 +01:00
|
|
|
"CI_SYSTEM_HOST",
|
|
|
|
"DRONE_SYSTEM_HOST",
|
|
|
|
"DRONE_SYSTEM_HOSTNAME",
|
2024-07-23 01:32:14 +02:00
|
|
|
),
|
2023-01-08 03:53:03 +01:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2024-02-15 19:53:26 +01:00
|
|
|
Name: "system.url",
|
|
|
|
Aliases: []string{"system.link"},
|
|
|
|
Usage: "system url",
|
2024-07-23 01:32:14 +02:00
|
|
|
Sources: cli.EnvVars(
|
2023-12-07 11:45:09 +01:00
|
|
|
"CI_SYSTEM_URL",
|
2023-01-08 03:53:03 +01:00
|
|
|
"CI_SYSTEM_LINK",
|
2024-07-23 01:32:14 +02:00
|
|
|
),
|
2023-01-08 03:53:03 +01:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "system.arch",
|
|
|
|
Usage: "system arch",
|
2024-07-23 01:32:14 +02:00
|
|
|
Sources: cli.EnvVars(
|
2023-01-08 03:53:03 +01:00
|
|
|
"CI_SYSTEM_PLATFORM",
|
|
|
|
"DRONE_STAGE_ARCH",
|
2024-07-23 01:32:14 +02:00
|
|
|
),
|
2023-01-08 03:53:03 +01:00
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "system.version",
|
|
|
|
Usage: "system version",
|
2024-07-23 01:32:14 +02:00
|
|
|
Sources: cli.EnvVars(
|
2023-01-08 03:53:03 +01:00
|
|
|
"CI_SYSTEM_VERSION",
|
|
|
|
"DRONE_SYSTEM_VERSION",
|
2024-07-23 01:32:14 +02:00
|
|
|
),
|
2023-01-08 03:53:03 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-23 01:32:14 +02:00
|
|
|
func systemFromContext(c *cli.Command) System {
|
|
|
|
url := c.String("system.url")
|
|
|
|
host := c.String("system.host")
|
2024-02-15 19:53:26 +01:00
|
|
|
if url == "" && host != "" {
|
|
|
|
// Alternative url format used by Drone.
|
2023-01-08 03:53:03 +01:00
|
|
|
proto := os.Getenv("DRONE_SYSTEM_PROTO")
|
|
|
|
if proto != "" {
|
2024-02-15 19:53:26 +01:00
|
|
|
url = proto + "://" + host
|
2023-01-08 03:53:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return System{
|
2024-07-23 01:32:14 +02:00
|
|
|
Name: c.String("system.name"),
|
2023-01-08 03:53:03 +01:00
|
|
|
Host: host,
|
2024-02-15 19:53:26 +01:00
|
|
|
URL: url,
|
|
|
|
Link: url,
|
2024-07-23 01:32:14 +02:00
|
|
|
Platform: c.String("system.arch"),
|
|
|
|
Version: c.String("system.version"),
|
2023-01-08 03:53:03 +01:00
|
|
|
}
|
|
|
|
}
|