(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func TestManagedDeploy(t *testing.T) { |
| 28 | testmode.Expensive(t) |
| 29 | adm := testadmin.New(t) |
| 30 | |
| 31 | _, c := adm.NewUser(t) |
| 32 | u1 := testcli.New(t, adm, c.Token) |
| 33 | |
| 34 | result := u1.Run(t, "org", "create", "github-test") |
| 35 | require.Equal(t, 0, result.ExitCode) |
| 36 | |
| 37 | // deploy the project |
| 38 | tempDir := initRillProject(t) |
| 39 | |
| 40 | result = u1.Run(t, "project", "deploy", "--interactive=false", "--org=github-test", "--project=rill-mgd-deploy", "--skip-deploy=true", "--path="+tempDir) |
| 41 | require.Equal(t, 0, result.ExitCode, result.Output) |
| 42 | |
| 43 | // verify the project is correctly created |
| 44 | resp, err := c.GetProject(t.Context(), &adminv1.GetProjectRequest{ |
| 45 | Org: "github-test", |
| 46 | Project: "rill-mgd-deploy", |
| 47 | }) |
| 48 | require.NoError(t, err) |
| 49 | require.Equal(t, "rill-mgd-deploy", resp.Project.Name) |
| 50 | |
| 51 | // get a github client |
| 52 | installationID, err := adm.Admin.Github.ManagedOrgInstallationID() |
| 53 | require.NoError(t, err) |
| 54 | ghClient := adm.Admin.Github.InstallationClient(installationID, nil) |
| 55 | |
| 56 | // redeploy the same project with changes |
| 57 | changes := map[string]string{ |
| 58 | "models/model.sql": `SELECT 1 AS one`, |
| 59 | } |
| 60 | putFiles(t, tempDir, changes) |
| 61 | result = u1.Run(t, "deploy", "--interactive=false", "--org=github-test", "--project=rill-mgd-deploy", "--skip-deploy=true", "--path="+tempDir) |
| 62 | require.Equal(t, 0, result.ExitCode, result.Output) |
| 63 | |
| 64 | // verify changes are pushed to Github repo |
| 65 | verifyGithubRepoContents(t, ghClient, resp.Project.GitRemote, changes) |
| 66 | |
| 67 | // clone the project to an empty directory and remove the __rill_remote to simulate fresh deploys in CI/CD |
| 68 | |
| 69 | // Get an installation token so we can clone the managed (private) repo without credentials. |
| 70 | managedOwner, _, ok := gitutil.SplitGithubRemote(resp.Project.GitRemote) |
| 71 | require.True(t, ok, "invalid github remote: %s", resp.Project.GitRemote) |
| 72 | cloneToken, _, err := adm.Admin.Github.InstallationTokenForOrg(t.Context(), managedOwner) |
| 73 | require.NoError(t, err) |
| 74 | |
| 75 | cloneDir := t.TempDir() |
| 76 | cmd := exec.CommandContext(t.Context(), "git", "clone", authGitURL(t, resp.Project.GitRemote, cloneToken), cloneDir) |
| 77 | out, err := cmd.CombinedOutput() |
| 78 | require.NoError(t, err, "git clone failed: %s", out) |
| 79 | |
| 80 | // remove __rill_remote to simulate fresh deploys in CI/CD where the git history is not preserved |
| 81 | err = os.Remove(filepath.Join(cloneDir, ".git", "refs", "heads", "main")) |
| 82 | require.NoError(t, err) |
| 83 | |
| 84 | // deploy again from the cloned directory with changes |
nothing calls this directly
no test coverage detected