Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
Signed-off-by: Johnatas <[email protected]>
  • Loading branch information
johnatasr committed Nov 15, 2023
1 parent aae5899 commit e3b512e
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 78 deletions.
64 changes: 64 additions & 0 deletions cmd/rancher_release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,70 @@ rancher_release label-issues -t v2.8.1-rc1 --dry-run
# [Waiting for RC] -> [To Test]
```

### check-rancher-rc-deps

This command checks Rancher by the commit hash in the selected files, verifying if they contain 'rc' and 'dev' dependencies. It generates an MD-formatted file print that can be used as a release description. If necessary, the command can generate an error if these dependencies are found, ideal for use in CI pipelines. When executed in the root of the Rancher project, it checks the `rancher-images.txt` and `rancher-windows-images.txt` files.

The pattern of files to be checked includes:
- `pkg/settings/setting.go`
- `package/Dockerfile`
- `scripts/package-env`
- `Dockerfile.dapper`
- `go.mod`
- `pkg/apis/go.mod`
- `pkg/client/go.mod`

| **Flag** | **Description** | **Required** |
| ---------------- | ----------------------------------------------------------------------------------------------------- | ------------ |
| `commit`, `c` | Required commit to find the Rancher project reference that will be executed | TRUE |
| `org`, `o` | Reference organization of the commit | FALSE |
| `repo`, `r` | Reference repository of the commit | FALSE |
| `files`, `f` | List of files to be checked by the command, they are mandatory | TRUE |
| `for-ci`, `p` | With this flag, it's possible to return an error if any of the files contain 'rc' tags or 'dev' dependencies, ideal for use in integration pipelines | FALSE |

**Examples**

```
rancher_release check-rancher-rc-deps -c <HASH_COMMIT> -f Dockerfile.dapper,go.mod,/package/Dockerfile,/pkg/apis/go.mod,/pkg/settings/setting.go,/scripts/package-env
```

```
# Images with -rc
* rancher/backup-restore-operator v4.0.0-rc1 (./bin/rancher-images.txt, line 1)
* rancher/rancher v2.8.0-rc3 (./bin/rancher-windows-images.txt, line 1)
* rancher/rancher-agent v2.8.0-rc3 (./bin/rancher-windows-images.txt, line 2)
* rancher/system-agent v0.3.4-rc1-suc (./bin/rancher-windows-images.txt, line 3)
# Components with -rc
* ENV CATTLE_KDM_BRANCH=dev-v2.8 (Dockerfile.dapper, line 16)
* ARG SYSTEM_CHART_DEFAULT_BRANCH=dev-v2.8 (/package/Dockerfile, line 1)
* ARG CHART_DEFAULT_BRANCH=dev-v2.8 (/package/Dockerfile, line 1)
* ARG CATTLE_KDM_BRANCH=dev-v2.8 (/package/Dockerfile, line 1)
* KDMBranch = NewSetting("kdm-branch", "dev-v2.8") (/pkg/settings/setting.go, line 84)
* ChartDefaultBranch = NewSetting("chart-default-branch", "dev-v2.8") (/pkg/settings/setting.go, line 116)
* SYSTEM_CHART_DEFAULT_BRANCH=${SYSTEM_CHART_DEFAULT_BRANCH:-"dev-v2.8"} (/scripts/package-env, line 5)
* CHART_DEFAULT_BRANCH=${CHART_DEFAULT_BRANCH:-"dev-v2.8"} (/scripts/package-env, line 7)
# Min version components with -rc
* ENV CATTLE_FLEET_MIN_VERSION=103.1.0+up0.9.0-rc.3
* ENV CATTLE_CSP_ADAPTER_MIN_VERSION=103.0.0+up3.0.0-rc1
# Components with dev-
* ENV CATTLE_KDM_BRANCH=dev-v2.8 (Dockerfile.dapper, line 16)
* ARG SYSTEM_CHART_DEFAULT_BRANCH=dev-v2.8 (/package/Dockerfile, line 1)
* ARG CHART_DEFAULT_BRANCH=dev-v2.8 (/package/Dockerfile, line 1)
* ARG CATTLE_KDM_BRANCH=dev-v2.8 (/package/Dockerfile, line 1)
* KDMBranch = NewSetting("kdm-branch", "dev-v2.8") (/pkg/settings/setting.go, line 84)
* ChartDefaultBranch = NewSetting("chart-default-branch", "dev-v2.8") (/pkg/settings/setting.go, line 116)
* SYSTEM_CHART_DEFAULT_BRANCH=${SYSTEM_CHART_DEFAULT_BRANCH:-"dev-v2.8"} (/scripts/package-env, line 5)
* CHART_DEFAULT_BRANCH=${CHART_DEFAULT_BRANCH:-"dev-v2.8"} (/scripts/package-env, line 7)
```

## Contributions

- File Issue with details of the problem, feature request, etc.
Expand Down
21 changes: 5 additions & 16 deletions cmd/rancher_release/check_rancher_rc_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"errors"
"fmt"

"github.com/rancher/ecm-distro-tools/release/rancher"
"github.com/sirupsen/logrus"
Expand All @@ -20,12 +19,6 @@ func checkRancherRCDepsCommand() *cli.Command {
Usage: "last commit for a final rc",
Required: false,
},
&cli.StringFlag{
Name: "release-title",
Aliases: []string{"t"},
Usage: "release title from a given release process",
Required: false,
},
&cli.StringFlag{
Name: "org",
Aliases: []string{"o"},
Expand Down Expand Up @@ -56,28 +49,24 @@ func checkRancherRCDepsCommand() *cli.Command {
}

func checkRancherRCDeps(c *cli.Context) error {
rcReleaseTitle := c.String("release-title")
rcCommit := c.String("commit")
rcOrg := c.String("org")
rcRepo := c.String("repo")
rcFiles := c.String("files")
forCi := c.Bool("for-ci")

if rcCommit == "" && rcReleaseTitle == "" {
return errors.New("'commit' or 'release-title' are required")
if rcCommit == "" {
return errors.New("'commit hash' are required")
}
if rcFiles == "" {
return errors.New("'files' is required, e.g, --files Dockerfile.dapper,go.mod")
}
logrus.Debugf("organization: %s, repository: %s, commit: %s, release title: %s, files: %s",
rcOrg, rcRepo, rcCommit, rcReleaseTitle, rcFiles)
logrus.Debugf("organization: %s, repository: %s, commit: %s, files: %s",
rcOrg, rcRepo, rcCommit, rcFiles)

output, err := rancher.CheckRancherRCDeps(forCi, rcOrg, rcRepo, rcCommit, rcReleaseTitle, rcFiles)
err := rancher.CheckRancherRCDeps(forCi, rcOrg, rcRepo, rcCommit, rcFiles)
if err != nil {
return err
}

fmt.Println(output)

return nil
}
107 changes: 45 additions & 62 deletions release/rancher/rancher.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,10 @@ type Content struct {
FilesWithDev []ContentLine
}

func CheckRancherRCDeps(forCi bool, org, repo, commitHash, releaseTitle, files string) (string, error) {
const (
releaseTitleRegex = `^Pre-release v2\.7\.[0-9]{1,100}-rc[1-9][0-9]{0,1}$`
partialFinalRCCommitMessage = "last commit for final rc"
)
func CheckRancherRCDeps(forCi bool, org, repo, commitHash, files string) error {
const partialFinalRCCommitMessage = "commit for final rc"
var (
matchCommitMessage bool
existsReleaseTitle bool
badFiles bool
content Content
)
Expand All @@ -369,87 +365,74 @@ func CheckRancherRCDeps(forCi bool, org, repo, commitHash, releaseTitle, files s
if org == "" {
org = rancherOrg
}

if commitHash != "" {
commitData, err := repository.CommitInfo(org, repo, commitHash, &httpClient)
if err != nil {
return "", err
return err
}
matchCommitMessage = strings.Contains(commitData.Message, partialFinalRCCommitMessage)

}
if releaseTitle != "" {
innerExistsReleaseTitle, err := regexp.MatchString(releaseTitleRegex, releaseTitle)
if err != nil {
return "", err
}
existsReleaseTitle = innerExistsReleaseTitle
}

//should return data if executed in rancher project root path
err := writeRancherImagesDeps(&content, rcTagPattern)
if err != nil {
return "", err
return err
}

if matchCommitMessage || existsReleaseTitle {
for _, filePath := range strings.Split(files, ",") {
repoContent, err := repository.ContentByFileNameAndCommit(org, repo, commitHash, filePath, &httpClient)
if err != nil {
return "", err
}
for _, filePath := range strings.Split(files, ",") {
repoContent, err := repository.ContentByFileNameAndCommit(org, repo, commitHash, filePath, &httpClient)
if err != nil {
return err
}

scanner := bufio.NewScanner(strings.NewReader(string(repoContent)))
lineNum := 1
scanner := bufio.NewScanner(strings.NewReader(string(repoContent)))
lineNum := 1

for scanner.Scan() {
lineByte, line := formatLineByte(scanner.Text())
for scanner.Scan() {
lineByte, line := formatLineByte(scanner.Text())

if devDependencyPattern.Match(lineByte) {
badFiles = true
lineContent := ContentLine{File: filePath, Line: lineNum, Content: formatContentLine(line)}
content.FilesWithRC = append(content.FilesWithRC, lineContent)
}
if strings.Contains(filePath, "/package/Dockerfile") {
if !strings.Contains(line, "_VERSION") {
continue
}
matches := regexp.MustCompile(`CATTLE_(\S+)_MIN_VERSION`).FindStringSubmatch(line)
if len(matches) == 2 && strings.Contains(line, "-rc") {
lineContent := ContentLine{Line: lineNum, File: filePath, Content: formatContentLine(line)}
content.MinFilesWithRC = append(content.MinFilesWithRC, lineContent)
}
if devDependencyPattern.Match(lineByte) {
badFiles = true
lineContent := ContentLine{File: filePath, Line: lineNum, Content: formatContentLine(line)}
content.FilesWithRC = append(content.FilesWithRC, lineContent)
}
if strings.Contains(filePath, "/package/Dockerfile") {
if !strings.Contains(line, "_VERSION") {
continue
}
if rcTagPattern.Match(lineByte) {
badFiles = true
lineContent := ContentLine{File: filePath, Line: lineNum, Content: formatContentLine(line)}
content.FilesWithDev = append(content.FilesWithDev, lineContent)
matches := regexp.MustCompile(`CATTLE_(\S+)_MIN_VERSION`).FindStringSubmatch(line)
if len(matches) == 2 && strings.Contains(line, "-rc") {
lineContent := ContentLine{Line: lineNum, File: filePath, Content: formatContentLine(line)}
content.MinFilesWithRC = append(content.MinFilesWithRC, lineContent)
}
lineNum++
}
if err := scanner.Err(); err != nil {
return "", err
if rcTagPattern.Match(lineByte) {
badFiles = true
lineContent := ContentLine{File: filePath, Line: lineNum, Content: formatContentLine(line)}
content.FilesWithDev = append(content.FilesWithDev, lineContent)
}
lineNum++
}

tmpl := template.New("rancher-release-rc-dev-deps")
tmpl = template.Must(tmpl.Parse(templateCheckRCDevDeps))
buff := bytes.NewBuffer(nil)
err := tmpl.ExecuteTemplate(buff, "componentsFile", content)
if err != nil {
return "", err
if err := scanner.Err(); err != nil {
return err
}
output := buff.String()
}

if forCi && badFiles {
fmt.Println(output)
return "", errors.New("check failed, some files don't match the expected dependencies for a final release candidate")
}
tmpl := template.New("rancher-release-rc-dev-deps")
tmpl = template.Must(tmpl.Parse(templateCheckRCDevDeps))
buff := bytes.NewBuffer(nil)
err = tmpl.ExecuteTemplate(buff, "componentsFile", content)
if err != nil {
return err
}

fmt.Println(buff.String())

return output, nil
if forCi && matchCommitMessage && badFiles {
return errors.New("check failed, some files don't match the expected dependencies for a final release candidate")
}

return "skipped check", nil
return nil
}

func writeRancherImagesDeps(content *Content, rcTagPattern *regexp.Regexp) error {
Expand Down

0 comments on commit e3b512e

Please sign in to comment.