Woodpecker Plugin for creating netlify previews on PRs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1007 B

package main
import (
"os"
"strconv"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
env "go.jolheiser.com/woodpecker-env"
)
func main() {
app := app()
app.Action = doMain
if err := app.Run(os.Args); err != nil {
log.Err(err).Msg("")
}
}
func doMain(ctx *cli.Context) error {
var prIndex int
if env.CI_PULL_REQUEST != "" {
var err error
prIndex, err = strconv.Atoi(env.CI_PULL_REQUEST)
if err != nil {
return err
}
}
// Netlify deploy
deploy, err := netlifyDeploy(ctx.String("netlify-auth-token"), ctx.String("netlify-site-id"), ctx.String("build-dir"), prIndex, ctx.Bool("prod"))
if err != nil {
return err
}
if err := os.Setenv("FULL_PREVIEW_URL", deploy.DeployURL); err != nil {
return err
}
// Gitea comment
if prIndex > 0 {
c, err := giteaComment(ctx.String("gitea-url"), ctx.String("gitea-token"), ctx.String("issue-comment"), prIndex)
if err != nil {
return err
}
log.Info().Msgf("Issue Comment created at %s", c.HTMLURL)
}
return nil
}