Skip to content
This repository has been archived by the owner on Jul 26, 2020. It is now read-only.

Linting, Pre-Commit, and Release #20

Merged
merged 14 commits into from
May 17, 2019
54 changes: 27 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
environment: &environment
environment:
- PROJECT_NAME: bake
- GO111MODULE: "on"
PROJECT_NAME: bake
GO111MODULE: "on"

defaults: &defaults
build_defaults: &build_defaults
working_directory: /tmp/build
docker:
- image: golang:1.12.4
- image: golang:1.12.5
<<: *environment

lint_defaults: &lint_defaults
working_directory: /tmp/build
docker:
- image: golangci/golangci-lint:v1.16
<<: *environment

version: 2.1
jobs:
lint:
<<: *defaults
<<: *lint_defaults
steps:
- checkout
- run: go get -u golang.org/x/lint/golint
- run:
name: Run gofmt, enforce formatting
command: "! go fmt ./... 2>&1 | read"
- run:
name: Run golint, enforce styles
command: "golint -set_exit_status ./..."
- run: golangci-lint run --config=$CIRCLE_WORKING_DIRECTORY/.golangci.yml

test:
<<: *defaults
<<: *build_defaults
environment:
TEST_RESULTS: /tmp/test-results
steps:
Expand All @@ -35,31 +35,31 @@ jobs:
- run: mkdir -p $TEST_RESULTS
- run: "go get -u gotest.tools/gotestsum"
- run: "gotestsum --junitfile $TEST_RESULTS/unit-tests.xml"
- run: "go mod tidy"
- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}-test
paths:
- "/go/pkg/mod"
- store_test_results:
path: /tmp/test-results

build:
<<: *defaults
release:
docker:
- image: circleci/golang:1.12
steps:
- checkout
- restore_cache:
keys:
- go-mod-v4-{{ checksum "go.sum" }}
- run: "GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build ."
- save_cache:
key: go-mod-v4-{{ checksum "go.sum" }}
paths:
- "/go/pkg/mod"
- run: curl -sL https://git.io/goreleaser | bash

workflows:
lint_and_build:
jobs:
# - lint
- lint
- test
- build:
requires:
- test
release:
jobs:
- release:
filters:
branches:
ignore: /.*/
tags:
only: /v[0-9]+(\.[0-9]+)*(-.*)*/
1 change: 1 addition & 0 deletions .errcheck-exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(*github.com/spf13/cobra.Command).MarkFlagRequired
30 changes: 30 additions & 0 deletions .golangci.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
run:
# default concurrency is a available CPU number
concurrency: 8
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 1m
# exit code when at least one issue was found, default is 1
issues-exit-code: 1
# include test files or not, default is true
tests: true
skip-dirs:
- .circleci
- .github

linters:
fast: true

# all available settings of specific linters
linters-settings:
errcheck:
# path to a file containing a list of functions to exclude from checking
# see https://github.com/kisielk/errcheck#excluding-functions for details
exclude: .errcheck-exclude

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- errcheck
41 changes: 41 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
run:
# default concurrency is a available CPU number
concurrency: 8
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 30s
# exit code when at least one issue was found, default is 1
issues-exit-code: 1
# include test files or not, default is true
tests: true
skip-dirs:
- .circleci
- .github

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number
# print lines of code with issue, default is true
print-issued-lines: true
# print linter name in the end of issue text, default is true
print-linter-name: true

linters:
fast: true
enable:
- goimports

# all available settings of specific linters
linters-settings:
errcheck:
# path to a file containing a list of functions to exclude from checking
# see https://github.com/kisielk/errcheck#excluding-functions for details
exclude: .errcheck-exclude

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- errcheck
55 changes: 55 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
project_name: bake

release:
github:
owner: breadtubetv
name: bake

before:
hooks:
- go mod download

builds:
- binary: bake
env:
- CGO_ENABLED=0
- GO111MODULE=on
goos:
- linux
- darwin
- windows
goarch:
- amd64
- 386
ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}

archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
format: tar.gz
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
- README.md

checksum:
name_template: '{{ .ProjectName }}-{{ .Version }}-checksums.txt'

snapshot:
name_template: SNAPSHOT-{{.Commit}}

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- README
- Merge branch
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- name: Local Validations
repo: local
hooks:
- id: golangci-lint
name: golangci-lint
description: Fast linters runner for Go.
entry: golangci-lint run --fix
types: [go]
language: golang
pass_filenames: false
91 changes: 57 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
# BreadTube Bake CLI

The `bake` cli is a companion CLI to the [breadtubetv/breadtubetv](https://github.com/breadtubetv/breadtubetv) project.
The `bake` cli is a companion CLI to the [breadtubetv/breadtubetv](https://github.com/breadtubetv/breadtubetv) project.

## [Contributing](https://github.com/breadtubetv/bake/blob/master/CONTRIBUTING.md)

Scripts are being written in Go, this keeps the scripting and operational language the same, provides cross system compatibility, and gives everyone an opportunity to learn a new programming language.

### Installation
## Installation

#### Installing Go
The compiled bake binary has no dependencies, so you can download your platforms release from the [release page](https://github.com/breadtubetv/bake/releases), pop it in your `$PATH` and off you go.

This is going to be dependent on your system, we recommend following https://golang.org/doc/install
If you want to build from source you will need the Go programming language installed, and your `$GOPATH` configured.

#### Developing

You'll need a copy of the project in your `$GOPATH`.

```
```bash
# Enable Go 1.11+ module support
export GO111MODULE=on
go get github.com/breadtubetv/bake
cd $GOPATH/github.com/breadtubetv/bake
```

And you'll need to install bake's dependencies with:
This will install the binary into your `$GOPATH/bin` folder. If you don't already it's recommended you add this directory to your `$PATH`.

```
go get
```

#### Installing
## Usage

This will put the `bake` command in your path:

```
go install
```

#### Configuring the `bake` CLI
### Configuring the `bake` CLI

The `.bake.yaml` configuration file can be stored in the following locations:

Expand All @@ -44,30 +31,66 @@ The `.bake.yaml` configuration file can be stored in the following locations:

Current configuration options and default values:

- `projectRoot: "../"` : Directory of channel data files.
- `projectRoot: "../"` : Directory of channel data files.
E.g. `$GOPATH/src/github.com/breadtubetv/breadtubetv/data/channels`

#### Importing a Channel
### Commands

Once you have `bake` installed:

**Import a Channel:**

```bash
bake channel import creator_slug youtube channel_url
```

You can run bake directly from the source like so:
**Import a Video:**
jmickey marked this conversation as resolved.
Show resolved Hide resolved

```bash
bake import video [--id | --url] video_id_or_URL --creators creator_slug --provider youtube
jmickey marked this conversation as resolved.
Show resolved Hide resolved
```
go run main.go config youtube #follow prompts
go run main.go channel import contrapoints youtube https://www.youtube.com/user/contrapoints

## Contributing

You'll need the Go programming language installed. We recommend version v1.12+. This is going to be dependent on your system, we recommend following <https://golang.org/doc/install>

Clone the repo and pull dependencies:

```bash
# Enable Go 1.11 module support
export GO111MODULE=on
# Clone directory
git clone https://github.com/breadtubetv/bake
cd bake
# Download dependencies
go mod download
jmickey marked this conversation as resolved.
Show resolved Hide resolved
```

Or if you've installed it:
> **NOTE:** The `spf13/cobra` generator CLI won't work if you don't clone the project into `$GOPATH`. This is not a requirement to develop for the project.

### Linting & Pre-Commit

We recommend using [`golangci/golangci-lint`](https://github.com/golangci/golangci-lint) for linting. A development config (`.golangci.dev.yaml`) is provided. To use this config:

```shell
golangci-lint run --config=<path/to/.golangci.dev.yaml>
jmickey marked this conversation as resolved.
Show resolved Hide resolved
```
bake config youtube #follow prompts
bake channel import contrapoints youtube https://www.youtube.com/user/contrapoints

A `.pre-commit-config.yaml` is provided for pre-commit hooks using [`pre-commit/pre-commit`](https://github.com/pre-commit/pre-commit).

### Submitting a PR

We welcome PRs! The only thing we ask is that you ensure you keep the `go.mod` and `go.sum` files clean by running the following:

```shell
GO111MODULE=on go mod tidy
jmickey marked this conversation as resolved.
Show resolved Hide resolved
```

#### Testing
### Testing
jmickey marked this conversation as resolved.
Show resolved Hide resolved

Bake has some very basic tests for now, they can be run with the standard go test command line:

```
```bash
go get -t ./...
go test ./...
```
```
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ var rootCmd = &cobra.Command{

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
func Execute(version, commit, date string) {
rootCmd.Version = version
rootCmd.SetVersionTemplate(fmt.Sprintf("Version: {{.Version}}, Commit: %s, Date: %s", commit, date))
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
6 changes: 6 additions & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func updateChannelList(args []string) {
}

youtube, err := providers.FetchDetails(url)
if err != nil {
log.Fatalf("failed to update channel %s: %v", channel.Slug, err)
}

channel.Providers["youtube"] = youtube

Expand All @@ -72,6 +75,9 @@ func updateChannels() {
}

youtube, err := providers.FetchDetails(url)
if err != nil {
log.Fatalf("failed to update channel %s: %v", channel.Slug, err)
}

channel.Providers["youtube"] = youtube

Expand Down
Loading