diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..f58785b --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,74 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "main" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "main" ] + schedule: + - cron: '32 12 * * 3' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 0000000..fe461b4 --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,20 @@ +# Dependency Review Action +# +# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging. +# +# Source repository: https://github.com/actions/dependency-review-action +# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement +name: 'Dependency Review' +on: [pull_request] + +permissions: + contents: read + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: 'Checkout Repository' + uses: actions/checkout@v3 + - name: 'Dependency Review' + uses: actions/dependency-review-action@v2 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..dfa7a26 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,33 @@ +name: Go Build and test + +on: + push: + pull_request: + workflow_dispatch: + + +jobs: + build: + name: Test Builds + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest] + + steps: + - name: Setup Golang + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Checkout repo + uses: actions/checkout@v3 + + + - name: Build talosplus + run: go build . + working-directory: cmd/talosplus/ + + - name: Unit Tests + run: go test ./test/... \ No newline at end of file diff --git a/.github/workflows/mongodb_tests.yml b/.github/workflows/mongodb_tests.yml new file mode 100644 index 0000000..bdf225c --- /dev/null +++ b/.github/workflows/mongodb_tests.yml @@ -0,0 +1,32 @@ +name: Run MongoDB tests + +on: + push: + pull_request: + workflow_dispatch: + +env: + RUN_MONGODB_TEST: true + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Setup Golang + uses: actions/setup-go@v3 + with: + go-version: 1.18 + + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Start MongoDB + uses: supercharge/mongodb-github-action@1.8.0 + + - name: Build talosplus + run: go build . + working-directory: cmd/talosplus/ + + - name: Unit Tests + run: go test ./test/... \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7384f52 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +name: Release nestle binary + +on: + push: + # Only against tags + tags: + - '*' + +permissions: + contents: write + packages: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + + steps: + - name: Setup Git repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + + - + name: Force Fetch Tags + run: git fetch --force --tags + + - + name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - + name: Setup Goreleaser + uses: goreleaser/goreleaser-action@v3 + with: + args: "release --rm-dist" + version: latest + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cde0123 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..f4d702f --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,42 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + + id: talosplus + main: ./cmd/talosplus/ + binary: talosplus + + goos: + - linux + - windows + - darwin + + goarch: [amd64,"386",arm,arm64] + ignore: + - goos: darwin + goarch: "386" + - goos: windows + goarch: arm + - goos: windows + goarch: arm64 + +archives: + - format: zip + replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 + +checksum: + algorithm: sha256 + name_template: 'checksums.txt' + diff --git a/pkg/db/mongox/mongodb.go b/pkg/db/mongox/mongodb.go index fb36f23..e566b99 100644 --- a/pkg/db/mongox/mongodb.go +++ b/pkg/db/mongox/mongodb.go @@ -63,6 +63,8 @@ func (m *Provider) open() error { if m.MongoDB.CollectionName == "" { return fmt.Errorf("mongoDB collection name missing") + } else { + m.GetCollection(m.MongoDB.CollectionName) } return nil diff --git a/test/shell_test/simple_test.go b/test/shell_test/simple_test.go index 5979862..62f08a4 100644 --- a/test/shell_test/simple_test.go +++ b/test/shell_test/simple_test.go @@ -5,7 +5,6 @@ import ( "strings" "testing" - "github.com/tarunKoyalwar/talosplus/pkg/alerts" "github.com/tarunKoyalwar/talosplus/pkg/db" "github.com/tarunKoyalwar/talosplus/pkg/shell" "github.com/tarunKoyalwar/talosplus/pkg/stringutils" @@ -85,24 +84,24 @@ func Test_CMD_Export(t *testing.T) { } } -func Test_Alerts(t *testing.T) { - id := os.Getenv("DISCORD_WID") - tok := os.Getenv("DISCORD_WTOKEN") +// func Test_Alerts(t *testing.T) { +// id := os.Getenv("DISCORD_WID") +// tok := os.Getenv("DISCORD_WTOKEN") - alerts.Alert = alerts.NewDiscordHook(id, tok) +// alerts.Alert = alerts.NewDiscordHook(id, tok) - alerts.Alert.Title = "Testing" +// alerts.Alert.Title = "Testing" - g := shell.NewCMDWrap("echo 'Hello Luci!!' #notify{Test Output}", "") - g.Process() +// g := shell.NewCMDWrap("echo 'Hello Luci!!' #notify{Test Output}", "") +// g.Process() - if err := g.Execute(); err != nil { - HandleErrors(err, t, "Failed to Run Command %v\n returned %v", g.Raw, err) - } +// if err := g.Execute(); err != nil { +// HandleErrors(err, t, "Failed to Run Command %v\n returned %v", g.Raw, err) +// } - // g.Export() +// // g.Export() -} +// } func HandleErrors(er error, t *testing.T, msg string, a ...any) { if er != nil { @@ -113,10 +112,12 @@ func HandleErrors(er error, t *testing.T, msg string, a ...any) { } func TestMain(m *testing.M) { - val := os.Getenv("ENABLE_MONGODB_TEST") + val := os.Getenv("RUN_MONGODB_TEST") if val == "" { db.UseBBoltDB(os.TempDir(), stringutils.RandomString(6)+".db", "Complex_test") + } else { + db.UseMongoDB("", stringutils.RandomString(6)+".db", "Complex_test") } m.Run()