@@ -3,6 +3,7 @@ package deploy_test
33import (
44 "context"
55 "fmt"
6+ "net/url"
67 "os"
78 "os/exec"
89 "path/filepath"
@@ -127,8 +128,7 @@ func TestManagedDeployWithPrimaryBranch(t *testing.T) {
127128
128129// This test require gh cli to be installed on the system.
129130// Alternatively a personal access token can be set via RILL_TEST_GH_TOKEN environment variable.
130- // TODO: Set personal acccess token for CI/CD tests.
131- func NoCICDTestGithubDeploy (t * testing.T ) {
131+ func TestGithubDeploy (t * testing.T ) {
132132 testmode .Expensive (t )
133133 personalAccessToken := getGithubAuthToken (t )
134134 // github client
@@ -150,15 +150,15 @@ func NoCICDTestGithubDeploy(t *testing.T) {
150150 u1 := testcli .New (t , adm , c .Token )
151151
152152 t .Run ("self-hosted git deploy" , func (t * testing.T ) {
153- testSelfHostedDeploy (t , c , ghClient , u1 )
153+ testSelfHostedDeploy (t , c , ghClient , u1 , personalAccessToken )
154154 })
155155
156156 t .Run ("self-hosted git deploy with monorepo" , func (t * testing.T ) {
157- testSelfHostedMonorepoDeploy (t , c , ghClient , u1 )
157+ testSelfHostedMonorepoDeploy (t , c , ghClient , u1 , personalAccessToken )
158158 })
159159}
160160
161- func testSelfHostedDeploy (t * testing.T , adminClient * client.Client , ghClient * github.Client , adm * testcli.Fixture ) {
161+ func testSelfHostedDeploy (t * testing.T , adminClient * client.Client , ghClient * github.Client , adm * testcli.Fixture , token string ) {
162162 testmode .Expensive (t )
163163 result := adm .Run (t , "org" , "create" , "github-test" )
164164 require .Equal (t , 0 , result .ExitCode )
@@ -184,9 +184,11 @@ func testSelfHostedDeploy(t *testing.T, adminClient *client.Client, ghClient *gi
184184 author := & object.Signature {
185185 Name : "Rill test user" ,
186186 Email : "test.user@rilldata.com" ,
187+ When : time .Now (),
187188 }
189+ authCloneURL := authGitURL (t , * repo .CloneURL , token )
188190 err = gitutil .CommitAndPush (t .Context (), tempDir , & gitutil.Config {
189- Remote : * repo . CloneURL ,
191+ Remote : authCloneURL ,
190192 DefaultBranch : "main" ,
191193 }, "" , author )
192194 require .NoError (t , err , "failed to push to github repo" )
@@ -204,10 +206,12 @@ func testSelfHostedDeploy(t *testing.T, adminClient *client.Client, ghClient *gi
204206 require .Equal (t , "self-hosted-deploy" , resp .Project .Name )
205207 require .Empty (t , resp .Project .ManagedGitId )
206208
207- // check remote configured in directory
209+ // check remote configured in directory (normalize to strip any embedded credentials)
208210 remote , err := gitutil .ExtractGitRemote (tempDir , "origin" , false )
209211 require .NoError (t , err )
210- require .Equal (t , * repo .CloneURL , remote .URL )
212+ normalizedRemoteURL , err := gitutil .NormalizeGithubRemote (remote .URL )
213+ require .NoError (t , err )
214+ require .Equal (t , * repo .CloneURL , normalizedRemoteURL )
211215
212216 result = adm .Run (t , "deploy" , "--interactive=false" , "--org=github-test" , "--project=self-hosted-deploy" , "--skip-deploy=true" , "--path=" + tempDir )
213217 require .Equal (t , 0 , result .ExitCode , result .Output )
@@ -224,7 +228,7 @@ func testSelfHostedDeploy(t *testing.T, adminClient *client.Client, ghClient *gi
224228 verifyGithubRepoContents (t , ghClient , resp .Project .GitRemote , changes )
225229}
226230
227- func testSelfHostedMonorepoDeploy (t * testing.T , adminClient * client.Client , ghClient * github.Client , adm * testcli.Fixture ) {
231+ func testSelfHostedMonorepoDeploy (t * testing.T , adminClient * client.Client , ghClient * github.Client , adm * testcli.Fixture , token string ) {
228232 testmode .Expensive (t )
229233 result := adm .Run (t , "org" , "create" , "github-monorepo-test" )
230234 require .Equal (t , 0 , result .ExitCode )
@@ -250,24 +254,34 @@ func testSelfHostedMonorepoDeploy(t *testing.T, adminClient *client.Client, ghCl
250254 author := & object.Signature {
251255 Name : "Rill test user" ,
252256 Email : "test.user@rilldata.com" ,
257+ When : time .Now (),
253258 }
254259 err = gitutil .CommitAndPush (t .Context (), tempDir , & gitutil.Config {
255- Remote : * repo .CloneURL ,
260+ Remote : authGitURL ( t , * repo .CloneURL , token ) ,
256261 DefaultBranch : "main" ,
257262 }, "" , author )
258263 require .NoError (t , err , "failed to push to github repo" )
259264
260265 // Clone two separate copies of the same repo to simulate independent working directories
261266 // This demonstrates that different subpaths can be worked on independently
267+ cloneRepo := func (ctx context.Context , repoURL , path , token string ) error {
268+ cmd := exec .CommandContext (ctx , "git" , "clone" , authGitURL (t , repoURL , token ), path )
269+ out , err := cmd .CombinedOutput ()
270+ if err != nil {
271+ return fmt .Errorf ("git clone failed: %s(%s)" , out , err )
272+ }
273+ return nil
274+ }
275+
262276 clone1Dir := t .TempDir ()
263277 clone2Dir := t .TempDir ()
264278
265279 // Clone repo to first directory
266- err = cloneRepo (t .Context (), * repo .CloneURL , clone1Dir )
280+ err = cloneRepo (t .Context (), * repo .CloneURL , clone1Dir , token )
267281 require .NoError (t , err , "failed to clone repo to first directory" )
268282
269283 // Clone repo to second directory
270- err = cloneRepo (t .Context (), * repo .CloneURL , clone2Dir )
284+ err = cloneRepo (t .Context (), * repo .CloneURL , clone2Dir , token )
271285 require .NoError (t , err , "failed to clone repo to second directory" )
272286
273287 // deploy project1 from first clone
@@ -475,11 +489,9 @@ func initGitWithTwoBranches(t *testing.T, dir string) {
475489 runGitCmd ("commit" , "-m" , "staging changes" )
476490}
477491
478- func cloneRepo (ctx context.Context , repoURL , path string ) error {
479- cmd := exec .CommandContext (ctx , "git" , "clone" , repoURL , path )
480- out , err := cmd .CombinedOutput ()
481- if err != nil {
482- return fmt .Errorf ("clone repo failed with error: %s(%s)" , out , err )
483- }
484- return nil
492+ func authGitURL (t * testing.T , repoURL , token string ) string {
493+ u , err := url .Parse (repoURL )
494+ require .NoError (t , err )
495+ u .User = url .UserPassword ("x-access-token" , token )
496+ return u .String ()
485497}
0 commit comments