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

adds github actions #12

Merged
merged 3 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
74 changes: 74 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -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}}"
20 changes: 20 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -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/...
32 changes: 32 additions & 0 deletions .github/workflows/mongodb_tests.yml
Original file line number Diff line number Diff line change
@@ -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/...
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

dist/
42 changes: 42 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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'

2 changes: 2 additions & 0 deletions pkg/db/mongox/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 15 additions & 14 deletions test/shell_test/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand Down