Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 6s
CI Workflow / CI (pull_request) Failing after 16m49s
CI Workflow / Code coverage report (pull_request) Has been skipped
CI Workflow / Test readiness for publishing provider (pull_request) Successful in 18m3s
126 lines
3.3 KiB
Go
126 lines
3.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io/fs"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
publish2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/cmd/cmd/publish"
|
|
)
|
|
|
|
var (
|
|
namespace string
|
|
domain string
|
|
providerName string
|
|
distPath string
|
|
repoName string
|
|
version string
|
|
gpgFingerprint string
|
|
gpgPubKeyFile string
|
|
)
|
|
|
|
var publishCmd = &cobra.Command{
|
|
Use: "publish",
|
|
Short: "Publish terraform provider",
|
|
Long: `...`,
|
|
RunE: func(_ *cobra.Command, args []string) error {
|
|
return publish()
|
|
},
|
|
}
|
|
|
|
func init() { // nolint: gochecknoinits
|
|
publishCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "Namespace for the Terraform registry.")
|
|
publishCmd.Flags().StringVarP(&domain, "domain", "d", "", "Domain for the Terraform registry.")
|
|
publishCmd.Flags().StringVarP(&providerName, "providerName", "p", "", "ProviderName for the Terraform registry.")
|
|
publishCmd.Flags().StringVarP(&distPath, "distPath", "x", "dist", "Dist Path for the Terraform registry.")
|
|
publishCmd.Flags().StringVarP(&repoName, "repoName", "r", "", "RepoName for the Terraform registry.")
|
|
publishCmd.Flags().StringVarP(&version, "version", "v", "", "Version for the Terraform registry.")
|
|
publishCmd.Flags().StringVarP(&gpgFingerprint, "gpgFingerprint", "f", "", "GPG Fingerprint for the Terraform registry.")
|
|
publishCmd.Flags().StringVarP(&gpgPubKeyFile, "gpgPubKeyFile", "k", "", "GPG PubKey file name for the Terraform registry.")
|
|
|
|
err := publishCmd.MarkFlagRequired("namespace")
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = publishCmd.MarkFlagRequired("domain")
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = publishCmd.MarkFlagRequired("providerName")
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = publishCmd.MarkFlagRequired("gpgFingerprint")
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = publishCmd.MarkFlagRequired("gpgPubKeyFile")
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = publishCmd.MarkFlagRequired("repoName")
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = publishCmd.MarkFlagRequired("version")
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = publishCmd.MarkFlagRequired("gpgFingerprint")
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = publishCmd.MarkFlagRequired("gpgPubKeyFile")
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
func NewPublishCmd() *cobra.Command {
|
|
return publishCmd
|
|
}
|
|
|
|
func publish() error {
|
|
log.Println("📦 Packaging Terraform Provider for private registry...")
|
|
p := publish2.Provider{
|
|
Namespace: namespace,
|
|
Provider: providerName,
|
|
DistPath: filepath.Clean(distPath) + "/",
|
|
RepoName: repoName,
|
|
Version: version,
|
|
GpgFingerprint: gpgFingerprint,
|
|
GpgPubKeyFile: gpgPubKeyFile,
|
|
Domain: domain,
|
|
}
|
|
err := p.GetRoot()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Create release dir - only the contents of this need to be uploaded to S3
|
|
log.Printf("* Creating release directory")
|
|
err = os.MkdirAll(path.Join(p.RootPath, "release"), os.ModePerm)
|
|
if err != nil && !errors.Is(err, fs.ErrExist) {
|
|
return fmt.Errorf("error creating '%s' dir: %w", path.Join(p.RootPath, "release"), err)
|
|
}
|
|
|
|
// Create .wellKnown directory and terraform.json file
|
|
err = p.CreateWellKnown()
|
|
if err != nil {
|
|
return fmt.Errorf("error creating '.well-known' dir: %w", err)
|
|
}
|
|
|
|
err = p.CreateV1Dir()
|
|
if err != nil {
|
|
return fmt.Errorf("error creating 'v1' dir: %w", err)
|
|
}
|
|
|
|
log.Println("📦 Packaged Terraform Provider for private registry.")
|
|
return nil
|
|
}
|