mirror of
https://github.com/thegeeklab/wp-s3-action.git
synced 2024-11-22 11:10:39 +00:00
added --dry-run
This commit is contained in:
parent
7e3a9e3888
commit
32492e4d02
@ -1,9 +1,6 @@
|
|||||||
# drone-s3-sync
|
# 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)
|
[![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
|
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
|
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),
|
Bucket: aws.String(p.Bucket),
|
||||||
Key: aws.String(remote),
|
Key: aws.String(remote),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil && err.(awserr.Error).Code() != "404" {
|
||||||
if err.(awserr.Error).Code() != "404" {
|
if err.(awserr.Error).Code() == "404" {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +131,11 @@ func (a *AWS) Upload(local, remote string) error {
|
|||||||
putObject.ContentEncoding = aws.String(contentEncoding)
|
putObject.ContentEncoding = aws.String(contentEncoding)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// skip upload during dry run
|
||||||
|
if a.plugin.DryRun {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
_, err = a.client.PutObject(putObject)
|
_, err = a.client.PutObject(putObject)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -246,6 +251,11 @@ func (a *AWS) Upload(local, remote string) error {
|
|||||||
copyObject.ContentEncoding = aws.String(contentEncoding)
|
copyObject.ContentEncoding = aws.String(contentEncoding)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// skip update if dry run
|
||||||
|
if a.plugin.DryRun {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
_, err = a.client.CopyObject(copyObject)
|
_, err = a.client.CopyObject(copyObject)
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
@ -272,6 +282,11 @@ func (a *AWS) Upload(local, remote string) error {
|
|||||||
putObject.ContentEncoding = aws.String(contentEncoding)
|
putObject.ContentEncoding = aws.String(contentEncoding)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// skip upload if dry run
|
||||||
|
if a.plugin.DryRun {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
_, err = a.client.PutObject(putObject)
|
_, err = a.client.PutObject(putObject)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -280,6 +295,11 @@ func (a *AWS) Upload(local, remote string) error {
|
|||||||
func (a *AWS) Redirect(path, location string) error {
|
func (a *AWS) Redirect(path, location string) error {
|
||||||
p := a.plugin
|
p := a.plugin
|
||||||
debug("Adding redirect from \"%s\" to \"%s\"", path, location)
|
debug("Adding redirect from \"%s\" to \"%s\"", path, location)
|
||||||
|
|
||||||
|
if a.plugin.DryRun {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
_, err := a.client.PutObject(&s3.PutObjectInput{
|
_, err := a.client.PutObject(&s3.PutObjectInput{
|
||||||
Bucket: aws.String(p.Bucket),
|
Bucket: aws.String(p.Bucket),
|
||||||
Key: aws.String(path),
|
Key: aws.String(path),
|
||||||
@ -292,6 +312,11 @@ func (a *AWS) Redirect(path, location string) error {
|
|||||||
func (a *AWS) Delete(remote string) error {
|
func (a *AWS) Delete(remote string) error {
|
||||||
p := a.plugin
|
p := a.plugin
|
||||||
debug("Removing remote file \"%s\"", remote)
|
debug("Removing remote file \"%s\"", remote)
|
||||||
|
|
||||||
|
if a.plugin.DryRun {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
_, err := a.client.DeleteObject(&s3.DeleteObjectInput{
|
_, err := a.client.DeleteObject(&s3.DeleteObjectInput{
|
||||||
Bucket: aws.String(p.Bucket),
|
Bucket: aws.String(p.Bucket),
|
||||||
Key: aws.String(remote),
|
Key: aws.String(remote),
|
||||||
|
6
main.go
6
main.go
@ -97,6 +97,11 @@ func main() {
|
|||||||
Usage: "id of cloudfront distribution to invalidate",
|
Usage: "id of cloudfront distribution to invalidate",
|
||||||
EnvVar: "PLUGIN_CLOUDFRONT_DISTRIBUTION",
|
EnvVar: "PLUGIN_CLOUDFRONT_DISTRIBUTION",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "dry-run",
|
||||||
|
Usage: "dry run disables api calls",
|
||||||
|
EnvVar: "DRY_RUN,PLUGIN_DRY_RUN",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "env-file",
|
Name: "env-file",
|
||||||
Usage: "source env file",
|
Usage: "source env file",
|
||||||
@ -128,6 +133,7 @@ func run(c *cli.Context) error {
|
|||||||
Metadata: c.Generic("metadata").(*DeepStringMapFlag).Get(),
|
Metadata: c.Generic("metadata").(*DeepStringMapFlag).Get(),
|
||||||
Redirects: c.Generic("redirects").(*MapFlag).Get(),
|
Redirects: c.Generic("redirects").(*MapFlag).Get(),
|
||||||
CloudFrontDistribution: c.String("cloudfront-distribution"),
|
CloudFrontDistribution: c.String("cloudfront-distribution"),
|
||||||
|
DryRun: c.Bool("dry-run"),
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugin.Exec()
|
return plugin.Exec()
|
||||||
|
@ -23,6 +23,7 @@ type Plugin struct {
|
|||||||
Metadata map[string]map[string]string
|
Metadata map[string]map[string]string
|
||||||
Redirects map[string]string
|
Redirects map[string]string
|
||||||
CloudFrontDistribution string
|
CloudFrontDistribution string
|
||||||
|
DryRun bool
|
||||||
client AWS
|
client AWS
|
||||||
jobs []job
|
jobs []job
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user