Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalcaliskan committed Jan 13, 2024
2 parents e96ae7c + 7162fa3 commit 5c3cbbf
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 192 deletions.
64 changes: 29 additions & 35 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ jobs:
run: make -s clean

test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -66,38 +63,35 @@ jobs:
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

# sonarcloud:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# with:
# fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
# - name: Install Go
# uses: actions/setup-go@v5
# with:
# go-version-file: "go.mod"
# cache: true
# - name: Test
# run: make -s test
# - name: SonarCloud Scan
# uses: SonarSource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# with:
# args: >
# -Dproject.settings=build/ci/sonar-project.properties
# - name: SonarQube Quality Gate check
# uses: sonarsource/sonarqube-quality-gate-action@master
# timeout-minutes: 5
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
sonarcloud:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache: true
- name: Test
run: make -s test
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dproject.settings=build/ci/sonar-project.properties
- name: SonarQube Quality Gate check
uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -106,5 +100,5 @@ jobs:
with:
go-version-file: "go.mod"
cache: true
- name: Test
- name: Build
run: make -s build
75 changes: 30 additions & 45 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ jobs:
run: make -s clean

test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -63,38 +60,35 @@ jobs:
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

# sonarcloud:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# with:
# fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
# - name: Install Go
# uses: actions/setup-go@v5
# with:
# go-version-file: "go.mod"
# cache: true
# - name: Test
# run: make -s test
# - name: SonarCloud Scan
# uses: SonarSource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# with:
# args: >
# -Dproject.settings=build/ci/sonar-project.properties
# - name: SonarQube Quality Gate check
# uses: sonarsource/sonarqube-quality-gate-action@master
# timeout-minutes: 5
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
sonarcloud:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache: true
- name: Test
run: make -s test
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dproject.settings=build/ci/sonar-project.properties
- name: SonarQube Quality Gate check
uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -103,7 +97,7 @@ jobs:
with:
go-version-file: "go.mod"
cache: true
- name: Test
- name: Build
run: make -s build

tag:
Expand All @@ -113,7 +107,7 @@ jobs:
- test
- codeql
- staticcheck
# - sonarcloud
- sonarcloud
- build
steps:
- name: Checkout
Expand Down Expand Up @@ -142,14 +136,6 @@ jobs:
echo "::set-output name=latest_tag::$(git describe --tags $(git rev-list --tags --max-count=1))"
echo "::set-output name=build_time::$(date -u +'%m-%d-%YT%H:%M:%SZ')"
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2
# - name: Docker Login
# uses: docker/login-action@v2
# with:
# registry: docker.io
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
- name: Install Go
uses: actions/setup-go@v5
with:
Expand All @@ -162,4 +148,3 @@ jobs:
args: release --clean --config build/package/.goreleaser.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}
74 changes: 28 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,42 @@
# golang-cli-template
[![CI](https://github.com/bilalcaliskan/golang-cli-template/workflows/CI/badge.svg?event=push)](https://github.com/bilalcaliskan/golang-cli-template/actions?query=workflow%3ACI)
[![Docker pulls](https://img.shields.io/docker/pulls/bilalcaliskan/golang-cli-template)](https://hub.docker.com/r/bilalcaliskan/golang-cli-template/)
[![Go Report Card](https://goreportcard.com/badge/github.com/bilalcaliskan/golang-cli-template)](https://goreportcard.com/report/github.com/bilalcaliskan/golang-cli-template)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=bilalcaliskan_golang-cli-template&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_golang-cli-template)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=bilalcaliskan_golang-cli-template&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_golang-cli-template)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=bilalcaliskan_golang-cli-template&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_golang-cli-template)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=bilalcaliskan_golang-cli-template&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_golang-cli-template)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=bilalcaliskan_golang-cli-template&metric=coverage)](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_golang-cli-template)
[![Release](https://img.shields.io/github/release/bilalcaliskan/golang-cli-template.svg)](https://github.com/bilalcaliskan/golang-cli-template/releases/latest)
[![Go version](https://img.shields.io/github/go-mod/go-version/bilalcaliskan/golang-cli-template)](https://github.com/bilalcaliskan/golang-cli-template)
# split-the-tunnel
[![CI](https://github.com/bilalcaliskan/split-the-tunnel/workflows/CI/badge.svg?event=push)](https://github.com/bilalcaliskan/split-the-tunnel/actions?query=workflow%3ACI)
[![Go Report Card](https://goreportcard.com/badge/github.com/bilalcaliskan/split-the-tunnel)](https://goreportcard.com/report/github.com/bilalcaliskan/split-the-tunnel)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=bilalcaliskan_split-the-tunnel&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_split-the-tunnel)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=bilalcaliskan_split-the-tunnel&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_split-the-tunnel)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=bilalcaliskan_split-the-tunnel&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_split-the-tunnel)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=bilalcaliskan_split-the-tunnel&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_split-the-tunnel)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=bilalcaliskan_split-the-tunnel&metric=coverage)](https://sonarcloud.io/summary/new_code?id=bilalcaliskan_split-the-tunnel)
[![Release](https://img.shields.io/github/release/bilalcaliskan/split-the-tunnel.svg)](https://github.com/bilalcaliskan/split-the-tunnel/releases/latest)
[![Go version](https://img.shields.io/github/go-mod/go-version/bilalcaliskan/split-the-tunnel)](https://github.com/bilalcaliskan/split-the-tunnel)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

## Required Steps
- Single command is mostly enough to prepare project, it will prompt you with some questions about your new project:
```shell
$ make -s prepare-initial-project
```
## Overview
`split-the-tunnel` is a daemon that runs on Linux hosts. It is designed to add domains that bypass VPN, effectively creating a split tunnel. This allows for more efficient use of network resources and can improve network performance.

## Additional nice-to-have steps
- If you want to build and publish Docker image:
- Ensure `DOCKER_USERNAME` has been added as **repository secret on GitHub**
- Ensure `DOCKER_PASSWORD` has been added as **repository secret on GitHub**
- Uncomment **line 145** to **line 152** in [.github/workflows/push.yml](.github/workflows/push.yml)
- Uncomment **line 32** to **line 50** in [build/package/.goreleaser.yaml](build/package/.goreleaser.yaml)
- If you want to enable https://sonarcloud.io/ integration:
- Ensure your created repository from that template has been added to https://sonarcloud.io/
- Ensure `SONAR_TOKEN` has been added as **repository secret** on GitHub
- Ensure `SONAR_TOKEN` has been added as **dependabot secret** on GitHub
- Uncomment **line 69** to **line 94** in [.github/workflows/pr.yml](.github/workflows/pr.yml)
- Uncomment **line 116** in [.github/workflows/push.yml](.github/workflows/push.yml)
- Uncomment **line 66** to **line 91** in [.github/workflows/push.yml](.github/workflows/push.yml)
- If you want to create banner:
- Generate a banner from [here](https://devops.datenkollektiv.de/banner.txt/index.html) and place it inside of [build/ci](build/ci) directory into a file **banner.txt**
- Uncomment **line 18** and **line 35** to **line 38** in [cmd/root.go](cmd/root.go)
- Run `go get -u github.com/dimiro1/banner`
- If you want to release as Homebrew Formula:
- At first, you must have a **formula repository** like https://github.com/bilalcaliskan/homebrew-tap
- Create an access token on account that has **formula repository** mentioned above item and ensure that token is added as`TAP_GITHUB_TOKEN` **repository secret** on GitHub
- Uncomment **line 165** in [.github/workflows/push.yml](.github/workflows/push.yml)
- Uncomment **line 70** to **line 80** in [build/package/.goreleaser.yaml](build/package/.goreleaser.yaml)
- If you want to mock your interfaces with [mockery](https://github.com/vektra/mockery):
- Add `generate-mocks` target as a prerequisite to all uncommented targets starting with `test` in [Makefile](Makefile)
## Features
- Runs as a daemon on Linux hosts
- Capable of adding domains to bypass VPN
- Creates a split tunnel for efficient network usage

## Used Libraries
- [spf13/cobra](https://github.com/spf13/cobra)
- [rs/zerolog](https://github.com/rs/zerolog)
## Installation
To install `split-the-tunnel`, you can download the latest binary from the [releases page](https://github.com/bilalcaliskan/split-the-tunnel/releases/latest) and add it to your PATH.

## Usage
After installing `split-the-tunnel`, you can start the daemon with the following command:

```shell
$ split-the-tunnel start
$ split-the-tunnel add --domain example.com
```

## Development
This project requires below tools while developing:
- [Golang 1.21](https://golang.org/doc/go1.21)
- [pre-commit](https://pre-commit.com/)
- [golangci-lint](https://golangci-lint.run/usage/install/) - required by [pre-commit](https://pre-commit.com/)
- [gocyclo](https://github.com/fzipp/gocyclo) - required by [pre-commit](https://pre-commit.com/)

After you installed [pre-commit](https://pre-commit.com/), simply run below command to prepare your development environment:
After you installed [pre-commit](https://pre-commit.com/) and the rest, simply run below command to prepare your
development environment:
```shell
$ make pre-commit-setup
```
12 changes: 4 additions & 8 deletions build/ci/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
sonar.projectKey=bilalcaliskan_golang-cli-template
sonar.projectKey=bilalcaliskan_split-the-tunnel
sonar.organization=bilalcaliskan-github

# This is the name and version displayed in the SonarCloud UI.
# sonar.projectName=golang-cli-template
# sonar.projectVersion=1.0

sonar.sources=.
sonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/*,build/package/Dockerfile
sonar.exclusions=**/*_test.go,**/vendor/**,**/testdata/*
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**
sonar.test.exclusions=**/vendor/**,**/mock*
sonar.go.coverage.reportPaths=/github/workspace/coverage.txt
sonar.coverage.exclusions=main.go
sonar.coverage.exclusions=main.go,**/mock*
48 changes: 12 additions & 36 deletions build/package/.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
---
project_name: golang-cli-template
project_name: split-the-tunnel

variables:
versionDir: internal/version
module: github.com/bilalcaliskan/{{ .ProjectName }}

env:
- CGO_ENABLED=0
- GO111MODULE=auto
# - VERSION_DIR=internal/version
# - MODULE=github.com/bilalcaliskan/{{ .ProjectName }}

before:
hooks:
Expand All @@ -17,9 +23,11 @@ builds:
- darwin
goarch:
- amd64
binary: golang-cli-template
binary: "{{ .ProjectName }}"
ldflags:
- -s -w -X github.com/bilalcaliskan/golang-cli-template/internal/version.gitVersion={{ .Version }} -X github.com/bilalcaliskan/golang-cli-template/internal/version.gitCommit={{ .ShortCommit }} -X github.com/bilalcaliskan/golang-cli-template/internal/version.buildDate={{ .CommitDate }}
- -s -w -X {{ .Var.module }}/{{ .Var.versionDir }}.gitVersion={{ .Version }}
- -s -w -X {{ .Var.module }}/{{ .Var.versionDir }}.gitCommit={{ .ShortCommit }}
- -s -w -X {{ .Var.module }}/{{ .Var.versionDir }}.buildDate={{ .CommitDate }}
main: ./main.go

archives:
Expand All @@ -29,30 +37,10 @@ archives:
name_template: >-
{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}
#dockers:
# - image_templates:
# - "docker.io/bilalcaliskan/{{ .ProjectName }}:{{ .Version }}"
# - "docker.io/bilalcaliskan/{{ .ProjectName }}:latest"
# dockerfile: build/package/Dockerfile.goreleaser
# goos: linux
# goarch: amd64
# use: docker
# build_flag_templates:
# - --pull
# - --platform=linux/amd64
# - --label=org.opencontainers.image.title={{ .ProjectName }}
# - --label=org.opencontainers.image.description={{ .ProjectName }}
# - --label=org.opencontainers.image.url=https://github.com/bilalcaliskan/golang-cli-template
# - --label=org.opencontainers.image.source=https://github.com/bilalcaliskan/golang-cli-template
# - --label=org.opencontainers.image.version={{ .Version }}
# - --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
# - --label=org.opencontainers.image.revision={{ .FullCommit }}
# - --label=org.opencontainers.image.licenses=Apache

release:
github:
owner: bilalcaliskan
name: golang-cli-template
name: "{{ .ProjectName }}"

changelog:
sort: asc
Expand All @@ -66,15 +54,3 @@ changelog:
- 'README'
- '^Merge branch'
- '^Merge pull request'

#brews:
# - name: golang-cli-template
# tap:
# owner: bilalcaliskan
# name: homebrew-tap
# token: "{{ .Env.TAP_GITHUB_TOKEN }}"
# folder: Formula
# goarm: 6
# homepage: https://github.com/bilalcaliskan/golang-cli-template
# license: apache-2.0
# description: golang-cli-template does something
6 changes: 0 additions & 6 deletions build/package/Dockerfile.goreleaser

This file was deleted.

Loading

0 comments on commit 5c3cbbf

Please sign in to comment.