Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 5s
CI Workflow / CI run build and linting (pull_request) Successful in 20m7s
CI Workflow / Code coverage report (pull_request) Successful in 5s
CI Workflow / CI run tests (pull_request) Failing after 21m28s
CI Workflow / Test readiness for publishing provider (pull_request) Successful in 29m1s
139 lines
3.5 KiB
Go
139 lines
3.5 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/generator/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, _ []string) error {
|
|
return publish()
|
|
},
|
|
}
|
|
|
|
func init() { //nolint:gochecknoinits //this is the standard way to set up cobra commands
|
|
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")
|
|
//nolint:gosec // this directory is not sensitive, so we can use 0750
|
|
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
|
|
}
|