mirror of
https://github.com/thegeeklab/wp-s3-action.git
synced 2024-11-21 14:50:39 +00:00
added --dry-run
This commit is contained in:
parent
7e3a9e3888
commit
32492e4d02
@ -1,9 +1,6 @@
|
||||
# drone-s3-sync
|
||||
|
||||
[![Build Status](http://beta.drone.io/api/badges/drone-plugins/drone-s3-sync/status.svg)](http://beta.drone.io/drone-plugins/drone-s3-sync)
|
||||
[![Go Doc](https://godoc.org/github.com/drone-plugins/drone-s3-sync?status.svg)](http://godoc.org/github.com/drone-plugins/drone-s3-sync)
|
||||
[![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-s3-sync)](https://goreportcard.com/report/github.com/drone-plugins/drone-s3-sync)
|
||||
[![Join the chat at https://gitter.im/drone/drone](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/drone/drone)
|
||||
|
||||
Drone plugin to synchronize a directory with an Amazon S3 Bucket. For the
|
||||
usage information and a listing of the available options please take a look at
|
||||
|
29
aws.go
29
aws.go
@ -108,8 +108,8 @@ func (a *AWS) Upload(local, remote string) error {
|
||||
Bucket: aws.String(p.Bucket),
|
||||
Key: aws.String(remote),
|
||||
})
|
||||
if err != nil {
|
||||
if err.(awserr.Error).Code() != "404" {
|
||||
if err != nil && err.(awserr.Error).Code() != "404" {
|
||||
if err.(awserr.Error).Code() == "404" {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -131,6 +131,11 @@ func (a *AWS) Upload(local, remote string) error {
|
||||
putObject.ContentEncoding = aws.String(contentEncoding)
|
||||
}
|
||||
|
||||
// skip upload during dry run
|
||||
if a.plugin.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = a.client.PutObject(putObject)
|
||||
return err
|
||||
}
|
||||
@ -246,6 +251,11 @@ func (a *AWS) Upload(local, remote string) error {
|
||||
copyObject.ContentEncoding = aws.String(contentEncoding)
|
||||
}
|
||||
|
||||
// skip update if dry run
|
||||
if a.plugin.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = a.client.CopyObject(copyObject)
|
||||
return err
|
||||
} else {
|
||||
@ -272,6 +282,11 @@ func (a *AWS) Upload(local, remote string) error {
|
||||
putObject.ContentEncoding = aws.String(contentEncoding)
|
||||
}
|
||||
|
||||
// skip upload if dry run
|
||||
if a.plugin.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = a.client.PutObject(putObject)
|
||||
return err
|
||||
}
|
||||
@ -280,6 +295,11 @@ func (a *AWS) Upload(local, remote string) error {
|
||||
func (a *AWS) Redirect(path, location string) error {
|
||||
p := a.plugin
|
||||
debug("Adding redirect from \"%s\" to \"%s\"", path, location)
|
||||
|
||||
if a.plugin.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := a.client.PutObject(&s3.PutObjectInput{
|
||||
Bucket: aws.String(p.Bucket),
|
||||
Key: aws.String(path),
|
||||
@ -292,6 +312,11 @@ func (a *AWS) Redirect(path, location string) error {
|
||||
func (a *AWS) Delete(remote string) error {
|
||||
p := a.plugin
|
||||
debug("Removing remote file \"%s\"", remote)
|
||||
|
||||
if a.plugin.DryRun {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := a.client.DeleteObject(&s3.DeleteObjectInput{
|
||||
Bucket: aws.String(p.Bucket),
|
||||
Key: aws.String(remote),
|
||||
|
6
main.go
6
main.go
@ -97,6 +97,11 @@ func main() {
|
||||
Usage: "id of cloudfront distribution to invalidate",
|
||||
EnvVar: "PLUGIN_CLOUDFRONT_DISTRIBUTION",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "dry-run",
|
||||
Usage: "dry run disables api calls",
|
||||
EnvVar: "DRY_RUN,PLUGIN_DRY_RUN",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "env-file",
|
||||
Usage: "source env file",
|
||||
@ -128,6 +133,7 @@ func run(c *cli.Context) error {
|
||||
Metadata: c.Generic("metadata").(*DeepStringMapFlag).Get(),
|
||||
Redirects: c.Generic("redirects").(*MapFlag).Get(),
|
||||
CloudFrontDistribution: c.String("cloudfront-distribution"),
|
||||
DryRun: c.Bool("dry-run"),
|
||||
}
|
||||
|
||||
return plugin.Exec()
|
||||
|
Loading…
Reference in New Issue
Block a user