Browse Source

Move to urfave and add docs

Signed-off-by: jolheiser <john.olheiser@gmail.com>
main
jolheiser 8 months ago
parent
commit
458b2a385b
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
  1. 45
      DOCS.md
  2. 9
      README.md
  3. 53
      app.go
  4. 23
      docs.go
  5. 4
      go.mod
  6. 13
      go.sum
  7. 41
      main.go

45
DOCS.md

@ -0,0 +1,45 @@
# NAME
woodpecker-netlify - Woodpecker plugin to deploy to Netlify
# SYNOPSIS
woodpecker-netlify
```
[--build-dir]=[value]
[--gitea-token]=[value]
[--gitea-url]=[value]
[--issue-comment]=[value]
[--netlify-auth-token]=[value]
[--netlify-side-id]=[value]
```
**Usage**:
```
woodpecker-netlify [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
```
# GLOBAL OPTIONS
**--build-dir**="": Build Directory to Deploy
**--gitea-token**="": Gitea Token
**--gitea-url**="": Gitea URL
**--issue-comment**="": Issue Comment (default:
Hi @${CI_COMMIT_AUTHOR}!
Thank you for creating a PR!
[I've deployed a preview of the changes here.](${FULL_PREVIEW_URL})
> Beep boop, I'm a bot. :robot:
)
**--netlify-auth-token**="": Netlify Auth Token
**--netlify-side-id**="": Netlify Site ID

9
README.md

@ -0,0 +1,9 @@
# Woodpecker Netlify
[Woodpecker](https://github.com/woodpecker-ci/woodpecker) plugin to deploy site to [Netlify](https://www.netlify.com/).
[CLI Docs](DOCS.md)
## License
[MIT](LICENSE)

53
app.go

@ -0,0 +1,53 @@
package main
import "github.com/urfave/cli/v2"
func app() *cli.App {
app := cli.NewApp()
app.Name = "woodpecker-netlify"
app.Usage = "Woodpecker plugin to deploy to Netlify"
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "netlify-side-id",
Usage: "Netlify Site ID",
EnvVars: []string{"NETLIFY_SITE_ID", "PLUGIN_NETLIFY_SITE_ID"},
},
&cli.StringFlag{
Name: "netlify-auth-token",
Usage: "Netlify Auth Token",
EnvVars: []string{"NETLIFY_AUTH_TOKEN", "PLUGIN_NETLIFY_AUTH_TOKEN"},
},
&cli.StringFlag{
Name: "gitea-token",
Usage: "Gitea Token",
EnvVars: []string{"GITEA_TOKEN", "PLUGIN_GITEA_TOKEN"},
},
&cli.StringFlag{
Name: "gitea-url",
Usage: "Gitea URL",
EnvVars: []string{"GITEA_URL", "PLUGIN_GITEA_URL"},
},
&cli.StringFlag{
Name: "build-dir",
Usage: "Build Directory to Deploy",
EnvVars: []string{"BUILD_DIR", "PLUGIN_BUILD_DIR"},
},
&cli.StringFlag{
Name: "issue-comment",
Usage: "Issue Comment",
Value: defaultComment,
EnvVars: []string{"ISSUE_COMMENT", "PLUGIN_ISSUE_COMMENT"},
},
}
return app
}
var defaultComment = `
Hi @${CI_COMMIT_AUTHOR}!
Thank you for creating a PR!
[I've deployed a preview of the changes here.](${FULL_PREVIEW_URL})
> Beep boop, I'm a bot. :robot:
`

23
docs.go

@ -0,0 +1,23 @@
//go:build generate
package main
import "os"
//go:generate go run app.go docs.go
func main() {
md, err := app().ToMarkdown()
if err != nil {
panic(err)
}
fi, err := os.Create("DOCS.md")
if err != nil {
panic(err)
}
defer fi.Close()
if _, err := fi.WriteString(md); err != nil {
panic(err)
}
}

4
go.mod

@ -8,8 +8,8 @@ require (
github.com/go-openapi/strfmt v0.19.11
github.com/gosimple/slug v1.11.2
github.com/netlify/open-api v1.4.0
github.com/peterbourgon/ff/v3 v3.1.2
github.com/rs/zerolog v1.26.0
github.com/urfave/cli/v2 v2.3.1-0.20211205195634-e8d81738896c
go.jolheiser.com/woodpecker-env v0.0.0-20211211171841-abc1ed471fa1
)
@ -23,6 +23,7 @@ require (
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect
github.com/cenkalti/backoff/v4 v4.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/go-openapi/analysis v0.19.16 // indirect
github.com/go-openapi/errors v0.19.9 // indirect
@ -40,6 +41,7 @@ require (
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mitchellh/mapstructure v1.4.0 // indirect
github.com/rsc/goversion v1.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
go.mongodb.org/mongo-driver v1.4.4 // indirect
golang.org/x/mod v0.5.1 // indirect

13
go.sum

@ -53,6 +53,9 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@ -283,8 +286,6 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo=
github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
github.com/peterbourgon/ff/v3 v3.1.2 h1:0GNhbRhO9yHA4CC27ymskOsuRpmX0YQxwxM9UPiP6JM=
github.com/peterbourgon/ff/v3 v3.1.2/go.mod h1:XNJLY8EIl6MjMVjBS4F0+G0LYoAqs0DTa4rmHHukKDE=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@ -310,7 +311,11 @@ github.com/rs/zerolog v1.26.0 h1:ORM4ibhEZeTeQlCojCK2kPz1ogAY4bGs4tD+SaAdGaE=
github.com/rs/zerolog v1.26.0/go.mod h1:yBiM87lvSqX8h0Ww4sdzNSkVYZ8dL2xjZJG1lAuGZEo=
github.com/rsc/goversion v1.2.0 h1:zVF4y5ciA/rw779S62bEAq4Yif1cBc/UwRkXJ2xZyT4=
github.com/rsc/goversion v1.2.0/go.mod h1:Tf/O0TQyfRvp7NelXAyfXYRKUO+LX3KNgXc8ALRUv4k=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
@ -346,7 +351,10 @@ github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhV
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/toqueteos/webbrowser v1.2.0/go.mod h1:XWoZq4cyp9WeUeak7w7LXRUQf1F1ATJMir8RTqb4ayM=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli/v2 v2.3.1-0.20211205195634-e8d81738896c h1:AOaGBsDA+L9XCwHTGvxN1aHs685BVlrfqVqthtVg5XQ=
github.com/urfave/cli/v2 v2.3.1-0.20211205195634-e8d81738896c/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
github.com/wacul/ptr v0.0.0-20170209030335-91632201dfc8/go.mod h1:BD0gjsZrCwtoR+yWDB9v2hQ8STlq9tT84qKfa+3txOc=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
@ -497,6 +505,7 @@ gopkg.in/square/go-jose.v2 v2.4.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

41
main.go

@ -1,55 +1,42 @@
package main
import (
"flag"
"os"
"strconv"
"github.com/peterbourgon/ff/v3"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
env "go.jolheiser.com/woodpecker-env"
)
func main() {
fs := flag.NewFlagSet("woodpecker-netlify", flag.ExitOnError)
netlifySiteID := fs.String("netlify-site-id", "", "Netlify Site ID")
netlifyAuthToken := fs.String("netlify-auth-token", "", "Netlify Auth Token")
giteaToken := fs.String("gitea-token", "", "Gitea Token")
giteaURL := fs.String("gitea-url", "", "Gitea Base URL")
buildDir := fs.String("build-dir", "dist", "Build Directory")
comment := fs.String("comment", defaultComment, "Issue Comment")
if err := ff.Parse(fs, os.Args[1:], ff.WithEnvVarNoPrefix()); err != nil {
log.Fatal().Err(err).Msg("")
app := app()
app.Action = doMain
if err := app.Run(os.Args); err != nil {
log.Err(err).Msg("")
}
}
func doMain(ctx *cli.Context) error {
prIndex, err := strconv.Atoi(env.CI_PULL_REQUEST)
if err != nil {
log.Fatal().Err(err).Msg("")
return err
}
// Netlify deploy
deploy, err := netlifyDeploy(*netlifyAuthToken, *netlifySiteID, *buildDir, prIndex)
deploy, err := netlifyDeploy(ctx.String("netlify-auth-token"), ctx.String("netlify-site-id"), ctx.String("build-dir"), prIndex)
if err != nil {
log.Fatal().Err(err).Msg("")
return err
}
if err := os.Setenv("FULL_PREVIEW_URL", deploy.DeployURL); err != nil {
log.Fatal().Err(err).Msg("")
return err
}
// Gitea comment
c, err := giteaComment(*giteaURL, *giteaToken, *comment, prIndex)
c, err := giteaComment(ctx.String("gitea-url"), ctx.String("gitea-token"), ctx.String("issue-comment"), prIndex)
if err != nil {
log.Fatal().Err(err).Msg("")
return err
}
log.Info().Msgf("Issue Comment created at %s", c.HTMLURL)
return nil
}
var defaultComment = `
Hi ${CI_COMMIT_AUTHOR}!
Thank you for creating a PR!
[I've deployed a preview of the changes here.](${FULL_PREVIEW_URL})
> Beep boop, I'm a bot. :robot:
`

Loading…
Cancel
Save