From 4493b18e41941b5fb8abcea37f1bd6530ab1a792 Mon Sep 17 00:00:00 2001 From: bilalcaliskan Date: Sun, 7 Jan 2024 23:38:06 +0300 Subject: [PATCH] feat: initial commit --- .github/workflows/pr.yml | 64 +++++++++++------------- .github/workflows/push.yml | 75 ++++++++++++----------------- build/ci/sonar-project.properties | 12 ++--- build/package/.goreleaser.yaml | 38 ++------------- build/package/Dockerfile.goreleaser | 6 --- cmd/foo/foo.go | 7 ++- cmd/foo/options/options.go | 2 +- cmd/root/root.go | 10 ++-- go.mod | 2 +- main.go | 2 +- 10 files changed, 77 insertions(+), 141 deletions(-) delete mode 100644 build/package/Dockerfile.goreleaser diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8747e67..85f049e 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -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 @@ -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 @@ -106,5 +100,5 @@ jobs: with: go-version-file: "go.mod" cache: true - - name: Test + - name: Build run: make -s build diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 046c38a..3b9753f 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -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 @@ -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 @@ -103,7 +97,7 @@ jobs: with: go-version-file: "go.mod" cache: true - - name: Test + - name: Build run: make -s build tag: @@ -113,7 +107,7 @@ jobs: - test - codeql - staticcheck -# - sonarcloud + - sonarcloud - build steps: - name: Checkout @@ -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: @@ -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 }} diff --git a/build/ci/sonar-project.properties b/build/ci/sonar-project.properties index 2eda823..874b454 100644 --- a/build/ci/sonar-project.properties +++ b/build/ci/sonar-project.properties @@ -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* diff --git a/build/package/.goreleaser.yaml b/build/package/.goreleaser.yaml index beed7f5..9b625f8 100644 --- a/build/package/.goreleaser.yaml +++ b/build/package/.goreleaser.yaml @@ -1,5 +1,5 @@ --- -project_name: golang-cli-template +project_name: split-the-tunnel env: - CGO_ENABLED=0 @@ -19,7 +19,7 @@ builds: - amd64 binary: golang-cli-template 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 github.com/bilalcaliskan/split-the-tunnel/internal/version.gitVersion={{ .Version }} -X github.com/bilalcaliskan/split-the-tunnel/internal/version.gitCommit={{ .ShortCommit }} -X github.com/bilalcaliskan/split-the-tunnel/internal/version.buildDate={{ .CommitDate }} main: ./main.go archives: @@ -29,30 +29,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: split-the-tunnel changelog: sort: asc @@ -66,15 +46,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 diff --git a/build/package/Dockerfile.goreleaser b/build/package/Dockerfile.goreleaser deleted file mode 100644 index c80fdfa..0000000 --- a/build/package/Dockerfile.goreleaser +++ /dev/null @@ -1,6 +0,0 @@ -FROM gcr.io/distroless/static:nonroot-amd64 - -ADD golang-cli-template /usr/local/bin/golang-cli-template - -USER nonroot -ENTRYPOINT ["golang-cli-template"] diff --git a/cmd/foo/foo.go b/cmd/foo/foo.go index d5e7f81..8fb7675 100644 --- a/cmd/foo/foo.go +++ b/cmd/foo/foo.go @@ -1,11 +1,11 @@ package foo import ( - "github.com/bilalcaliskan/golang-cli-template/cmd/foo/options" + "github.com/bilalcaliskan/split-the-tunnel/cmd/foo/options" - rootopts "github.com/bilalcaliskan/golang-cli-template/cmd/root/options" + rootopts "github.com/bilalcaliskan/split-the-tunnel/cmd/root/options" - "github.com/bilalcaliskan/golang-cli-template/internal/logging" + "github.com/bilalcaliskan/split-the-tunnel/internal/logging" "github.com/rs/zerolog" "github.com/spf13/cobra" ) @@ -33,7 +33,6 @@ var ( return nil }, RunE: func(cmd *cobra.Command, args []string) error { - logger.Info().Str("rootOptsKey", fooOpts.RootOptions.Key).Msg("hello guys") return nil }, diff --git a/cmd/foo/options/options.go b/cmd/foo/options/options.go index 1228109..b271a49 100644 --- a/cmd/foo/options/options.go +++ b/cmd/foo/options/options.go @@ -1,7 +1,7 @@ package options import ( - "github.com/bilalcaliskan/golang-cli-template/cmd/root/options" + "github.com/bilalcaliskan/split-the-tunnel/cmd/root/options" "github.com/spf13/cobra" ) diff --git a/cmd/root/root.go b/cmd/root/root.go index cc0d585..aee4db1 100644 --- a/cmd/root/root.go +++ b/cmd/root/root.go @@ -4,11 +4,11 @@ import ( "context" "os" - "github.com/bilalcaliskan/golang-cli-template/cmd/foo" - "github.com/bilalcaliskan/golang-cli-template/cmd/root/options" + "github.com/bilalcaliskan/split-the-tunnel/cmd/foo" + "github.com/bilalcaliskan/split-the-tunnel/cmd/root/options" - "github.com/bilalcaliskan/golang-cli-template/internal/logging" - "github.com/bilalcaliskan/golang-cli-template/internal/version" + "github.com/bilalcaliskan/split-the-tunnel/internal/logging" + "github.com/bilalcaliskan/split-the-tunnel/internal/version" "github.com/spf13/cobra" ) @@ -27,7 +27,7 @@ func init() { // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ - Use: "golang-cli-template", + Use: "split-the-tunnel", Short: "", Long: ``, Version: ver.GitVersion, diff --git a/go.mod b/go.mod index 92ee06b..b0ca91f 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/bilalcaliskan/golang-cli-template +module github.com/bilalcaliskan/split-the-tunnel go 1.21 diff --git a/main.go b/main.go index d2efb5d..a6c1f4e 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,7 @@ Copyright © 2022 bilalcaliskan bilalcaliskan@protonmail.com package main import ( - "github.com/bilalcaliskan/golang-cli-template/cmd/root" + "github.com/bilalcaliskan/split-the-tunnel/cmd/root" ) func main() {