Added direct publishing to Netlify
This commit is contained in:
parent
8136655336
commit
a59008b3e8
15 changed files with 695 additions and 19 deletions
|
|
@ -3,7 +3,13 @@ package publisher
|
|||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"emperror.dev/errors"
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/netlify/open-api/v2/go/porcelain"
|
||||
netlify_ctx "github.com/netlify/open-api/v2/go/porcelain/context"
|
||||
"lmika.dev/lmika/weiro/layouts/simplecss"
|
||||
"lmika.dev/lmika/weiro/models"
|
||||
"lmika.dev/lmika/weiro/models/pubmodel"
|
||||
|
|
@ -71,10 +77,33 @@ func (p *Publisher) publishSite(ctx context.Context, pubSite pubmodel.Site, targ
|
|||
}
|
||||
|
||||
switch target.TargetType {
|
||||
case models.PublishTargetTypeLocalFS:
|
||||
case "localfs":
|
||||
log.Printf("Building site at %s", target.TargetRef)
|
||||
return sb.BuildSite(target.TargetRef)
|
||||
case "netlify":
|
||||
return func() error {
|
||||
tmpDir, err := os.MkdirTemp("", "weiro-publish")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
if err := sb.BuildSite(tmpDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx = netlify_ctx.WithAuthInfo(ctx, runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error {
|
||||
return r.SetHeaderParam("Authorization", "Bearer "+target.TargetKey)
|
||||
}))
|
||||
|
||||
client := porcelain.Default
|
||||
_, err = client.DeploySite(ctx, porcelain.DeployOptions{
|
||||
SiteID: target.TargetRef,
|
||||
Dir: tmpDir,
|
||||
})
|
||||
return err
|
||||
}()
|
||||
}
|
||||
|
||||
return nil
|
||||
return errors.New("unknown target type")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue