Skip to content

Commit

Permalink
Auto-Generate Docs for CLI (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuajerin authored Apr 25, 2024
1 parent 47ec629 commit 724019d
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 1 deletion.
64 changes: 64 additions & 0 deletions .github/actions/generate-docs/action.yml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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
33 changes: 33 additions & 0 deletions .github/workflows/tembo_cli.yml
Original file line number Diff line number Diff line change
@@ -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'
9 changes: 9 additions & 0 deletions tembo-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tembo-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
9 changes: 8 additions & 1 deletion tembo-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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::<App>();
return Ok(());
}
let app = App::parse();

match app.command {
Expand Down

0 comments on commit 724019d

Please sign in to comment.