mirror of
https://github.com/joshdk/drone-skip-pipeline
synced 2024-11-26 11:33:45 +01:00
feat: setting to touch file when pipeline is skipped (#13)
This commit is contained in:
parent
ca87ac8526
commit
3e066944ec
14
README.md
14
README.md
@ -54,6 +54,20 @@ clone:
|
||||
disable: true
|
||||
```
|
||||
|
||||
In order to provide some level of feature parity for older versions of DroneCI that do not support pipeline skipping, you can configure the `touch` setting with a filename that will be created in the event that the pipeline should be skipped.
|
||||
The existence of file can then be checked for in subsequent steps, where commands can then be skipped where appropriate.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- name: debug
|
||||
image: ghcr.io/joshdk/drone-skip-pipeline:v0.1.0
|
||||
settings:
|
||||
rules:
|
||||
- package.json
|
||||
- app/
|
||||
touch: .skip-pipeline
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This code is distributed under the [MIT License][license-link], see [LICENSE.txt][license-file] for more information.
|
||||
|
19
main.go
19
main.go
@ -96,6 +96,15 @@ func mainCmd() error {
|
||||
// No files were matched by any of the plugin rules. Skip the rest of the
|
||||
// pipeline.
|
||||
if skip {
|
||||
// Touch a sentinel file to signal to subsequent steps that the
|
||||
// pipeline should be skipped.
|
||||
if cfg.Touch != "" {
|
||||
log.Printf("touching file %s", cfg.Touch)
|
||||
if err := touchFile(cfg.Touch); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return errDroneSkipPipeline
|
||||
}
|
||||
|
||||
@ -111,6 +120,7 @@ type config struct {
|
||||
RepoName string `envconfig:"DRONE_REPO_NAME"`
|
||||
RepoOwner string `envconfig:"DRONE_REPO_OWNER"`
|
||||
Rules []string `envconfig:"PLUGIN_RULES"`
|
||||
Touch string `envconfig:"PLUGIN_TOUCH"`
|
||||
}
|
||||
|
||||
func loadConfig() (*config, error) {
|
||||
@ -135,3 +145,12 @@ func loadConfig() (*config, error) {
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func touchFile(filename string) error {
|
||||
file, err := os.Create(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return file.Close()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user