Skip to content

Commit

Permalink
Merge pull request #13 from marcellodesales/develop
Browse files Browse the repository at this point in the history
Tested Release
  • Loading branch information
marcellodesales authored Sep 17, 2020
2 parents 970980e + 2224fad commit 997e7f8
Show file tree
Hide file tree
Showing 19 changed files with 527 additions and 145 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/develop.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# https://www.freecodecamp.org/news/a-lightweight-tool-agnostic-ci-cd-flow-with-github-actions/
name: build-develop

on:
push:
branches:
- develop
- feature/**

jobs:
test:
name: Run Test Cases
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 1

- name: Golang test
run: make test

build:
name: Build CLI Binaries
runs-on: ubuntu-latest
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://github.com/golangci/golangci-lint-action#how-to-use
name: lint-develop

# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-using-a-list-of-events
on: [push, pull_request]

jobs:
lint:
name: Code Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1

- name: golangci-lint
uses: golangci/golangci-lint-action@v1
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.31

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 - 2020 Marcello de Sales

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ clean: ## Deletes the directory ./build
rm -rf $(DIST_DIR)
mkdir $(DIST_DIR)

test: ## Run the test cases
@echo "Testing current version $(BIN_VERSION)"
go test -v ./...

local: clean ## Makes a local build using Go
@echo "Building binary locally $(BIN_VERSION)"
GO111MODULE=on CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -o dist/cloner-darwin-local main.go

build: clean ## Builds the docker image with binaries
Expand Down
106 changes: 82 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,32 @@ When the CLI runs, it will create the dirs `git.cloneBaseDir/git.host/git.org/gi

# Running

```console
```go
$ cloner git --repo https://github.com/comsysto/redis-locks-with-grafana
INFO[0000] Loading the config object 'git' from '/Users/marcellodesales/.cloner.yaml'
INFO[2020-09-07T16:16:12-03:00] Cloning the provided repo at '/Users/marcellodesales/dev/github.com/comsysto/redis-locks-with-grafana'
INFO[2020-09-07T16:16:15-03:00] Finished cloning...
INFO[2020-09-07T16:16:16-03:00]
/Users/marcellodesales/dev/github.com/comsysto/redis-locks-with-grafana
├── Dockerfile
├── LICENSE
├── README.md
├── docker-compose-redis-standalone-grafana.yml
├── docker-compose-redis-standalone.yml
├── grafana
├── img
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
3 directories, 8 files
INFO[2020-09-08T12:28:11-03:00] Cloning into '/Users/marcellodesales/dev/github.com/comsysto/redis-locks-with-grafana'
Enumerating objects: 233, done.
Total 233 (delta 0), reused 0 (delta 0), pack-reused 233
INFO[2020-09-08T12:28:18-03:00] Done...
$ cloner git --repo https://github.com/comsysto/redis-locks-with-grafana
INFO[0000] Loading the config object 'git' from '/Users/marcellodesales/.cloner.yaml'
ERRO[2020-09-08T12:29:58-03:00] Can't clone repo: clone location '/Users/marcellodesales/dev/github.com/comsysto/redis-locks-with-grafana' exists and it's not empty
ERRO[2020-09-08T12:29:58-03:00] You can specify --force or -f to delete the existing dir and clone again. Make sure there are no panding changes!
$ cloner git --repo https://github.com/comsysto/redis-locks-with-grafana -f
INFO[0000] Loading the config object 'git' from '/Users/marcellodesales/.cloner.yaml'
INFO[2020-09-08T12:30:42-03:00] Forcing clone...
INFO[2020-09-08T12:30:42-03:00] Deleted dir '/Users/marcellodesales/dev/github.com/comsysto/redis-locks-with-grafana'
INFO[2020-09-08T12:30:42-03:00] Cloning into '/Users/marcellodesales/dev/github.com/comsysto/redis-locks-with-grafana'
Enumerating objects: 233, done.
Total 233 (delta 0), reused 0 (delta 0), pack-reused 233
INFO[2020-09-08T12:28:18-03:00] Done...
```

# Development

* Using Golang and Docker to implement the CLI.
* Here's how we are doing it!

## Design

Expand All @@ -91,17 +92,26 @@ main +----->+ CMD +------>+ API +----->+ UTIL |
* `API`: Abstraction of services that implement capabilities
* `UTIL`: Utility functions serving the API services

## Build
## Tests

* Look at the scenarios of the CLI in the tests
* Tests at `cmd/git_test.go`

```shell
make test
```

## Binaries

You can use Golang locally to build a local executable as follows (MacOS)
You can use Golang locally to build a local executable as follows (MacOS). The Github Actions CI [build-develop](https://github.com/marcellodesales/cloner/actions?query=workflow%3Abuild-develop) implements the steps below, publishing binary artifacts at every commit under the `develop` branch.

```console
$ make local
```

* The local build will be available at `dist/cloner-darwin-local`

In order to run the CLI:
Other binary versions are available at the `Artifacts` section of the `build-develop` Github Actions. If you want to build locally, here's what you need to do:

> Requirement: install the following:
> * `docker`
Expand All @@ -123,9 +133,31 @@ The CLI will print the help
$ ./dist/cloner-darwin-amd64
```

# Releases
## Bug Reports & Feature Requests

Requires `make` and `docker` to build as the build is dockerized for Golang.
Please use the [issue tracker](https://github.com/marcellodesales/cloner/issues) to report any bugs or file feature requests.

## Social Coding and Contributing

1. Create an issue to discuss about your idea
2. [Fork it] (https://github.com/marcellodesales/cloner/fork)
3. Create your feature branch (`git checkout -b feature/my-new-feature`)
4. Commit your changes (`git commit -am 'feature x: Add some capability'`)
5. Push to the branch (`git push origin feature/my-new-feature`)
6. Create a new Pull Request
7. Profit! :white_check_mark:

Our Gitflow is as follows:

* `develop`: CI that runs all builds and generate binaries.
* Target your PR here.
* `master`: CD that creates a new release based on a TAG
* Performed from PRs from `develop`
* Publishes latest binary version from `develop`

## Releases

Requires `make` and `docker` for a dockerized build and cross-compilation for Golang. We can run the same exact script on local host or in a CI environemtn. See our Github Action `release-master`, which runs at every PR merge to the `master` branch.

> ATTENTION: Make sure to have a Github token with write permissions to the repo
> * https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
Expand Down Expand Up @@ -270,3 +302,29 @@ Attaching release asset `dist/cloner-linux-amd64'...
Attaching release asset `dist/cloner-windows-amd64.exe'...
https://github.com/marcellodesales/cloner/releases/tag/v19.11.1
```

## License

```
The MIT License (MIT)
Copyright (c) 2019-2020 Marcello de Sales
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```
75 changes: 75 additions & 0 deletions api/git/git_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright © 2019 Marcello de Sales <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package git

import (
"fmt"

"github.com/marcellodesales/cloner/config"
"github.com/marcellodesales/cloner/util"
log "github.com/sirupsen/logrus"
)

/**
* Clones the repo implementation, returning the exit code and any error message
*/
func CloneGitRepo(cloneRequest *CloneGitRepoRequest, config *config.Configuration) (int, []error) {
log.Debugf("config.git.cloneBaseDir=%s", config.Git.CloneBaseDir)
err := GitService.ParseRepoString(cloneRequest)
if err != nil {
return 1, []error{fmt.Errorf("git URL invalid: %v", err)}
}

if cloneRequest.Force {
log.Info("Forcing clone...")
}

deletedExistingDir, err := GitService.VerifyCloneDir(cloneRequest, config)
if deletedExistingDir {
log.Infof("Deleted dir '%s'", cloneRequest.CloneLocation)
}
if err != nil {
return 2, []error{fmt.Errorf("can't clone repo: %v", err),
fmt.Errorf("you can specify --force or -f to delete the existing dir and clone again. " +
"Make sure there are no panding changes")}
}

err = GitService.MakeCloneDir(cloneRequest, config)
if err != nil {
return 3, []error{fmt.Errorf("can't create the base clone repo '%s': %v", cloneRequest.Type.GetUserDir(), err)}
}

log.Infof("Cloning into '%s'", cloneRequest.CloneLocation)
err = GitService.GoCloneRepo(cloneRequest, config)
if err != nil {
return 4, []error{fmt.Errorf("can't clone the repo at '%s': %v", cloneRequest.Type.GetRepoDir(), err)}

} else {
log.Info("Done...")
}

// Show the files cloned
filesListTree, err := GitService.GoPrintTree(cloneRequest)
if err != nil {
return 5, []error{fmt.Errorf("can't show the cloned repo tree '%s': %v", cloneRequest.Type.GetRepoDir(), err)}
}

if util.IsLogInDebug() {
log.Infof("\n%s", filesListTree)
}

return 0, nil
}
Loading

0 comments on commit 997e7f8

Please sign in to comment.