generated from templates/go-generic
WIP: New Flow website built with Nanoc and Mage #1
4 changed files with 40 additions and 30 deletions
|
@ -9,8 +9,7 @@
|
||||||
<div id="sidebar">
|
<div id="sidebar">
|
||||||
<h2>Projects</h2>
|
<h2>Projects</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/projects/spruce/">Spruce</a></li>
|
<%= project_list %>
|
||||||
<li><a href="/projects/pelican/">Pelican</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
9
flow/lib/project_list.rb
Normal file
9
flow/lib/project_list.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
def project_list
|
||||||
|
out = +''
|
||||||
|
|
||||||
|
@config[:projects].each do |project|
|
||||||
|
out << "<li><a href=\"/projects/#{project[:name]}/\">#{project[:name]}</a></li>\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
out
|
||||||
|
end
|
|
@ -28,11 +28,11 @@ environments:
|
||||||
base_url: https://dananglin.me.uk
|
base_url: https://dananglin.me.uk
|
||||||
|
|
||||||
projects:
|
projects:
|
||||||
pelican:
|
- name: pelican
|
||||||
repository_url: https://codeflow.dananglin.me.uk/apollo/pelican.git
|
repository_url: https://codeflow.dananglin.me.uk/apollo/pelican.git
|
||||||
branch: flow-website-support
|
branch: flow-website-support
|
||||||
documentation_root: docs
|
documentation_root: docs
|
||||||
spruce:
|
- name: spruce
|
||||||
repository_url: https://codeflow.dananglin.me.uk/apollo/spruce.git
|
repository_url: https://codeflow.dananglin.me.uk/apollo/spruce.git
|
||||||
branch: flow-website-support
|
branch: flow-website-support
|
||||||
documentation_root: docs
|
documentation_root: docs
|
||||||
|
|
|
@ -16,10 +16,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type projectsConfig struct {
|
type projectsConfig struct {
|
||||||
Projects map[string]project `yaml:"projects"`
|
Projects []project `yaml:"projects"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type project struct {
|
type project struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
RepositoryURL string `yaml:"repository_url"`
|
RepositoryURL string `yaml:"repository_url"`
|
||||||
Commit string `yaml:"commit"`
|
Commit string `yaml:"commit"`
|
||||||
Tag string `yaml:"tag"`
|
Tag string `yaml:"tag"`
|
||||||
|
@ -42,16 +43,16 @@ func Projects() error {
|
||||||
return fmt.Errorf("unable to parse the projects configuration; %w", err)
|
return fmt.Errorf("unable to parse the projects configuration; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, details := range projects.Projects {
|
for _, project := range projects.Projects {
|
||||||
clonedDirectory, err := cloneProject(name, details)
|
clonedDirectory, err := cloneProject(project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to clone %q; %w", name, err)
|
return fmt.Errorf("unable to clone %q; %w", project.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
documentationDir := filepath.Join(clonedDirectory, details.DocumentationRoot)
|
documentationDir := filepath.Join(clonedDirectory, project.DocumentationRoot)
|
||||||
|
|
||||||
if err := copyDocumentation(documentationDir, name); err != nil {
|
if err := copyDocumentation(documentationDir, project.Name); err != nil {
|
||||||
return fmt.Errorf("unable to copy the documentation from %q; %w", name, err)
|
return fmt.Errorf("unable to copy the documentation from %q; %w", project.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,20 +78,20 @@ func parseProjectsConfig() (projectsConfig, error) {
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneProject(projectName string, projectDetails project) (string, error) {
|
func cloneProject(p project) (string, error) {
|
||||||
slog.Info("Cloning the project repository.", "repository", projectDetails.RepositoryURL)
|
slog.Info("Cloning the project repository.", "repository", p.RepositoryURL)
|
||||||
var (
|
var (
|
||||||
reference plumbing.ReferenceName
|
reference plumbing.ReferenceName
|
||||||
singleBranch bool
|
singleBranch bool
|
||||||
depth int
|
depth int
|
||||||
)
|
)
|
||||||
|
|
||||||
if projectDetails.Tag != "" {
|
if p.Tag != "" {
|
||||||
reference = plumbing.NewTagReferenceName(projectDetails.Tag)
|
reference = plumbing.NewTagReferenceName(p.Tag)
|
||||||
singleBranch = false
|
singleBranch = false
|
||||||
depth = 1
|
depth = 1
|
||||||
} else if projectDetails.Branch != "" {
|
} else if p.Branch != "" {
|
||||||
reference = plumbing.NewBranchReferenceName(projectDetails.Branch)
|
reference = plumbing.NewBranchReferenceName(p.Branch)
|
||||||
singleBranch = true
|
singleBranch = true
|
||||||
depth = 1
|
depth = 1
|
||||||
} else {
|
} else {
|
||||||
|
@ -99,13 +100,13 @@ func cloneProject(projectName string, projectDetails project) (string, error) {
|
||||||
depth = 0
|
depth = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
cloneDir, err := os.MkdirTemp("", projectName)
|
cloneDir, err := os.MkdirTemp("", p.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("unable to create the temporary clone directory; %w", err)
|
return "", fmt.Errorf("unable to create the temporary clone directory; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
options := git.CloneOptions{
|
options := git.CloneOptions{
|
||||||
URL: projectDetails.RepositoryURL,
|
URL: p.RepositoryURL,
|
||||||
Progress: nil,
|
Progress: nil,
|
||||||
ReferenceName: reference,
|
ReferenceName: reference,
|
||||||
SingleBranch: singleBranch,
|
SingleBranch: singleBranch,
|
||||||
|
@ -117,7 +118,7 @@ func cloneProject(projectName string, projectDetails project) (string, error) {
|
||||||
return "", fmt.Errorf("unable to clone the repository; %w", err)
|
return "", fmt.Errorf("unable to clone the repository; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if projectDetails.Commit == "" {
|
if p.Commit == "" {
|
||||||
return cloneDir, nil
|
return cloneDir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,12 +128,12 @@ func cloneProject(projectName string, projectDetails project) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkoutOptions := git.CheckoutOptions{
|
checkoutOptions := git.CheckoutOptions{
|
||||||
Hash: plumbing.NewHash(projectDetails.Commit),
|
Hash: plumbing.NewHash(p.Commit),
|
||||||
Create: false,
|
Create: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := worktree.Checkout(&checkoutOptions); err != nil {
|
if err := worktree.Checkout(&checkoutOptions); err != nil {
|
||||||
return "", fmt.Errorf("unable to checkout %q; %w", projectDetails.Commit, err)
|
return "", fmt.Errorf("unable to checkout %q; %w", p.Commit, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Info("Project cloned successfully.")
|
slog.Info("Project cloned successfully.")
|
||||||
|
@ -141,7 +142,9 @@ func cloneProject(projectName string, projectDetails project) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyDocumentation(inputDirectory, projectName string) error {
|
func copyDocumentation(inputDirectory, projectName string) error {
|
||||||
slog.Info("Copying documentation.", "project", projectName, "directory", inputDirectory)
|
outputDirectory := filepath.Join(projectsDirectory, projectName)
|
||||||
|
|
||||||
|
slog.Info("Copying documentation.", "project", projectName, "source", inputDirectory, "destination", outputDirectory)
|
||||||
|
|
||||||
defer os.RemoveAll(inputDirectory)
|
defer os.RemoveAll(inputDirectory)
|
||||||
|
|
||||||
|
@ -154,7 +157,6 @@ func copyDocumentation(inputDirectory, projectName string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
outputDirectory := filepath.Join(projectsDirectory, projectName)
|
|
||||||
|
|
||||||
if err := os.MkdirAll(outputDirectory, 0o750); err != nil {
|
if err := os.MkdirAll(outputDirectory, 0o750); err != nil {
|
||||||
return fmt.Errorf("unable to create %q; %w", outputDirectory, err)
|
return fmt.Errorf("unable to create %q; %w", outputDirectory, err)
|
||||||
|
|
Loading…
Reference in a new issue