2020-02-10 01:03:12 -06:00
package model
import (
2020-05-04 07:40:11 -05:00
"fmt"
2020-02-10 01:03:12 -06:00
"io"
2020-05-03 22:59:13 -05:00
"strings"
2020-02-10 01:03:12 -06:00
2020-02-10 18:35:00 -06:00
"gopkg.in/yaml.v3"
2020-02-10 01:03:12 -06:00
)
// ActionRunsUsing is the type of runner for the action
type ActionRunsUsing string
2020-05-04 07:40:11 -05:00
func ( a * ActionRunsUsing ) UnmarshalYAML ( unmarshal func ( interface { } ) error ) error {
var using string
if err := unmarshal ( & using ) ; err != nil {
return err
}
// Force input to lowercase for case insensitive comparison
format := ActionRunsUsing ( strings . ToLower ( using ) )
switch format {
2021-12-22 13:34:18 -06:00
case ActionRunsUsingNode16 , ActionRunsUsingNode12 , ActionRunsUsingDocker , ActionRunsUsingComposite :
2020-05-04 07:40:11 -05:00
* a = format
default :
return fmt . Errorf ( fmt . Sprintf ( "The runs.using key in action.yml must be one of: %v, got %s" , [ ] string {
2021-04-02 15:40:44 -05:00
ActionRunsUsingComposite ,
2020-05-04 07:40:11 -05:00
ActionRunsUsingDocker ,
ActionRunsUsingNode12 ,
2021-12-22 13:34:18 -06:00
ActionRunsUsingNode16 ,
2020-05-04 07:40:11 -05:00
} , format ) )
}
return nil
}
2020-02-10 01:03:12 -06:00
const (
// ActionRunsUsingNode12 for running with node12
ActionRunsUsingNode12 = "node12"
2021-12-22 13:34:18 -06:00
// ActionRunsUsingNode12 for running with node16
ActionRunsUsingNode16 = "node16"
2020-02-10 01:03:12 -06:00
// ActionRunsUsingDocker for running with docker
ActionRunsUsingDocker = "docker"
2021-04-02 15:40:44 -05:00
// ActionRunsUsingComposite for running composite
ActionRunsUsingComposite = "composite"
2020-02-10 01:03:12 -06:00
)
2021-03-30 14:26:25 -05:00
// ActionRuns are a field in Action
type ActionRuns struct {
Using ActionRunsUsing ` yaml:"using" `
Env map [ string ] string ` yaml:"env" `
Main string ` yaml:"main" `
Image string ` yaml:"image" `
2021-11-13 13:43:31 -06:00
Entrypoint string ` yaml:"entrypoint" `
2021-03-30 14:26:25 -05:00
Args [ ] string ` yaml:"args" `
2021-04-02 15:40:44 -05:00
Steps [ ] Step ` yaml:"steps" `
2021-03-30 14:26:25 -05:00
}
2020-02-10 01:03:12 -06:00
// Action describes a metadata file for GitHub actions. The metadata filename must be either action.yml or action.yaml. The data in the metadata file defines the inputs, outputs and main entrypoint for your action.
type Action struct {
Name string ` yaml:"name" `
Author string ` yaml:"author" `
Description string ` yaml:"description" `
Inputs map [ string ] Input ` yaml:"inputs" `
Outputs map [ string ] Output ` yaml:"outputs" `
2021-03-30 14:26:25 -05:00
Runs ActionRuns ` yaml:"runs" `
Branding struct {
2020-02-10 01:03:12 -06:00
Color string ` yaml:"color" `
Icon string ` yaml:"icon" `
} ` yaml:"branding" `
}
// Input parameters allow you to specify data that the action expects to use during runtime. GitHub stores input parameters as environment variables. Input ids with uppercase letters are converted to lowercase during runtime. We recommended using lowercase input ids.
type Input struct {
Description string ` yaml:"description" `
Required bool ` yaml:"required" `
Default string ` yaml:"default" `
}
// Output parameters allow you to declare data that an action sets. Actions that run later in a workflow can use the output data set in previously run actions. For example, if you had an action that performed the addition of two inputs (x + y = z), the action could output the sum (z) for other actions to use as an input.
type Output struct {
Description string ` yaml:"description" `
2021-04-02 15:40:44 -05:00
Value string ` yaml:"value" `
2020-02-10 01:03:12 -06:00
}
// ReadAction reads an action from a reader
func ReadAction ( in io . Reader ) ( * Action , error ) {
a := new ( Action )
err := yaml . NewDecoder ( in ) . Decode ( a )
2021-12-22 13:19:50 -06:00
if err != nil {
return nil , err
}
return a , nil
2020-02-10 01:03:12 -06:00
}