Skip to content

Commit

Permalink
refactor: combine stage and step settings (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdk committed May 4, 2022
1 parent 98ccf7e commit 986fd71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ steps:
from_secret: GITHUB_TOKEN
```

You then need to configure a target pipeline `stage` and `step` name that refers to another existing step.
You then need to configure a target `step` name that refers to existing pipeline step.

```yaml
kind: pipeline
Expand All @@ -42,8 +42,7 @@ steps:
- name: drone-github-comment
image: ghcr.io/joshdk/drone-github-comment:v0.1.0
settings:
stage: build-pull-request
step: lint-code
step: build-pull-request/lint-code
```

You must also configure the `depends_on` values, since this plugin must be run after the target step finishes.
Expand Down
27 changes: 15 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,10 @@ func mainCmd() error {
// Example: true
pluginKeep := os.Getenv("PLUGIN_KEEP")

// pluginStage is a named build stage which will be used in conjunction
// with PLUGIN_STEP to find step logs.
// Example: build-pull-request
pluginStage := os.Getenv("PLUGIN_STAGE")

// pluginStep is a named build step which will be used in conjunction with
// PLUGIN_STAGE to find step logs.
// Example: lint-code
pluginStep := os.Getenv("PLUGIN_STEP")
// pluginStepFull is a named build stage and step which will be used for
// finding logs.
// Example: build-pull-request/lint-code
pluginStepFull := os.Getenv("PLUGIN_STEP")

// pluginWhen determines if logs from a successful step, or a failing step
// (or both) should be posted as a comment.
Expand Down Expand Up @@ -179,9 +174,7 @@ func mainCmd() error {
return fmt.Errorf("DRONE_TOKEN was not provided")
case githubToken == "":
return fmt.Errorf("GITHUB_TOKEN was not provided")
case pluginStage == "":
return fmt.Errorf("PLUGIN_STAGE was not provided")
case pluginStep == "":
case pluginStepFull == "":
return fmt.Errorf("PLUGIN_STEP was not provided")
}

Expand All @@ -203,6 +196,16 @@ func mainCmd() error {
pluginKeepBool = false
}

// Spit the stage and step values from the combined plugin setting.
var pluginStage, pluginStep string
parts := strings.Split(pluginStepFull, "/")
switch len(parts) {
case 2: // nolint:gomnd
pluginStage, pluginStep = parts[0], parts[1]
default:
return fmt.Errorf("PLUGIN_STEP was malformed")
}

// Parse the plugin verbatim parameter, and default to false on error.
pluginVerbatimBool, err := strconv.ParseBool(pluginVerbatim)
if err != nil {
Expand Down

0 comments on commit 986fd71

Please sign in to comment.