Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exit code flag #77

Merged
merged 5 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,37 @@ steps:
environment:
CGO_ENABLED: 0

- name: release-snapshot-dev
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the reviewer: These newly added steps ensure dev tagged container up-to-date. That particular container is used to test the plugin on its on CI pipeline.

image: goreleaser/goreleaser:v0.109
commands:
- apk add --update make upx
- goreleaser release --rm-dist --snapshot
- echo "$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)" > .tags
environment:
GITHUB_TOKEN:
from_secret: github_token

- name: release-docker-dev
image: plugins/docker
settings:
build_args_from_env:
- BUILD_DATE
- DOCKERFILE_PATH
- VCS_REF
- VERSION
dockerfile: docker/Dockerfile.linux.386
environment:
- "BUILD_DATE=$(date -u +\"%Y-%m-%dT%H:%M:%S%Z\")"
- "DOCKERFILE_PATH=\"/docker/Dockerfile.linux.386\""
- VCS_REF=$(git rev-parse --short HEAD)
- VERSION=$(git describe --always --tags --dirty)
password:
from_secret: docker_password
repo: meltwater/drone-cache
tags: dev
username:
from_secret: docker_username

- name: rebuild-cache
pull: true
image: meltwater/drone-cache:dev
Expand All @@ -62,6 +93,7 @@ steps:
region: eu-west-1
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand All @@ -78,6 +110,7 @@ steps:
region: eu-west-1
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand All @@ -95,6 +128,7 @@ steps:
region: eu-west-1
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand All @@ -109,6 +143,7 @@ steps:
mount:
- vendor
rebuild: true
exit_code: true
volumes:
- name: cache
path: /tmp/cache
Expand Down Expand Up @@ -166,6 +201,7 @@ steps:
restore: true
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand All @@ -183,6 +219,7 @@ steps:
restore: true
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand All @@ -197,6 +234,7 @@ steps:
mount:
- vendor
restore: true
exit_code: true
volumes:
- name: cache
path: /tmp/cache
Expand All @@ -219,6 +257,7 @@ steps:
restore: true
path_style: true
endpoint: filestorage:9000
exit_code: true
environment:
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Nothing.
[#77](https://github.com/meltwater/drone-cache/pull/77) Adds a new CLI hidden flag to be used for tests.
[#68](https://github.com/meltwater/drone-cache/pull/68) Introduces new storage backend, sFTP.

### Changed

Expand Down
19 changes: 18 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ func main() {
Usage: "debug",
EnvVar: "PLUGIN_DEBUG, DEBUG",
},
cli.BoolFlag{
Name: "exit-code, ex",
Usage: "always exit with exit code, disable silent fails for known errors",
Hidden: true,
EnvVar: "PLUGIN_EXIT_CODE, EXIT_CODE",
},

// Volume specific Config args

Expand Down Expand Up @@ -319,7 +325,7 @@ func main() {
EnvVar: "SFTP_HOST",
},
cli.StringFlag{
Name: "sftp-host",
Name: "sftp-port",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the reviewer: This minor issue has introduced by the previous PR.

Usage: "sftp port",
EnvVar: "SFTP_PORT",
},
Expand Down Expand Up @@ -405,10 +411,21 @@ func run(c *cli.Context) error {
}

err := plg.Exec()
if err == nil {
return nil
}

if c.Bool("exit-code") {
// If it is exit-code enabled, always exit with error
log.Println("silent fails disabled, exiting with status code on error")
return err
}

if _, ok := err.(plugin.Error); ok {
// If it is an expected error log it, handle it gracefully
log.Println(err)
return nil
}

return err
}