|
5 | 5 | "log/slog"
|
6 | 6 | "os"
|
7 | 7 | "path/filepath"
|
| 8 | + "time" |
8 | 9 |
|
9 | 10 | "github.com/input-output-hk/catalyst-forge/cli/pkg/earthly"
|
10 | 11 | "github.com/input-output-hk/catalyst-forge/cli/pkg/events"
|
@@ -82,7 +83,22 @@ func (r *DocsReleaser) Release() error {
|
82 | 83 | }
|
83 | 84 |
|
84 | 85 | r.logger.Info("Checking out branch", "branch", r.config.Branch)
|
85 |
| - if err := git.CheckoutBranch(r.project.Repo, r.config.Branch, git.GitCheckoutRemote()); err != nil { |
| 86 | + if err := git.CheckoutBranch( |
| 87 | + r.project.Repo, |
| 88 | + r.config.Branch, |
| 89 | + git.GitCheckoutRemote(), |
| 90 | + ); err != nil { |
| 91 | + return fmt.Errorf("failed to checkout branch: %w", err) |
| 92 | + } |
| 93 | + |
| 94 | + tempBranch := generateTempBranch() |
| 95 | + r.logger.Info("Creating orphan branch", "branch", tempBranch) |
| 96 | + if err := git.CheckoutBranch( |
| 97 | + r.project.Repo, |
| 98 | + tempBranch, |
| 99 | + git.GitCheckoutOrphan(), |
| 100 | + git.GitCheckoutCreate(), |
| 101 | + ); err != nil { |
86 | 102 | return fmt.Errorf("failed to checkout branch: %w", err)
|
87 | 103 | }
|
88 | 104 |
|
@@ -191,6 +207,12 @@ func (r *DocsReleaser) clean(targetPath string) error {
|
191 | 207 | return nil
|
192 | 208 | }
|
193 | 209 |
|
| 210 | +// generateBranchName generates a temporary branch name. |
| 211 | +func generateTempBranch() string { |
| 212 | + timestamp := time.Now().Format("20060102-150405") |
| 213 | + return fmt.Sprintf("%s-%s", "forge-gh-pages", timestamp) |
| 214 | +} |
| 215 | + |
194 | 216 | // run runs the release target.
|
195 | 217 | func (r *DocsReleaser) run(path string) error {
|
196 | 218 | return r.runner.RunTarget(
|
|
0 commit comments