Skip to content

Commit

Permalink
BREAKING CHANGE: Remove pull request command
Browse files Browse the repository at this point in the history
  • Loading branch information
p1ass committed Feb 4, 2021
1 parent 6fa7355 commit b92ee32
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 221 deletions.
89 changes: 0 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

## Features
- Create GitHub releases with bumping Semantic Versioning tag
- Send pull requests which update docker image tag.
- Support `{{.Owner}}` and `{{.Repository}}` placeholder in environment variables and command-line options when setting configs.

## Installation

Expand Down Expand Up @@ -66,27 +64,6 @@ $ mikku release sample-repository patch
Note that `mikku` doesn't build and push a docker image, so you have to do it using CI service such as CircleCI.


### Create a pull request updating docker image tag in Kubernetes manifest file

Update image tag in Kubernetes manifest file to the latest version.
```bash
$ export MIKKU_MANIFEST_REPOSITORY=sample-manifest-repository
$ export MIKKU_MANIFEST_FILEPATH=manifests/{{.Repository}}/deployment.yml
$ export MIKKU_DOCKER_IMAGE_NAME={{.Owner}}/{{.Repository}}

$ mikku pr sample-repository
```

```yaml
spec:
containers:
- name: sample-repository-container
image: p1ass/sample-repository:v1.0.0
↓ Replace
image: p1ass/sample-repository:v1.0.1
```


## Screenshots

### Release
Expand All @@ -98,14 +75,6 @@ $ mikku release sample-repository v0.1.1
![changelog](images/changelog.png)


### PullRequest

```bash
$ mikku pr memoito-server
```

![diff](images/diff.png)

## Commands

#### `mikku release <repository> <major | minor | patch | (version)>`
Expand All @@ -129,64 +98,6 @@ $ mikku release sample-repository minor # v1.0.1 → v1.1.0
$ mikku release sample-repository major # v1.1.0 → v2.0.0
```

#### `mikku pr [-m <manifest-repository>] [-p <path-to-manifest-file>] [-i <image-name>] <repository>`

Create a pull request updating Docker image tag written in Kubernetes manifest file.


##### Options

If you don't set environment variables, you must add options when executing commands.

- `--manifest, -m`
- Specify a repository existing Kubernetes manifest file.
- Optional.
- Default : `MIKKU_MANIFEST_REPOSITORY` environment variable.

- `--path, -p`
- File path where the target docker image is written.
- Optional.
- Default : `MIKKU_MANIFEST_FILEPATH` environment variable.
- You can use [text/template](https://golang.org/pkg/text/template/) in Go.
- Support variable : `{{.Owner}}`, `{{.Repository}}`
- Ex. `manifests/{{.Repository}}/deployment.yml`

- `--image, -i`
- Docker image name.
- Optional.
- Default : `MIKKU_DOCKER_IMAGE_NAME` environment variable.
- You can use [text/template](https://golang.org/pkg/text/template/) in Go.
- Support variable : `{{.Owner}}`, `{{.Repository}}`
- Ex. `asia.gcr.io/{{.Owner}}/{{.Repository}}`



##### Examples

```bash
$ export MIKKU_GITHUB_ACCESS_TOKEN=[YOUR_ACCESS_TOKEN]
$ export MIKKU_GITHUB_OWNER=p1ass

# You need to set environment variables. Otherwise, add options when executing commands
$ export MIKKU_MANIFEST_REPOSITORY=manifest-repository
$ export MIKKU_MANIFEST_FILEPATH=manifests/{{.Repository}}/deployment.yml
$ export MIKKU_DOCKER_IMAGE_NAME=asia.gcr.io/{{.Owner}}/{{.Repository}}

# The most simple case
# When the latest tag name is `v1.0.1`,
# replace p1ass/sample-repository:v1.0.0 existing in manifest-repository to p1ass/sample-repository:v1.0.1.
$ mikku pr sample-repository

# Override manifest repository
$ mikku pr --manifest other-manifest-repo sample-repository

# Override Kubernetes manifest file
$ mikku pr --path {{.Owner}}/{{.Repository}}/deployment.yml sample-repository

# Override docker image name
$ mikku pr --image docker.example.com/{{.Repository}} sample-repository
```

## For developers

### Build
Expand Down
2 changes: 1 addition & 1 deletion commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func doRelease(c *cli.Context) error {
func Run(args []string) error {
app := &cli.App{
Name: "mikku",
Usage: "Bump Semantic Versioning tag, create GitHub release and update Kubernetes manifest file",
Usage: "Bump Semantic Versioning tag andcreate GitHub release",
Authors: []*cli.Author{
{
Name: "p1ass",
Expand Down
17 changes: 2 additions & 15 deletions github.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ const (
var (
// errReleaseNotFound represents error that the release does not found
errReleaseNotFound = errors.New("release not found")

errFileORRepoNotFound = errors.New("file or repository not found")
errContentIsDirectory = errors.New("content is directory, not file")
)

//go:generate mockgen -source=$GOFILE -destination=mock_$GOFILE -package=$GOPACKAGE
Expand All @@ -30,9 +27,6 @@ var (
type gitHubRepositoriesClient interface {
CreateRelease(ctx context.Context, owner, repo string, release *github.RepositoryRelease) (*github.RepositoryRelease, *github.Response, error)
GetLatestRelease(ctx context.Context, owner, repo string) (*github.RepositoryRelease, *github.Response, error)

GetContents(ctx context.Context, owner, repo, path string, opt *github.RepositoryContentGetOptions) (fileContent *github.RepositoryContent, directoryContent []*github.RepositoryContent, resp *github.Response, err error)
UpdateFile(ctx context.Context, owner, repo, path string, opt *github.RepositoryContentFileOptions) (*github.RepositoryContentResponse, *github.Response, error)
}

// gitHubPullRequestsClient is a interface for calling GitHub API about pull requests
Expand All @@ -42,17 +36,11 @@ type gitHubPullRequestsClient interface {
Create(ctx context.Context, owner string, repo string, pull *github.NewPullRequest) (*github.PullRequest, *github.Response, error)
}

type gitHubGitClient interface {
GetRef(ctx context.Context, owner string, repo string, ref string) (*github.Reference, *github.Response, error)
CreateRef(ctx context.Context, owner string, repo string, ref *github.Reference) (*github.Reference, *github.Response, error)
}

// githubClient handles application logic using GitHub API
type githubClient struct {
owner string
repoCli gitHubRepositoriesClient
prCli gitHubPullRequestsClient
gitCli gitHubGitClient
}

// newGitHubClientUsingEnv returns a pointer of githubClient
Expand All @@ -65,15 +53,14 @@ func newGitHubClientUsingEnv(owner, accessToken string) *githubClient {
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)

return newGitHubClient(owner, client.Repositories, client.PullRequests, client.Git)
return newGitHubClient(owner, client.Repositories, client.PullRequests)
}

func newGitHubClient(owner string, repoCli gitHubRepositoriesClient, prCli gitHubPullRequestsClient, gitCli gitHubGitClient) *githubClient {
func newGitHubClient(owner string, repoCli gitHubRepositoriesClient, prCli gitHubPullRequestsClient) *githubClient {
return &githubClient{
owner: owner,
repoCli: repoCli,
prCli: prCli,
gitCli: gitCli,
}
}

Expand Down
6 changes: 3 additions & 3 deletions github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestGitHubClient_createRelease(t *testing.T) {
cli := NewMockgitHubRepositoriesClient(ctrl)
cli = tt.injector(cli)

s := newGitHubClient("test-owner", cli, nil, nil)
s := newGitHubClient("test-owner", cli, nil)

got, err := s.createRelease(tt.args.repo, tt.args.tagName, tt.args.body)
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestGitHubService_getLatestRelease(t *testing.T) {
cli := NewMockgitHubRepositoriesClient(ctrl)
cli = tt.injector(cli)

s := newGitHubClient("test-owner", cli, nil, nil)
s := newGitHubClient("test-owner", cli, nil)

got, err := s.getLatestRelease(tt.repo)
fmt.Printf("%#v\n", got)
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestGitHubService_getMergedPRsAfter(t *testing.T) {
cli := NewMockgitHubPullRequestsClient(ctrl)
cli = tt.injector(cli)

s := newGitHubClient("test-owner", nil, cli, nil)
s := newGitHubClient("test-owner", nil, cli)
got, err := s.getMergedPRsAfter(tt.repo, tt.after)
if (err != nil) != tt.wantErr {
t.Errorf("githubClient.getMergedPRsAfter() error = %v, wantErr %v", err, tt.wantErr)
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ require (
github.com/google/go-cmp v0.5.4
github.com/google/go-github/v32 v32.1.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/kr/pretty v0.1.0 // indirect
github.com/urfave/cli/v2 v2.3.0
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect

)
21 changes: 0 additions & 21 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,26 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
github.com/google/go-github/v32 v28.1.1 h1:kORf5ekX5qwXO2mGzXXOjMe/g6ap8ahVe0sBEulhSxo=
github.com/google/go-github/v32 v28.1.1/go.mod h1:bsqJWQX05omyWVmc00nEUql9mhQyv38lDZ8kPZcQVoM=
github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
Expand All @@ -50,8 +36,6 @@ golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAG
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -65,9 +49,4 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Binary file removed images/diff.png
Binary file not shown.
91 changes: 1 addition & 90 deletions mock_github.go

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

0 comments on commit b92ee32

Please sign in to comment.