Skip to content

Commit

Permalink
Merge pull request #55 from pleonex/feature/fix-pushDocs
Browse files Browse the repository at this point in the history
Fix Push-Doc was not pushing the documentation
  • Loading branch information
pleonex authored Dec 4, 2021
2 parents 931cb0e + 6e50b8a commit ac253a4
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/PleOps.Cake/documentation.cake
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,29 @@ Task("Push-Doc")
}

// TODO: [#6] Implement multi-version documentation
string pushWorktreeName = "push-gh-pages";
string worktreeName = "push-gh-pages";
string committerName = "PleOps.Cake Bot";
string committerEmail = "ci@pleops.cake";

using (Repository repo = new Repository(GitFindRootFromPath(".").FullPath)) {
bool ownTree = false;
Worktree tree = null;
if (repo.Worktrees.Any(w => w.Name == pushWorktreeName)) {
if (repo.Worktrees.Any(w => w.Name == worktreeName)) {
Information("Re-use worktree");
tree = repo.Worktrees[pushWorktreeName];
tree = repo.Worktrees[worktreeName];
} else {
Information("Create worktree");

// libgit2sharp does not clean the refs and it complains if you run it again later
string refPath = $"{repo.Info.Path}/refs/heads/{pushWorktreeName}";
string refPath = $"{repo.Info.Path}/refs/heads/{worktreeName}";
if (FileExists(refPath)) {
Information("Deleting old ref");
DeleteFile(refPath);
}

CreateDirectory($"{info.ArtifactsDirectory}/tmp");
tree = repo.Worktrees.Add(
"origin/gh-pages",
pushWorktreeName,
worktreeName,
$"{info.ArtifactsDirectory}/tmp/gh-pages",
false); // no lock since it's not a portable media
ownTree = true;
Expand All @@ -79,6 +78,29 @@ Task("Push-Doc")
string treePath = treeRepo.Info.WorkingDirectory;
Information($"Worktree at: {treePath}");

// LibGit2Sharp seems to have a bug where it creates the worktree branch
// at the current HEAD (main branch), instead at the given reference.
// So we do the checkout with a pull ourselves.
var checkoutSettings = new ProcessSettings {
Arguments = "checkout gh-pages",
WorkingDirectory = treePath,
};
int checkoutResult = StartProcess("git", checkoutSettings);
if (checkoutResult != 0) {
Error("Error creating gh-pages branch");
}

var pullSettings = new ProcessSettings {
Arguments = "pull --ff-only origin gh-pages",
WorkingDirectory = treePath,
};
int pullResult = StartProcess("git", pullSettings);
if (pullResult != 0) {
Error("Error pulling");
}

Information($"Current branch: {treeRepo.Head.FriendlyName}");

// Clean directory so we don't keep old files
// Just move temporary the .git file so it's not deleted.
CopyFile($"{treePath}/.git", $"{info.ArtifactsDirectory}/tmp/.git");
Expand Down Expand Up @@ -111,10 +133,10 @@ Task("Push-Doc")
Information("No changes detected, no new commits done");
}


if (ownTree) {
Information("Prune worktree");
repo.Worktrees.Prune(tree);
repo.Branches.Remove(worktreeName);
}
}
});

0 comments on commit ac253a4

Please sign in to comment.