Skip to content

Commit

Permalink
feat: create run using config from repo (#466)
Browse files Browse the repository at this point in the history
Neither OTF (nor TFC) currently permits, in a single API call, creating
a run using configuration from a VCS repo (assuming the run's workspace
is connected to a VCS repo). Instead the user/client has to manually
invoke several operations:

1. retrieve tarball of vcs repo contents
2. create config version and upload tarball to config version
3. create run, specifying aforementioned config version

Step 1 can be particularly onerous for the client, because connectivity
and credentials are needed to access the repo, as well as necessary
tooling, (curl, git, or equivalent libs in a programmatic context).

This PR introduces a "magic string", `__pull_vcs__`, that if specified
in place of the configuration version ID when creating the run,
instructs OTF to perform those operations on behalf of the client.

Using a magic string rather than introducing another API endpoint means
the existing APIs and SDKs can be used, including `go-tfe`.

Note: I've also taken this opportunity to refactor out the "run
starter", which has been folded into the "run factory".
  • Loading branch information
leg100 authored Jun 14, 2023
1 parent 3f9c31e commit 885f786
Show file tree
Hide file tree
Showing 16 changed files with 348 additions and 260 deletions.
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ require (
github.com/gorilla/schema v1.2.0
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-retryablehttp v0.7.1
github.com/hashicorp/go-retryablehttp v0.7.2
github.com/hashicorp/go-tfe v1.27.0
github.com/hashicorp/hcl/v2 v2.10.0
github.com/hashicorp/terraform-config-inspect v0.0.0-20221020162138-81db043ad408
github.com/iancoleman/strcase v0.2.0
Expand All @@ -43,7 +44,7 @@ require (
github.com/r3labs/sse/v2 v2.8.1
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.4
github.com/xanzy/go-gitlab v0.73.1
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
golang.org/x/mod v0.8.0
Expand Down Expand Up @@ -84,7 +85,10 @@ require (
github.com/googleapis/gax-go/v2 v2.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-slug v0.11.1 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/jsonapi v0.0.0-20210826224640-ee7dae0fb22d // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand Down
21 changes: 18 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
github.com/googleapis/gax-go/v2 v2.8.0 h1:UBtEZqx1bjXtOQ5BVTkuYghXrr3N4V123VKJK67vJZc=
github.com/googleapis/gax-go/v2 v2.8.0/go.mod h1:4orTrqY6hXxxaUL4LHIPl6lGo8vAE38/qKbhSAKP6QI=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
Expand Down Expand Up @@ -328,20 +329,29 @@ github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iP
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ=
github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0=
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-slug v0.11.1 h1:c6lLdQnlhUWbS5I7hw8SvfymoFuy6EmiFDedy6ir994=
github.com/hashicorp/go-slug v0.11.1/go.mod h1:Ib+IWBYfEfJGI1ZyXMGNbu2BU+aa3Dzu41RKLH301v4=
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-tfe v1.27.0 h1:g+85TZfdUZOhIEkdDKRO8/q2JflhWB9Ne0V1xJOr4nE=
github.com/hashicorp/go-tfe v1.27.0/go.mod h1:gu0DD6yf7K9P9IcuM4Wjl1grKYCa/o3oRRX5BQ+xEnY=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/hcl/v2 v2.10.0 h1:1S1UnuhDGlv3gRFV4+0EdwB+znNP5HmcGbIqwnSCByg=
github.com/hashicorp/hcl/v2 v2.10.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
github.com/hashicorp/jsonapi v0.0.0-20210826224640-ee7dae0fb22d h1:9ARUJJ1VVynB176G1HCwleORqCaXm/Vx0uUi0dL26I0=
github.com/hashicorp/jsonapi v0.0.0-20210826224640-ee7dae0fb22d/go.mod h1:Yog5+CPEM3c99L1CL2CFCYoSzgWm5vTU58idbRUaLik=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
Expand Down Expand Up @@ -422,6 +432,7 @@ github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
Expand Down Expand Up @@ -614,7 +625,9 @@ github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrf
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.13.0 h1:Dx1kYM01xsSqKPno3aqLnrwac2LetPvN23diwyr69Qs=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/sowiner/lrserver v0.0.0-20230123160823-795409868576 h1:GpUML9gWdQuNHq2kmjl10l3Oa1LJ+CiJT6Q67AvV0dQ=
github.com/sowiner/lrserver v0.0.0-20230123160823-795409868576/go.mod h1:hVi7G9lpYYueFVHEJdkIm9MaunP66DRm9I+sbPLJcSU=
Expand Down Expand Up @@ -648,8 +661,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down Expand Up @@ -1102,6 +1116,7 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<button id="queue-destroy-plan-button" class="delete" {{ insufficient $canCreateRun }} onclick="return confirm('This will destroy all infrastructure in this workspace. Please confirm.')">
Queue destroy plan
</button>
<input type="hidden" name="connected" value="{{ ne .Workspace.Connection nil }}">
<input name="operation" value="destroy-all" type="hidden">
</form>
<form action="{{ deleteWorkspacePath .Workspace.ID }}" method="POST">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<div class="actions-container">
<h5>Actions</h5>
<form id="workspace-start-run-form" action="{{ startRunWorkspacePath .Workspace.ID }}" method="POST">
<input type="hidden" name="connected" value="{{ ne .Workspace.Connection nil }}">
<select name="operation" id="start-run-operation" onchange="this.form.submit()">
<option value="" selected>-- start run --</option>
<option value="plan-only">plan only</option>
Expand Down
84 changes: 84 additions & 0 deletions internal/integration/run_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package integration

import (
"testing"

tfe "github.com/hashicorp/go-tfe"
"github.com/leg100/otf/internal"
"github.com/leg100/otf/internal/cloud"
"github.com/leg100/otf/internal/github"
"github.com/leg100/otf/internal/run"
"github.com/leg100/otf/internal/testutils"
"github.com/leg100/otf/internal/workspace"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TestIntegration_RunAPI tests those parts of the run API that are not covered
// by the `go-tfe` integration tests, i.e. behaviours that are specific to
// OTF.
func TestIntegration_RunAPI(t *testing.T) {
t.Parallel()

// setup daemon along with fake github repo
repo := cloud.NewTestRepo()
daemon := setup(t, nil,
github.WithRepo(repo),
github.WithArchive(testutils.ReadFile(t, "../testdata/github.tar.gz")),
)
org := daemon.createOrganization(t, ctx)
sub := daemon.createSubscriber(t, ctx)
_, token := daemon.createToken(t, ctx, nil)

tfeClient, err := tfe.NewClient(&tfe.Config{
Address: "https://" + daemon.Hostname(),
Token: string(token),
RetryServerErrors: true,
})
require.NoError(t, err)

// test the "magic string" behaviour specific to OTF: if
// run.PullVCSMagicString is specified for the config version ID then the
// config is pulled from the workspace's connected repo.
t.Run("create run using config from repo", func(t *testing.T) {
vcsProvider := daemon.createVCSProvider(t, ctx, org)
ws, err := daemon.CreateWorkspace(ctx, workspace.CreateOptions{
Name: internal.String("connected-workspace"),
Organization: internal.String(org.Name),
ConnectOptions: &workspace.ConnectOptions{
RepoPath: repo,
VCSProviderID: vcsProvider.ID,
},
})
require.NoError(t, err)

created, err := tfeClient.Runs.Create(ctx, tfe.RunCreateOptions{
ConfigurationVersion: &tfe.ConfigurationVersion{
ID: run.PullVCSMagicString,
},
Workspace: &tfe.Workspace{
ID: ws.ID,
},
})
require.NoError(t, err)

// wait for run to reach planned status
for event := range sub {
if r, ok := event.Payload.(*run.Run); ok {
switch r.Status {
case internal.RunErrored:
t.Fatal("run unexpectedly errored")
case internal.RunPlanned:
// run should have planned two resources (defined in the config from the
// github repo)
planned, err := daemon.GetRun(ctx, created.ID)
require.NoError(t, err)

assert.Equal(t, 2, planned.Plan.Additions)
return // success
}
}
}

})
}
32 changes: 32 additions & 0 deletions internal/integration/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import (

"github.com/leg100/otf/internal"
"github.com/leg100/otf/internal/auth"
"github.com/leg100/otf/internal/cloud"
"github.com/leg100/otf/internal/configversion"
"github.com/leg100/otf/internal/daemon"
"github.com/leg100/otf/internal/github"
"github.com/leg100/otf/internal/run"
"github.com/leg100/otf/internal/testutils"
"github.com/leg100/otf/internal/workspace"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -27,6 +31,34 @@ func TestRun(t *testing.T) {
require.NoError(t, err)
})

// test the "magic string" behaviour specific to OTF: if
// run.PullVCSMagicString is specified for the config version ID then the
// config is pulled from the workspace's connected repo.
t.Run("create run using config from repo", func(t *testing.T) {
// setup daemon along with fake github repo
repo := cloud.NewTestRepo()
daemon := setup(t, nil,
github.WithRepo(repo),
github.WithArchive(testutils.ReadFile(t, "../testdata/github.tar.gz")),
)
org := daemon.createOrganization(t, ctx)
vcsProvider := daemon.createVCSProvider(t, ctx, org)
ws, err := daemon.CreateWorkspace(ctx, workspace.CreateOptions{
Name: internal.String("connected-workspace"),
Organization: internal.String(org.Name),
ConnectOptions: &workspace.ConnectOptions{
RepoPath: repo,
VCSProviderID: vcsProvider.ID,
},
})
require.NoError(t, err)

_, err = daemon.CreateRun(ctx, ws.ID, run.RunCreateOptions{
ConfigurationVersionID: internal.String(run.PullVCSMagicString),
})
require.NoError(t, err)
})

t.Run("enqueue plan", func(t *testing.T) {
svc := setup(t, &config{Config: daemon.Config{DisableScheduler: true}})
run := svc.createRun(t, ctx, nil, nil)
Expand Down
51 changes: 48 additions & 3 deletions internal/run/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,40 @@ package run

import (
"context"
"fmt"

"github.com/leg100/otf/internal/cloud"
"github.com/leg100/otf/internal/configversion"
"github.com/leg100/otf/internal/workspace"
)

// factory constructs runs
type factory struct {
ConfigurationVersionService
WorkspaceService
VCSProviderService
}

// NewRun constructs a new run at the beginning of its lifecycle using the
// provided options.
// NewRun constructs a new run using the provided options.
func (f *factory) NewRun(ctx context.Context, workspaceID string, opts RunCreateOptions) (*Run, error) {
ws, err := f.GetWorkspace(ctx, workspaceID)
if err != nil {
return nil, err
}

// There are three possibilities for the ConfigurationVersionID value:
// (a) equals PullVCSMagicString in which case a config version is first
// created from the contents of the vcs repo connected to the workspace
// (b) non-nil, in which case it is deemed to be a configuration version id
// and an existing config version with that ID is retrieved.
// (c) nil, in which the latest config version is retrieved.
var cv *configversion.ConfigurationVersion
if opts.ConfigurationVersionID != nil {
cv, err = f.GetConfigurationVersion(ctx, *opts.ConfigurationVersionID)
if *opts.ConfigurationVersionID == PullVCSMagicString {
cv, err = f.createConfigVersionFromVCS(ctx, ws)
} else {
cv, err = f.GetConfigurationVersion(ctx, *opts.ConfigurationVersionID)
}
} else {
cv, err = f.GetLatestConfigurationVersion(ctx, workspaceID)
}
Expand All @@ -32,3 +45,35 @@ func (f *factory) NewRun(ctx context.Context, workspaceID string, opts RunCreate

return newRun(cv, ws, opts), nil
}

// createConfigVersionFromVCS creates a config version from the vcs repo
// connected to the workspace using the contents of the vcs repo.
func (f *factory) createConfigVersionFromVCS(ctx context.Context, ws *workspace.Workspace) (*configversion.ConfigurationVersion, error) {
if ws.Connection == nil {
return nil, workspace.ErrNoVCSConnection
}
client, err := f.GetVCSClient(ctx, ws.Connection.VCSProviderID)
if err != nil {
return nil, err
}
// use workspace branch if set
var ref *string
if ws.Branch != "" {
ref = &ws.Branch
}
tarball, err := client.GetRepoTarball(ctx, cloud.GetRepoTarballOptions{
Repo: ws.Connection.Repo,
Ref: ref,
})
if err != nil {
return nil, fmt.Errorf("retrieving repository tarball: %w", err)
}
cv, err := f.CreateConfigurationVersion(ctx, ws.ID, configversion.ConfigurationVersionCreateOptions{})
if err != nil {
return nil, err
}
if err := f.UploadConfig(ctx, cv.ID, tarball); err != nil {
return nil, err
}
return cv, err
}
Loading

0 comments on commit 885f786

Please sign in to comment.