Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions cmd/gendocs/gen_cloud-sql-proxy_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
package main

import (
"bufio"
"bytes"
"fmt"
"os"
"path/filepath"
"regexp"

"github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/cmd"
"github.com/spf13/cobra/doc"
Expand Down Expand Up @@ -48,4 +51,40 @@
cloudSQLProxy.Execute()
cloudSQLProxy.DisableAutoGenTag = true
doc.GenMarkdownTree(cloudSQLProxy.Command, outDir)

// Edit the Markdown file to add release-please tags around the lines that contain
// the version number:
//
// <!-- {x-release-please-start-version} -->
// https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.20.0/third_party/licenses.tar.gz
// <!-- {x-release-please-end} -->

f := filepath.Join(outDir, "cloud-sql-proxy.md")
b, err := os.ReadFile(f)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to read file: %v\n", err)
os.Exit(1)
}

var out bytes.Buffer
sc := bufio.NewScanner(bytes.NewReader(b))
// Example: https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.20.0/third_party/licenses.tar.gz
re := regexp.MustCompile(`https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v\d+\.\d+\.\d+/`)

Check failure

Code scanning / CodeQL

Incomplete regular expression for hostnames High

This regular expression has an unescaped dot before 'googleapis.com', so it might match more hosts than expected when
the regular expression is used
.

Check failure

Code scanning / CodeQL

Missing regular expression anchor High

When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it.
for sc.Scan() {
line := sc.Bytes()
if re.Match(line) {
out.WriteString("<!-- {x-release-please-start-version} -->\n")
out.Write(line)
out.WriteString("\n")
out.WriteString("<!-- {x-release-please-end} -->\n")
} else {
out.Write(line)
out.WriteString("\n")
}
}

if err := os.WriteFile(f, out.Bytes(), 0644); err != nil {
fmt.Fprintf(os.Stderr, "failed to write file: %v\n", err)
os.Exit(1)
}
}
2 changes: 2 additions & 0 deletions docs/cmd/cloud-sql-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ Third Party Licenses
To view all licenses for third party dependencies used within this
distribution please see:

<!-- {x-release-please-start-version} -->
https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.20.0/third_party/licenses.tar.gz
<!-- {x-release-please-end} -->


```
Expand Down
Loading