Skip to content

Commit

Permalink
Merge branch 'master' into add_checksums
Browse files Browse the repository at this point in the history
  • Loading branch information
briandowns authored Oct 19, 2023
2 parents e019a31 + 9668e8d commit d4d921c
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ jobs:
${{ github.workspace }}/cmd/rke2_release/bin/rke2_release-linux-amd64
${{ github.workspace }}/cmd/rke2_release/bin/rke2_release-linux-arm64
${{ github.workspace }}/cmd/rke2_release/bin/sha256sums-rke2_release.txt
${{ github.workspace }}/cmd/semv/bin/semv-darwin-amd64
${{ github.workspace }}/cmd/semv/bin/semv-darwin-arm64
${{ github.workspace }}/cmd/semv/bin/semv-freebsd-amd64
${{ github.workspace }}/cmd/semv/bin/semv-freebsd-arm64
${{ github.workspace }}/cmd/semv/bin/semv-linux-amd64
${{ github.workspace }}/cmd/semv/bin/semv-linux-arm64
${{ github.workspace }}/cmd/semv/bin/sha256sums-semv.txt
${{ github.workspace }}/cmd/test_coverage/bin/test_coverage-darwin-amd64
${{ github.workspace }}/cmd/test_coverage/bin/test_coverage-darwin-arm64
${{ github.workspace }}/cmd/test_coverage/bin/test_coverage-freebsd-amd64
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ test_coverage:
upstream_go_version:
cd cmd/$@ && $(MAKE)

.PHONY: semv
semv:
cd cmd/$@ && $(MAKE)

.PHONY: test
test:
go test -v -cover ./...
Expand Down
2 changes: 1 addition & 1 deletion cmd/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BINARIES = gen_release_notes gen_release_report backport standup k3s_release rancher_release test_coverage upstream_go_version rke2_release
BINARIES = gen_release_notes gen_release_report backport semv standup k3s_release rancher_release test_coverage upstream_go_version rke2_release
ARCHS = amd64 arm64
OSs = linux darwin freebsd

Expand Down
20 changes: 18 additions & 2 deletions cmd/rancher_release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Results are printed in MD, and can be pasted into Slack, but formatting is trick
**Examples**

```
rancher_release list-nonmirrored-rc-images --tag v2.6
rancher_release list-nonmirrored-rc-images --tag v2.8.0-rc1
```

### check-rancher-image
Expand All @@ -32,7 +32,7 @@ Checks if there’s an available Helm Chart and Docker images for amd64, arm and
**Examples**

```
rancher_release check-rancher-image --tag v2.6
rancher_release check-rancher-image --tag v2.8.0-rc1
```

### set-kdm-branch-refs
Expand Down Expand Up @@ -102,6 +102,22 @@ export GITHUB_TOKEN={YOUR_GITHUB_TOKEN}
rancher_release set-charts-branch-refs -f $GOPATH/src/github.com/{YOUR_USERNAME}/rancher -b release/v2.8 -c dev-v2.8 -n dev-v2.9 -p -o {YOUR_USERNAME}
```

### label-issues

Given a release candidate, updates each GitHub issue belonging to its milestone with the tag `[zube]: To Test` and adds a comment with the prerelease version to test.

**Examples**

```sh
rancher_release label-issues -t v2.8.1-rc1 --dry-run
# Updating 2 issues
# #1 Issue one (v2.8.x)
# [Waiting for RC] -> [To Test]
# #2 Issue two (v2.8.x)
# [Waiting for RC] -> [To Test]
```


## Contributions

- File Issue with details of the problem, feature request, etc.
Expand Down
140 changes: 140 additions & 0 deletions cmd/rancher_release/label_issues.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package main

import (
"context"
"errors"
"fmt"

"github.com/Masterminds/semver/v3"
"github.com/google/go-github/v39/github"
"github.com/rancher/ecm-distro-tools/repository"
"github.com/urfave/cli/v2"
)

func labelIssuesCommand() *cli.Command {
return &cli.Command{
Name: "label-issues",
Usage: "relabels 'Waiting for RC' issues with 'To Test' and adds a comment",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "github-token",
Aliases: []string{"g"},
Usage: "github token",
EnvVars: []string{"GITHUB_TOKEN"},
Required: false,
},
&cli.StringFlag{
Name: "tag",
Aliases: []string{"t"},
Usage: "release candidate tag",
Required: true,
},
&cli.BoolFlag{
Name: "dry-run",
Aliases: []string{"r"},
Usage: "list matching issues and new labels without updating",
Required: false,
},
},
Action: labelIssuesWaitingForRC,
}
}

// labelIssuesWaitingForRC updates issues with the "Waiting for RC" label
// to "To Test" if the issue's milestone matches the tag, and creates a comment
func labelIssuesWaitingForRC(c *cli.Context) error {
ctx := context.Background()
tag := c.String("tag")
dryRun := c.Bool("dry-run")
githubToken := c.String("github-token")
const org = "rancher"
const repo = "rancher"
const oldTag = "[zube]: Waiting for RC"
const newTag = "[zube]: To Test"

if tag == "" {
return errors.New("'tag' must be set")
}
v, err := semver.NewVersion(tag)
if err != nil {
return err
}
if v.Prerelease() == "" {
return errors.New("'tag' must be a prerelease")
}
v, err = semver.NewVersion(fmt.Sprintf("%d.%d.%d", v.Major(), v.Minor(), v.Patch()))
if err != nil {
return err
}

if githubToken == "" {
return errors.New("'GITHUB_TOKEN' environment variable must be set")
}
client := repository.NewGithub(ctx, githubToken)
opts := &github.IssueListByRepoOptions{
State: "open",
Labels: []string{oldTag},
}
issues := make([]*github.Issue, 0)
for {

ghIssues, resp, err := client.Issues.ListByRepo(ctx, org, repo, opts)
if err != nil {
return err
}

for _, issue := range ghIssues {
if issue.Milestone == nil {
continue
}
pattern, err := semver.NewConstraint(*issue.Milestone.Title)
if err != nil {
return err
}
if pattern.Check(v) {
issues = append(issues, issue)
}
}

if resp.NextPage == 0 {
break
}
opts.ListOptions.Page = resp.NextPage
}

if dryRun {
if len(issues) == 1 {
fmt.Printf("Updating %d issue\n", len(issues))
} else {
fmt.Printf("Updating %d issues\n", len(issues))
}
}

for _, issue := range issues {
if dryRun {
fmt.Printf("#%d %s (%s)\n [%s] -> [%s] \n", *issue.Number, *issue.Title, *issue.Milestone.Title, oldTag, newTag)
continue
}
labels := make([]string, 0, len(issue.Labels))
for _, label := range issue.Labels {
if label.GetName() != oldTag {
labels = append(labels, label.GetName())
}
}
labels = append(labels, newTag)
_, _, err = client.Issues.Edit(ctx, org, repo, *issue.Number, &github.IssueRequest{
Labels: &labels,
})
if err != nil {
return err
}
_, _, err = client.Issues.CreateComment(ctx, org, repo, *issue.Number, &github.IssueComment{
Body: github.String("Available to test on " + tag),
})
if err != nil {
return err
}
}

return nil
}
1 change: 1 addition & 0 deletions cmd/rancher_release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func main() {
checkRancherImageCommand(),
setKDMBranchReferencesCommand(),
setChartsBranchReferencesCommand(),
labelIssuesCommand(),
}
app.Flags = rootFlags

Expand Down
23 changes: 23 additions & 0 deletions cmd/semv/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
include ../Makefile

GO = go

BINDIR := bin
BINARY := semv

VERSION = v0.1.0
GIT_SHA = $(shell git rev-parse HEAD)
override LDFLAGS += -X main.gitSHA=$(GIT_SHA) -X main.version=$(VERSION) -X main.name=$(BINARY) -extldflags '-static -Wl,--fatal-warnings'
TAGS = "netgo osusergo no_stage static_build"

$(BINDIR)/$(BINARY): clean
for arch in $(ARCHS); do \
for os in $(OSs); do \
$(GO_COMPILE) ; \
done; \
done

.PHONY: clean
clean:
$(GO) clean
rm -f $(BINDIR)/$(BINARY)
22 changes: 22 additions & 0 deletions cmd/semv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# semv

`semv` provides subcommands to parse a semantic version, and to test if a version conforms to a semantic version constraint.

### Examples

```sh
PRERELEASE=$(./bin/semv-darwin-amd64 parse --output go-template="{{ .Prerelease }}" v1.2.3)
if [ -n "$PRERELEASE" ]; then
echo "Prerelease: $PRERELEASE"
fi

```

```sh
semv test v1.1 v1.1.1
```

## Contributions

* File Issue with details of the problem, feature request, etc.
* Submit a pull request and include details of what problem or feature the code is solving or implementing.
Loading

0 comments on commit d4d921c

Please sign in to comment.