Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cobra and viper setup #3

Merged
21 commits merged into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/markdown-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
markdown-checks:
lint:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
Expand All @@ -27,6 +27,11 @@ jobs:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- name: markdownlint-cli2-action
uses: DavidAnson/markdownlint-cli2-action@v9

link-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
- uses: gaurav-nelson/github-action-markdown-link-check@d53a906aa6b22b8979d33bc86170567e619495ec # v1.0.15
with:
use-quiet-mode: 'yes'
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/scan-codeql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: scan:codeql

on:
workflow_dispatch:
push:
paths-ignore:
- '**/*.md'
schedule:
- cron: "0 0 * * 0"

permissions:
actions: read # for github/codeql-action/init to get workflow details
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/analyze to upload SARIF results

jobs:
codeql:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@cba0d00b1fc9a034e1e642ea0f1103c282990604 # 2.5.0
with:
egress-policy: block
disable-telemetry: true
allowed-endpoints: >
github.com:443
*.github.51.al:443
proxy.golang.org:443
storage.googleapis.com:443
sum.golang.org:443
objects.githubusercontent.com:443
- name: Check out code
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: go
queries: security-and-quality
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
# Go workspace file
go.work

# Build files
/out

### Helm ###
# Chart dependencies
**/charts/*.tgz
Expand Down
109 changes: 109 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Contribution guide

Everyone is more than welcome to contribute to this project! That's what open source is all about!

In the following, we try to provide some help and guidance on how to participate, contribute and develop on the project.

**Table of content:**

- [1. Raising an issue or feature request](#1-raising-an-issue-or-feature-request)
- [2. Project Setup \& Development](#2-project-setup--development)
- [2.1 Recommended IDE Setup](#21-recommended-ide-setup)
- [2.1.1 Type Support for `.vue` Imports in TypeScript](#211-type-support-for-vue-imports-in-typescript)
- [2.2 Daily-used commands](#22-daily-used-commands)
- [2.2.1 Installing all dependencies](#221-installing-all-dependencies)
- [2.2.2 Compile and Hot-Reload for Development](#222-compile-and-hot-reload-for-development)
- [2.2.3 Lint with ESLint](#223-lint-with-eslint)
- [2.2.4 Type-Check, Compile and Minify for Production](#224-type-check-compile-and-minify-for-production)
- [2.3 Usage of mkcert](#23-usage-of-mkcert)
- [2.4 Sandbox environment](#24-sandbox-environment)
- [2.5 Git workflow](#25-git-workflow)
- [2.5.1 Releases \& Versioning](#251-releases--versioning)
- [2.5.2 Patching of older release](#252-patching-of-older-release)

## 1. Raising an issue or feature request

The simplest way to contribute to the project is to use it!

Whenever you encounter any issues or missing features while using the project, please create a [GitHub Issue](https://github.com/florianrusch/vue3-quagga2/issues) in this project and describe what you found or what you need. To help you with this, we provide several templates to help and guide you through the issue creation.

## 2. Project Setup & Development

If you are interested in getting your hands dirty, the following subsections provide information and instructions for the setup of your local development environment.

### 2.1 Recommended IDE Setup

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

#### 2.1.1 Type Support for `.vue` Imports in TypeScript

TypeScript cannot handle type information for `.vue` imports by default, so we replaced the `tsc` CLI with `vue-tsc` for type checking. In editors, e.g. for [VSCode](https://code.visualstudio.com/) we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.

### 2.2 Daily-used commands

#### 2.2.1 Installing all dependencies

```sh
npm install
```

#### 2.2.2 Compile and Hot-Reload for Development

> Please be aware that some browser allow access to the cameras only if the website uses http**s**.
> Therefor we are using [mkcert](https://github.com/FiloSottile/mkcert). See [this chapter](#23-usage-of-mkcert) for more details.

```sh
npm run dev
```

Or if you want to access the application from you mobile device while developing:

```sh
npm run dev-network
```

#### 2.2.3 Lint with [ESLint](https://eslint.org/)

```sh
# Shows errors
npm run lint

# Fixes errors
npm run lint:fix
```

#### 2.2.4 Type-Check, Compile and Minify for Production

```sh
npm run build
```

### 2.3 Usage of mkcert

As some browsers only allow camera access on websites that were transferred via HTTP**S** we need for development purposes also HTTP**S**. To make it simple for the developer, we are using [mkcert](https://github.com/FiloSottile/mkcert) which was made to use one local Certificate Authority (CA) for all local development projects.

As we are using vite for hosting our local development server, we are also using the [vite-plugin-mkcert](https://github.com/liuweiGL/vite-plugin-mkcert) to configure and set up mkcert.

As the project is mostly focusing on mobile applications, we would also need to allow/accept the local self-signed certificates on our mobile devices. The vite-plugin we are using provides a good guide on how to do this: <https://github.com/liuweiGL/vite-plugin-mkcert#mobile-devices>

### 2.4 Sandbox environment

A sandbox environment has been set up for development purposes. You can find it in the [`/sandbox`](./sandbox/) folder and in the [`index.html`](./index.html).

### 2.5 Git workflow

The development is orientated on GitHub flow. Therefore every source code contribution needs to be provided through a [GitHub Pull-Request](https://github.com/florianrusch/vue3-quagga2/pulls) against the `main` branch.

#### 2.5.1 Releases & Versioning

Releases will be made by tagging a specific commit on the `main` branch. For the versioning we are using the [Semantic Versioning Schema](https://semver.org/):

> Given a version number MAJOR.MINOR.PATCH, increment the:
>
> 1. MAJOR version when you make incompatible API changes
> 2. MINOR version when you add functionality in a backwards compatible manner
> 3. PATCH version when you make backwards compatible bug fixes

#### 2.5.2 Patching of older release

Sometimes it's happening that security issues appear in older releases. Regarding the fact that the community behind this project is not very large, we are not able to provide patches for each release we have ever published. Therefore, _**we will only maintain the latest minor version with security patches and bug fixes!**_
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Path to the main file
MAIN_FILE_PATH ?= ./main.go

# Path where the binary will be stored
BINARY_FILE_PATH = out/lb

GOOS ?= linux
GOARCH ?= amd64

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

.PHONY: all
all: build

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development

.PHONY: dependencies
dependencies: ## Run go mod download against code.
go mod download

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

.PHONY: test
test: ## Run tests.
go test ./... -coverprofile cover.out

##@ Build

.PHONY: ci
ci: dependencies vet test build ## Run certain recipes for CI pipeline.

.PHONY: build
build: ## Build binary.
GOOS=${GOOS} GOARCH=${GOARCH} go build --ldflags="-s -w" -o ${BINARY_FILE_PATH} ${MAIN_FILE_PATH}
37 changes: 37 additions & 0 deletions cmd/backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2023 cluetec GmbH
*
* 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 cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// backupCmd represents the backup command
var backupCmd = &cobra.Command{
Use: "backup",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("backup called")
},
}
47 changes: 47 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2023 cluetec GmbH
*
* 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 cmd

import (
"os"

"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "lb",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
}

// 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() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {
rootCmd.AddCommand(backupCmd)
}
31 changes: 31 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module github.com/cluetec/lifeboat

go 1.21.3

require (
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.17.0
)

require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading