Skip to content

Commit

Permalink
Use temporary directory
Browse files Browse the repository at this point in the history
  • Loading branch information
guineveresaenger committed Nov 27, 2024
1 parent a336743 commit 4e3bd12
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions dynamic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"

"github.com/blang/semver"
"github.com/opentofu/opentofu/shim/run"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag/colors"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"os"
"os/exec"

"github.com/pulumi/pulumi-terraform-bridge/dynamic/parameterize"
"github.com/pulumi/pulumi-terraform-bridge/dynamic/version"
Expand Down Expand Up @@ -158,19 +156,20 @@ func initialSetup() (info.Provider, pfbridge.ProviderMetadata, func() error) {
}
fullDocs = args.Remote.Docs
if fullDocs {
upstreamRepoDir := "terraform-provider-" + info.Name + "-v" + info.Version
// Only clone if the directory doesn't exist in the expected location
if _, err := os.Stat(upstreamRepoDir); errors.Is(err, os.ErrNotExist) {
versionWithPrefix := "v" + info.Version
ghRepo := "https://github.com/" + info.GitHubOrg + "/terraform-provider-" + info.Name

cmd := exec.Command("git", "clone", "--depth", "1", "-b", versionWithPrefix, ghRepo, upstreamRepoDir)
err = cmd.Run()
if err != nil {
return plugin.ParameterizeResponse{}, err
}
// Write the upstream files at this version to a temporary directory
tmpDir, err := os.MkdirTemp("", "upstreamRepoDir")
if err != nil {
return plugin.ParameterizeResponse{}, err
}
versionWithPrefix := "v" + info.Version
ghRepo := "https://github.com/" + info.GitHubOrg + "/terraform-provider-" + info.Name

cmd := exec.Command("git", "clone", "--depth", "1", "-b", versionWithPrefix, ghRepo, tmpDir)
err = cmd.Run()
if err != nil {
return plugin.ParameterizeResponse{}, err
}
info.UpstreamRepoPath = upstreamRepoDir
info.UpstreamRepoPath = tmpDir
}
return plugin.ParameterizeResponse{
Name: p.Name(),
Expand Down

0 comments on commit 4e3bd12

Please sign in to comment.