From 724019d88197cd9c37ec1282b188e75e85c22249 Mon Sep 17 00:00:00 2001 From: Joshua Jerin Date: Thu, 25 Apr 2024 11:30:22 -0400 Subject: [PATCH] Auto-Generate Docs for CLI (#725) --- .github/actions/generate-docs/action.yml | 64 ++++++++++++++++++++++++ .github/workflows/tembo_cli.yml | 33 ++++++++++++ tembo-cli/Cargo.lock | 9 ++++ tembo-cli/Cargo.toml | 1 + tembo-cli/src/main.rs | 9 +++- 5 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 .github/actions/generate-docs/action.yml create mode 100644 .github/workflows/tembo_cli.yml diff --git a/.github/actions/generate-docs/action.yml b/.github/actions/generate-docs/action.yml new file mode 100644 index 000000000..30b4e5da6 --- /dev/null +++ b/.github/actions/generate-docs/action.yml @@ -0,0 +1,64 @@ +name: 'Generate and Deploy Documentation' +description: 'Generate and deploy documentation files.' +inputs: + tembo_repository: + description: 'GitHub repository to work with for documentation generation.' + required: true + website_repository: + description: 'Website repository to update with documentation.' + required: true + ssh_key: + description: 'SSH key for repository access.' + required: true + tembo_branch: + description: 'Branch to checkout for documentation generation.' + required: true + website_branch: + description: 'Branch to update with generated documentation.' + required: true + +runs: + using: "composite" + steps: + - name: Check out the tembo repo + uses: actions/checkout@v4 + with: + repository: ${{ inputs.tembo_repository }} + ssh-key: ${{ inputs.ssh_key }} + ref: ${{ inputs.tembo_branch }} + path: 'tembo-repo' + + - name: Generate Documentation + run: | + cd tembo-repo/tembo-cli + cargo run -- --markdown-help > ../command-reference.md + shell: bash + + - name: Check out the website repo + uses: actions/checkout@v4 + with: + repository: ${{ inputs.website_repository }} + ssh-key: ${{ inputs.ssh_key }} + ref: main + path: 'website-repo' + + - name: Copy documentation to website repository + run: | + mkdir -p website-repo/src/content/docs/development/cli/ + ls -lah + shell: bash + + - name: Commit and push documentation to website repository + run: | + cd website-repo + git config user.name "coredb-service-user" + git config user.email "admin@github.com" + git fetch origin ${{ inputs.website_branch }} + git checkout ${{ inputs.website_branch }} + cd .. + cp tembo-repo/command-reference.md website-repo/src/content/docs/development/cli/ + cd website-repo + git add src/content/docs/development/cli/command-reference.md + git status + git commit -m "Update command reference documentation: ${SHORT_SHA}" && git push origin ${{ inputs.website_branch }} || echo "No change in docs!" + shell: bash diff --git a/.github/workflows/tembo_cli.yml b/.github/workflows/tembo_cli.yml new file mode 100644 index 000000000..a4a2d24cf --- /dev/null +++ b/.github/workflows/tembo_cli.yml @@ -0,0 +1,33 @@ +name: Generate and Deploy Documentation + +on: + push: + paths: + - 'tembo-cli/**' + branches: + - main + +jobs: + generate_docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install system dependencies + run: | + set -xe + sudo apt-get update + + - name: Set version strings + id: versions + run: | + echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV + + - name: Generate and Deploy Docs + uses: ./.github/actions/generate-docs + with: + tembo_repository: 'tembo-io/tembo' + ssh_key: ${{ secrets.SERVICE_USER_GITHUB_SSH_KEY }} + tembo_branch: 'main' + website_branch: 'cli-updates' + website_repository: 'tembo-io/website' diff --git a/tembo-cli/Cargo.lock b/tembo-cli/Cargo.lock index c894a247d..7c56c8b77 100644 --- a/tembo-cli/Cargo.lock +++ b/tembo-cli/Cargo.lock @@ -577,6 +577,14 @@ dependencies = [ "clap_derive", ] +[[package]] +name = "clap-markdown" +version = "0.1.3" +source = "git+https://github.com/tembo-io/clap-markdown.git?branch=main#50b7a6c4ff8930643b80efa4dc8983ea0fe62ca5" +dependencies = [ + "clap", +] + [[package]] name = "clap_builder" version = "4.4.5" @@ -4029,6 +4037,7 @@ dependencies = [ "base64 0.21.5", "chrono", "clap", + "clap-markdown", "clap_complete", "clerk-rs", "cli-table", diff --git a/tembo-cli/Cargo.toml b/tembo-cli/Cargo.toml index bb338c941..69a53cf7f 100644 --- a/tembo-cli/Cargo.toml +++ b/tembo-cli/Cargo.toml @@ -76,6 +76,7 @@ tembo-stacks = "0.4.1" itertools = "0.12.1" random-string = "1.1.0" test-case = "=2.0.0-rc2" +clap-markdown = { git = "https://github.com/tembo-io/clap-markdown.git", branch = "main" } [target.aarch64-unknown-linux-musl.dependencies] openssl = { version = "0.10", features = ["vendored"] } diff --git a/tembo-cli/src/main.rs b/tembo-cli/src/main.rs index a04ad8a6b..103eed90e 100644 --- a/tembo-cli/src/main.rs +++ b/tembo-cli/src/main.rs @@ -14,8 +14,11 @@ mod cmd; mod tui; #[derive(Parser)] -#[clap(author = crate_authors!("\n"), version = crate_version!(), about = "Tembo CLI", long_about = None)] +#[clap(name = "tembo", author = crate_authors!("\n"), version = crate_version!(), long_about = None)] struct App { + #[arg(long, hide = true)] + markdown_help: bool, + #[clap(flatten)] global_opts: GlobalOpts, @@ -44,6 +47,10 @@ struct GlobalOpts { } fn main() -> Result<(), anyhow::Error> { + if std::env::args().any(|arg| arg == "--markdown-help") { + clap_markdown::print_help_markdown::(); + return Ok(()); + } let app = App::parse(); match app.command {