Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from dabumana/developer
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
dabumana committed Jul 19, 2023
2 parents c50a115 + 6a8a6cb commit f8e0e34
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 90 deletions.
41 changes: 37 additions & 4 deletions .github/workflows/acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ name: Acceptance

on:
push:
branches: [ "main" ]
branches: [ "main", "developer" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "developer" ]

jobs:
analyze:

codeql-analysis:
name: Analyze
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
runs-on: ${{'ubuntu-latest' || 'macos-latest' || 'windows-latest' }}
permissions:
actions: read
contents: read
Expand All @@ -34,3 +35,35 @@ jobs:
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"

codacy-security-scan:
name: Security Scan
runs-on: ${{'ubuntu-latest' || 'macos-latest' || 'windows-latest' }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@d840f886c4bd4edc059706d09c6a1586111c540b
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
verbose: true
output: results.sarif
format: sarif
gh-code-scanning-compat: true
max-allowed-issues: 2147483647

- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: results.sarif
58 changes: 24 additions & 34 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
name: Integrity
name: Integration

on:
push:
branches: [ "main" ]
branches: [ "main", "developer" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
branches: [ "main", "developer" ]

permissions:
contents: read
actions: read

jobs:
codacy-security-scan:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
name: Codacy Security Scan
runs-on: ubuntu-latest
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout code
uses: actions/checkout@v3

# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
- name: Run Codacy Analysis CLI
uses: codacy/codacy-analysis-cli-action@d840f886c4bd4edc059706d09c6a1586111c540b
build-coverage:
name: Coverage
runs-on: ${{'ubuntu-latest' || 'macos-latest' || 'windows-latest' }}
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
# You can also omit the token and run the tools that support default configurations
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
verbose: true
output: results.sarif
format: sarif
# Adjust severity of non-security issues
gh-code-scanning-compat: true
# Force 0 exit code to allow SARIF file generation
# This will handover control about PR rejection to the GitHub side
max-allowed-issues: 2147483647
go-version: 1.19

# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
uses: github/codeql-action/upload-sarif@v2
- name: Checkout
uses: actions/checkout@v3
with:
sarif_file: results.sarif
fetch-depth: 0
persist-credentials: false

- name: Dependencies
run: sudo apt-get install libcurl4-openssl-dev

- name: Build
run: make build APP=caos

- name: Coverage
run: make test
18 changes: 8 additions & 10 deletions .github/workflows/build.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
name: Build
name: Release

on:
push:
branches:
- main
- developer
pull_request:
branches: ["main"]
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{'ubuntu-latest' || 'macos-latest' || 'windows-latest' }}
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.20

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: false

- uses: go-semantic-release/action@v1
- name: Versioned
id: semantic
uses: go-semantic-release/action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Dependencies
run: sudo apt-get install libcurl4-openssl-dev

- name: Build
run: make build APP=caos
run: make build APP=caos VERSION=${{steps.semantic.outputs.version}}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ src/export*
src/training*
src/.env
src/test/.env
.env
5 changes: 3 additions & 2 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/ce2f44761a6e486999eddd05b749c1be)](https://app.codacy.com/gh/dabumana/caos/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![Maintainability](https://api.codeclimate.com/v1/badges/9bf177949db99d4b2f15/maintainability)](https://codeclimate.com/github/dabumana/caos/maintainability)

[![Build](https://github.com/dabumana/caos/actions/workflows/build.yml/badge.svg)](https://github.com/dabumana/caos/actions/workflows/build.yml)
[![Integrity](https://github.com/dabumana/caos/actions/workflows/integration.yml/badge.svg)](https://github.com/dabumana/caos/actions/workflows/integration.yml)

[![Acceptance](https://github.com/dabumana/caos/actions/workflows/acceptance.yml/badge.svg)](https://github.com/dabumana/caos/actions/workflows/acceptance.yml)
[![Integrity](https://github.com/dabumana/caos/actions/workflows/integration.yml/badge.svg)](https://github.com/dabumana/caos/actions/workflows/integration.yml)
[![Release](https://github.com/dabumana/caos/actions/workflows/release.yml/badge.svg)](https://github.com/dabumana/caos/actions/workflows/release.yml)

### Description :notebook:

Expand Down
7 changes: 3 additions & 4 deletions ci/service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
FROM golang:1.20
FROM golang:1.19

WORKDIR /usr/local/bin
ENV APP_HOME /usr/local/bin/caos

RUN mkdir -p ${APP_HOME}
RUN git clone https://github.com/dabumana/caos ${APP_HOME}
RUN make -C ${APP_HOME}/src build

RUN mv ${APP_HOME}/src/bin/* /usr/local/bin
RUN cp ${APP_HOME}/src/bin/caos/* /usr/local/bin
RUN rm -rf ${APP_HOME}

ENTRYPOINT [ "caos-v.0.0.0" ]
ENTRYPOINT [ "caos" ]
Empty file modified docs/index.rst
100755 → 100644
Empty file.
5 changes: 2 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
APP=caos
VERSION=v.0.0.0
# Configuration path
CONFIG_PATH=./ci/service

build:
build:
make -C ./src clean
make -C ./src build
make -C ./src test
make -C ./src build APP=${APP} VERSION=${VERSION}

clean:
make -C ./src clean
Expand Down
4 changes: 3 additions & 1 deletion src/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Main package
package main

import "caos/handler"
import (
"caos/handler"
)

// Main
func main() {
Expand Down
21 changes: 11 additions & 10 deletions src/makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
APP=caos
VERSION=v.0.0.0
PKG_LIST=$(go list ./... | grep -v /vendor/ | tr '\n' ' ')
VERSION=v0.0.0

benchmark:
go test ./test/... -bench -count 5 -benchmem | tee report/${VERSION}/profile.txt

build:
mkdir bin
mkdir bin/caos
cp .env ./bin/caos
cp -r template ./bin/caos
mkdir report
mkdir report/${VERSION}
go build -o ./bin/caos/${APP}


clean:
go clean
# Remove cache directories
rm -rf 'bin'
rm -rf 'log'
rm -rf 'export'
rm -rf 'report'
rm -rf 'training'
rm -rf '.cookies'
rm -rf 'localCA.key'
rm -rf 'localCA.crt'
rm -rf 'localCA.pem'
rm -rf 'rootCA.pem'
rm -rf 'coverage.out'

coverage:
go test -covermode=count -coverprofile coverage.out ${PKG_LIST}
coverage: benchmark
go test ./test/... -coverprofile=report/${VERSION}/coverage.out -coverpkg ./...

env:
openssl genrsa -out localCA.key 4096
Expand All @@ -35,8 +36,8 @@ env:
run:
./bin/caos/${APP}

test:
go test ./...
test: coverage
go test ./test/...

tidy:
go mod tidy
Expand Down
6 changes: 6 additions & 0 deletions src/resources/asset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package resources

import "embed"

//go:embed template
var Asset embed.FS
2 changes: 2 additions & 0 deletions src/resources/template/profile.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"API_KEY",""
"ZERO_API_KEY",""
File renamed without changes.
43 changes: 32 additions & 11 deletions src/service/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
package service

import (
"caos/model"
"caos/resources"
"caos/service/parameters"
"caos/util"
"context"
"crypto/tls"
"encoding/csv"
"fmt"
"net/http"
"os"

"caos/model"
"caos/service/parameters"
"caos/util"

"github.com/PullRequestInc/go-gpt3"
"github.com/joho/godotenv"
"github.com/spf13/viper"
Expand Down Expand Up @@ -120,10 +120,14 @@ func getKeys() []string {
path := fmt.Sprintf("%v/.env", dir)

file, _ := os.Stat(path)
if file != nil {

key := os.Getenv("API_KEY")
if key != "" {
return getKeyFromEnv()
} else if file != nil {
return getKeyFromLocal()
}
return getKeyFromEnv()
return getKeyFromInternal()
}

// getKeyFromEnv - Get environment keys
Expand Down Expand Up @@ -170,15 +174,32 @@ func getKeyFromLocal() []string {
return keys
}

// getKeyFromInternal - Get the currect key stablished on the internal .env file
func getKeyFromInternal() []string {
var keys []string

file, _ := resources.Asset.Open("template/profile.csv")
reader := csv.NewReader(file)
data, _ := reader.ReadAll()

for _, j := range data {
for k, l := range j {
if k == 1 {
keys = append(keys, l)
}
}
}

keys = append(keys, "", "")
return keys
}

// getTemplateFromLocal - Get templates on local dir
func getTemplateFromLocal() ([]string, []string) {
var index []string
var context []string

dir, _ := os.Getwd()
path := fmt.Sprintf("%v/template/role.csv", dir)

file, _ := os.Open(path)
file, _ := resources.Asset.Open("template/role.csv")
reader := csv.NewReader(file)
data, _ := reader.ReadAll()

Expand Down Expand Up @@ -238,7 +259,7 @@ func (c *Agent) SetTemplateParameters(promptContext []string) model.TemplateProp

// SetTemplate - Conversion human-ai roles
func (c *Agent) SetTemplate(context string, input string) []string {
if context == "" {
if context == "" && len(c.templateCtx) > 0 {
context = c.templateCtx[c.preferences.Template]
}

Expand Down

0 comments on commit f8e0e34

Please sign in to comment.