Skip to content

Commit

Permalink
Merge pull request #1359 from imjasonh/drop-build
Browse files Browse the repository at this point in the history
Drop `wolfictl build` and `wolfictl test`
  • Loading branch information
luhring authored Dec 10, 2024
2 parents 75eb9f2 + 3c45b9e commit 658d85e
Show file tree
Hide file tree
Showing 112 changed files with 146 additions and 3,065 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,27 @@ jobs:
./wolfictl text -d testdata/text/ | grep foo-0.0.2-r0
./wolfictl text -d testdata/text/ | grep bar-0.0.1-r0
./wolfictl text -d testdata/text/ | grep root-0.0.1-r0
docs:
permissions:
contents: read

name: check generated docs
runs-on: ubuntu-latest

steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
with:
go-version-file: 'go.mod'
check-latest: true

- run: rm -rf docs/**/*.md docs/**/*.1
- run: make docs
- run: git diff --exit-code
130 changes: 16 additions & 114 deletions cmd/docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,131 +14,33 @@
package main

import (
"fmt"
"flag"
"log"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/wolfi-dev/wolfictl/pkg/cli"
)

const descriptionSourcePath = "docs/reference/cmd/"
func main() {
var target string
var kind string
flag.StringVar(&target, "target", "/tmp", "Target path for generated yaml files")
flag.StringVar(&kind, "kind", "markdown", "Kind of docs to generate (supported: man, markdown)")
flag.Parse()

log.Printf("Generating files into %s\n", target)

func generateCliYaml(opts *options) error {
root := cli.New()
disableFlagsInUseLine(root)
source := filepath.Join(opts.source, descriptionSourcePath)
if err := loadLongDescription(root, source); err != nil {
return err
}

switch opts.kind {
switch kind {
case "markdown":
return GenMarkdownTree(root, opts.target)
if err := GenMarkdownTree(root, target); err != nil {
log.Fatalf("Error generating markdown: %v\n", err)
}
case "man":
header := &GenManHeader{
Section: "1",
if err := GenManTree(root, &GenManHeader{Section: "1"}, target); err != nil {
log.Fatalf("Error generating man: %v\n", err)
}
return GenManTree(root, header, opts.target)
default:
return fmt.Errorf("invalid docs kind : %s", opts.kind)
}
}

func disableFlagsInUseLine(cmd *cobra.Command) {
visitAll(cmd, func(ccmd *cobra.Command) {
// do not add a `[flags]` to the end of the usage line.
ccmd.DisableFlagsInUseLine = true
})
}

// visitAll will traverse all commands from the root.
// This is different from the VisitAll of cobra.Command where only parents
// are checked.
func visitAll(root *cobra.Command, fn func(*cobra.Command)) {
for _, c := range root.Commands() {
visitAll(c, fn)
}
fn(root)
}

func loadLongDescription(cmd *cobra.Command, path ...string) error {
for _, c := range cmd.Commands() {
if c.Name() == "" {
continue
}
fullpath := filepath.Join(path[0], strings.Join(append(path[1:], c.Name()), "_")+markdownExtension)
if c.HasSubCommands() {
if err := loadLongDescription(c, path[0], c.Name()); err != nil {
return err
}
}

if _, err := os.Stat(fullpath); err != nil {
log.Printf("WARN: %s does not exist, skipping\n", fullpath)
continue
}

content, err := os.ReadFile(fullpath)
if err != nil {
return err
}
description, examples := parseMDContent(string(content))
c.Long = description
c.Example = examples
}
return nil
}

type options struct {
source string
target string
kind string
}

func parseArgs() (*options, error) {
opts := &options{}
cwd, err := os.Getwd()
if err != nil {
return nil, fmt.Errorf("getting cwd: %w", err)
}
flags := pflag.NewFlagSet(os.Args[0], pflag.ContinueOnError)
flags.StringVar(&opts.source, "root", cwd, "Path to project root")
flags.StringVar(&opts.target, "target", "/tmp", "Target path for generated yaml files")
flags.StringVar(&opts.kind, "kind", "markdown", "Kind of docs to generate (supported: man, markdown)")
if err := flags.Parse(os.Args[1:]); err != nil {
return nil, fmt.Errorf("parsing arguments: %w", err)
}
return opts, nil
}

func parseMDContent(mdString string) (description, examples string) {
parsedContent := strings.Split(mdString, "\n## ")
for _, s := range parsedContent {
if strings.Index(s, "Description") == 0 {
description = strings.TrimSpace(strings.TrimPrefix(s, "Description"))
}
if strings.Index(s, "Examples") == 0 {
examples = strings.TrimSpace(strings.TrimPrefix(s, "Examples"))
}
}
return description, examples
}

func main() {
opts, err := parseArgs()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}
if opts != nil {
fmt.Printf("Project root: %s\n", opts.source)
fmt.Printf("Generating yaml files into %s\n", opts.target)

if err := generateCliYaml(opts); err != nil {
fmt.Fprintf(os.Stderr, "Failed to generate yaml files: %s\n", err.Error())
}
log.Fatalf("invalid docs kind : %s", kind)
}
}
101 changes: 0 additions & 101 deletions docs/advisory_guide_flow.md

This file was deleted.

30 changes: 0 additions & 30 deletions docs/check_so_name.md

This file was deleted.

2 changes: 0 additions & 2 deletions docs/cmd/wolfictl.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ A CLI helper for developing Wolfi

* [wolfictl advisory](wolfictl_advisory.md) - Commands for consuming and maintaining security advisory data
* [wolfictl apk](wolfictl_apk.md) -
* [wolfictl build](wolfictl_build.md) -
* [wolfictl bump](wolfictl_bump.md) - Bumps the epoch field in melange configuration files
* [wolfictl check](wolfictl_check.md) - Subcommands used for CI checks in Wolfi
* [wolfictl dot](wolfictl_dot.md) - Generate graphviz .dot output
Expand All @@ -26,7 +25,6 @@ A CLI helper for developing Wolfi
* [wolfictl lint](wolfictl_lint.md) - Lint the code
* [wolfictl ruby](wolfictl_ruby.md) - Work with ruby packages
* [wolfictl scan](wolfictl_scan.md) - Scan a package for vulnerabilities
* [wolfictl test](wolfictl_test.md) -
* [wolfictl text](wolfictl_text.md) - Print a sorted list of downstream dependent packages
* [wolfictl version](wolfictl_version.md) - Prints the version
* [wolfictl withdraw](wolfictl_withdraw.md) - Withdraw packages from an APKINDEX.tar.gz
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/wolfictl_advisory_alias_discover.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Discover new aliases for vulnerabilities in the advisory data
### Usage

```
wolfictl advisory alias discover
wolfictl advisory alias discover [flags]
```

### Synopsis
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/wolfictl_advisory_alias_find.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Query upstream data sources for aliases for the given vulnerability ID(s)
### Usage

```
wolfictl advisory alias find <vulnerability ID> [<vulnerability ID>...]
wolfictl advisory alias find <vulnerability ID> [<vulnerability ID>...] [flags]
```

### Synopsis
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/wolfictl_advisory_copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Copy a package's advisories into a new package.
### Usage

```
wolfictl advisory copy <source-package-name> <destination-package-name>
wolfictl advisory copy <source-package-name> <destination-package-name> [flags]
```

### Synopsis
Expand Down
5 changes: 2 additions & 3 deletions docs/cmd/wolfictl_advisory_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Create a new advisory
### Usage

```
wolfictl advisory create
wolfictl advisory create [flags]
```

### Synopsis
Expand Down Expand Up @@ -38,15 +38,14 @@ newly created advisory and any other advisories for the same package.
--arch strings package architectures to find published versions for (default [x86_64,aarch64])
-d, --distro-repo-dir string directory containing the distro repository
--fixed-version string package version where fix was applied (used only for 'fixed' event type)
--fp-note string prose explanation of the false positive (used only for false positives)
--fp-type string type of false positive [vulnerability-record-analysis-contested, component-vulnerability-mismatch, vulnerable-code-version-not-used, vulnerable-code-not-included-in-package, vulnerable-code-not-in-execution-path, vulnerable-code-cannot-be-controlled-by-adversary, inline-mitigations-exist]
-h, --help help for create
--no-distro-detection do not attempt to auto-detect the distro
--no-prompt do not prompt the user for input
--note string prose explanation to attach to the event data (can be used with any event type)
-p, --package string package name
-r, --package-repo-url string URL of the APK package repository
--timestamp string timestamp of the event (RFC3339 format) (default "now")
--tp-note string prose explanation of the true positive (used only for true positives)
-t, --type string type of event [detection, true-positive-determination, fixed, false-positive-determination, analysis-not-planned, fix-not-planned, pending-upstream-fix]
-V, --vuln string vulnerability ID for advisory
```
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/wolfictl_advisory_diff.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ See the advisory data differences introduced by your local changes
### Usage

```
wolfictl advisory diff
wolfictl advisory diff [flags]
```

### Synopsis
Expand Down
2 changes: 1 addition & 1 deletion docs/cmd/wolfictl_advisory_discover.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Automatically create advisories by matching distro packages to vulnerabilities i
### Usage

```
wolfictl advisory discover
wolfictl advisory discover [flags]
```

### Synopsis
Expand Down
Loading

0 comments on commit 658d85e

Please sign in to comment.