Skip to content

Commit

Permalink
feat: generate default configs for docs without compiled binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jan 6, 2025
1 parent 14ca842 commit 7ce784c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,6 @@ docsgen-cli:
$(GOCC) run ./scripts/docsgen-cli
.PHONY: docsgen-cli

# Compiled lotus and lotus-miner are required to generate the default config files
docsgen-config: lotus lotus-miner
./lotus config default > documentation/en/default-lotus-config.toml
./lotus-miner config default > documentation/en/default-lotus-miner-config.toml
.PHONY: docsgen-config

print-%:
@echo $*=$($*)

1 change: 0 additions & 1 deletion documentation/en/default-lotus-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,3 @@
# env var: LOTUS_FAULTREPORTER_CONSENSUSFAULTREPORTERADDRESS
#ConsensusFaultReporterAddress = ""


1 change: 0 additions & 1 deletion documentation/en/default-lotus-miner-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -650,4 +650,3 @@
# env var: LOTUS_HARMONYDB_PORT
#Port = "5433"


2 changes: 1 addition & 1 deletion documentation/misc/Building_a_network_skeleton.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Note: one only needs to update `filecion-ffi`'s dependency on `go-state-types` w
11. Run `make gen`.
12. Run `make docsgen-cli docsgen-config`.
12. Run `make docsgen-cli`.
And you're done! These are all the steps necessary to create a network upgrade skeleton that you will be able to run in a local devnet, and creates a basis where you can start testing new FIPs. When running a local developer network from this Lotus branch, bringing in all it dependencies, you should be able to:
Expand Down
4 changes: 2 additions & 2 deletions documentation/misc/RELEASE_ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<!--{{ if contains "Miner" .Type}}-->
- Ensure to update `MinerBuildVersion`
<!--{{ end}}-->
- [ ] Run `make gen && make docsgen-cli docsgen-config` before committing changes.
- [ ] Run `make gen && make docsgen-cli` before committing changes.
- [ ] Update the CHANGELOG
- [ ] Change the `UNRELEASED` section header to `UNRELEASED v{{.Tag}}`
- [ ] Set the `UNRELEASED v{{.Tag}}` section's content to be "_See https://github.com/filecoin-project/lotus/blob/release/v{{.Tag}}/CHANGELOG.md_"
Expand Down Expand Up @@ -118,7 +118,7 @@
<!-- {{if contains "Miner" $.Type}}-->
- Ensure to update `MinerBuildVersion`
<!-- {{end}}-->
- [ ] Run `make gen && make docsgen-cli docsgen-config` to generate documentation
- [ ] Run `make gen && make docsgen-cli` to generate documentation
- [ ] Create a draft PR with title `build: release Lotus {{$.Type}} v{{$.Tag}}{{$tagSuffix}}`
- Link to PR:
- Opening a PR will trigger a CI run that will build assets, create a draft GitHub release, and attach the assets.
Expand Down
53 changes: 51 additions & 2 deletions scripts/docsgen-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package main
import (
"fmt"
"os"
"path/filepath"

"github.com/urfave/cli/v2"

"github.com/filecoin-project/lotus/cli/lotus"
"github.com/filecoin-project/lotus/cli/miner"
"github.com/filecoin-project/lotus/cli/worker"
"github.com/filecoin-project/lotus/node/config"
)

const (
Expand Down Expand Up @@ -45,6 +47,23 @@ func main() {
os.Exit(1)
}

cliApps := loadCLIApps()

fmt.Println("Generating CLI documentation...")
failed := generateCLIDocumentation(cliApps)

fmt.Println("Generating default config files...")
failed = generateDefaultConfigs() || failed

if failed {
fmt.Println("Documentation generation failed.")
os.Exit(1)
} else {
fmt.Println("Documentation generation complete.")
}
}

func loadCLIApps() map[string]*cli.App {
// Some help output is generated based on whether the output is a terminal or not. To make stable
// output text, we set Stdout to not be a terminal while we load the CLI apps and reset it
// before generating the documentation.
Expand All @@ -61,8 +80,11 @@ func main() {
w.Close()
os.Stdout = stdout

fmt.Println("Generating CLI documentation...")
return cliApps
}

func generateCLIDocumentation(cliApps map[string]*cli.App) bool {
var failed bool
for name, app := range cliApps {
for _, cmd := range app.Commands {
cmd.HelpName = fmt.Sprintf("%s %s", app.HelpName, cmd.Name)
Expand All @@ -71,10 +93,37 @@ func main() {
generator := NewDocGenerator(outputDir, app)
if err := generator.Generate(name); err != nil {
fmt.Printf(" ❌ %s: %v\n", name, err)
failed = true
continue
}
fmt.Printf(" ✅ %s\n", name)
}
return failed
}

func generateDefaultConfigs() bool {
var failed bool
if err := generateDefaultConfig(config.DefaultFullNode(), "default-lotus-config.toml"); err != nil {
fmt.Printf(" ❌ %s: %v\n", "lotus", err)
failed = true
} else {
fmt.Printf(" ✅ %s\n", "lotus")
}

fmt.Println("Documentation generation complete.")
if err := generateDefaultConfig(config.DefaultStorageMiner(), "default-lotus-miner-config.toml"); err != nil {
fmt.Printf(" ❌ %s: %v\n", "lotus-miner", err)
failed = true
} else {
fmt.Printf(" ✅ %s\n", "lotus-miner")
}
return failed
}

func generateDefaultConfig(c interface{}, file string) error {
cb, err := config.ConfigUpdate(c, nil, config.Commented(true), config.DefaultKeepUncommented())
if err != nil {
return err
}
output := filepath.Join(outputDir, file)
return os.WriteFile(output, cb, 0644)
}

0 comments on commit 7ce784c

Please sign in to comment.