Skip to content

Commit

Permalink
Merge pull request #9 from molu8bits/feature/ci-actions
Browse files Browse the repository at this point in the history
Feature/ci actions
  • Loading branch information
molu8bits authored May 26, 2023
2 parents 0bc4b3b + 64e0e68 commit bf7b92c
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 0 deletions.
166 changes: 166 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
name: CI

on:
push:
branches:
- master
- develop
- "feature/ci-actions"
pull_request:
types: [opened, synchronize, reopened]

jobs:
Builds:
runs-on: ubuntu-latest
steps:

- name: Check out repository
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: go build -v

- name: Test
run: |
go test -coverprofile=./cov-report.out ./...
# go tool cover -html=cov-report.out -o coverage-report.html
go test -race -coverprofile=coverage.out -covermode=atomic
- name: Cache test coverage report
uses: actions/cache@v3
id: restore-test-coverage-report
with:
path: ./cov-report.out
key: ${{ github.sha }}

Static-Check:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x

# Generate mocks
- name: Generate mocks
run: go generate ./...

- name: Static Code Analysis
uses: golangci/golangci-lint-action@v3
with:
skip-cache: true
skip-pkg-cache: true
skip-build-cache: true
args: |
--timeout 5m --out-${NO_FUTURE}format checkstyle:golangci-report.xml --issues-exit-code 0 --enable errcheck,gosimple,govet,ineffassign,staticcheck,typecheck,unused,gocritic,asasalint,asciicheck,errchkjson,exportloopref,forcetypeassert,makezero,nilerr,unparam,unconvert,wastedassign,usestdlibvars
# --timeout 5m --out-format checkstyle:golangci-report.xml -issues-exit-code 0

- name: Cache golangci-lint report
uses: actions/cache@v3
id: restore-golangci-lint-report
with:
path: ./golangci-report.xml
key: ${{ github.sha }}

Go-Sec:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x

- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: -no-fail -exclude-dir=\.*test\.* -fmt=sonarqube -out=./gosec-report.json -stdout ./...
# args: -exclude=G204,G301,G302,G304,G306 -exclude-dir=\.*test\.* ./...
# args: -no-fail -exclude-dir=\.*test\.* --verbose sonar -out=./gosec-report.json ./...

- name: Cache gosec report
uses: actions/cache@v3
id: restore-gosec-report
with:
path: ./gosec-report.json
key: ${{ github.sha }}


SonarCloud:
runs-on: ubuntu-latest
needs: [Static-Check, Go-Sec, Builds]
steps:
- name: Checkout Source
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x

- uses: actions/cache@v3
id: restore-gosec-report
with:
path: ./gosec-report.json
key: ${{ github.sha }}

- uses: actions/cache@v3
id: restore-golangci-lint-report
with:
path: ./golangci-report.xml
key: ${{ github.sha }}

- uses: actions/cache@v3
id: restore-test-coverage-report
with:
path: ./cov-report.out
key: ${{ github.sha }}

- name: SonarCloud Scan
uses: SonarSource/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

CodeCov:
runs-on: ubuntu-latest
needs: [Builds]
steps:
- name: Checkout Source
uses: actions/checkout@v3

- uses: actions/cache@v3
id: restore-test-coverage-report
with:
path: ./cov-report.out
key: ${{ github.sha }}

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: cov-report.out
flags: unittests
verbose: true

LegalCheck:
runs-on: ubuntu-latest

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

- name: Run FOSSA scan and upload build data
uses: fossa-contrib/fossa-action@v2
with:
fossa-api-key: ${{ secrets.FOSSA_API_KEY }}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 molu8bits (Lucjan M)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

s3bucket_exporter collects informations about size and object list about all the buckets accessible by user. Was designed to work with ceph, but should work will all S3 compatible endpoints.

## Badges

[![License](https://img.shields.io/github/license/molu8bits/s3bucket_exporter)](/LICENSE)
[![Release](https://img.shields.io/github/release/molu8bits/s3bucket_exporter.svg)](https://github.com/molu8bits/s3bucket_exporter/releases/latest)
[![GitHub Releases Stats of s3bucket_exporter](https://img.shields.io/github/downloads/molu8bits/s3bucket_exporter/total.svg?logo=github)](https://somsubhra.github.io/github-release-stats/?username=molu8bits&repository=s3bucket_exporter)
[![CI](https://github.com/molu8bits/s3bucket_exporter/actions/workflows/ci.yaml/badge.svg?branch=master&event=push)](https://github.com/molu8bits/s3bucket_exporter/actions/workflows/ci.yaml?branch=master&event=push)
[![Frogbot Scan Pull Request](https://github.com/molu8bits/s3bucket_exporter/actions/workflows/frogbot-scan-pr-go.yml/badge.svg)](https://github.com/molu8bits/s3bucket_exporter/actions/workflows/frogbot-scan-pr-go.yml)
[![Scanned by Frogbot](https://raw.github.com/jfrog/frogbot/master/images/frogbot-badge.svg)](https://github.com/jfrog/frogbot#readme)
[![Go Report Card](https://goreportcard.com/badge/github.com/molu8bits/s3bucket_exporter)](https://goreportcard.com/report/github.com/molu8bits/s3bucket_exporter)
![Docker Image Size](https://img.shields.io/docker/image-size/molu8bits/s3bucket_exporter.svg?sort=date)
![Docker Image Version (latest by date):](https://img.shields.io/docker/v/molu8bits/s3bucket_exporter.svg?sort=date)
![Docker Pulls](https://img.shields.io/docker/pulls/molu8bits/s3bucket_exporter.svg)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=s3bucket_exporter&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=s3bucket_exporter)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=s3bucket_exporter&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=s3bucket_exporter)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=s3bucket_exporter&metric=coverage)](https://sonarcloud.io/summary/new_code?id=s3bucket_exporter)
[![codecov](https://codecov.io/github/molu8bits/s3bucket_exporter/branch/master/graph/badge.svg?token=6KIJFNB8WG)](https://codecov.io/github/molu8bits/s3bucket_exporter)

[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B20660%2Fgithub.com%2Fmolu8bits%2Fs3bucket_exporter.svg?type=large)](https://app.fossa.com/projects/custom%2B20660%2Fgithub.com%2Fmolu8bits%2Fs3bucket_exporter?ref=badge_large)

## Getting started

Run from command-line:
Expand Down
11 changes: 11 additions & 0 deletions controllers/s3talker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package controllers

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestOfTest(t *testing.T) {
assert.Equal(t, 1, 1)
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ require (
github.com/aws/aws-sdk-go v1.44.271 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.15.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/sirupsen/logrus v1.9.2 // indirect
github.com/stretchr/testify v1.8.3 // indirect
golang.org/x/sys v0.6.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
Expand All @@ -18,6 +19,7 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI=
github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
Expand All @@ -31,6 +33,8 @@ github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand Down Expand Up @@ -70,3 +74,5 @@ google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
20 changes: 20 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sonar.projectKey=s3bucket_exporter
sonar.organization=molu8bits

sonar.issuesReport.html.enable=true
sonar.report.export.path=sonar-report.json
sonar.sources=.
# sonar.sources=**/*.go # wildcards not allowed
sonar.exclusions=**/*_test.go,**/vendor/**,**/*.json,prometheus-vmware-exporter,*report*.*,*-config.yml
sonar.tests=.
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**/vendor/**

sonar.issuesReport.html.enable=true
sonar.report.export.path=report.json

# Change the host.url to point to the
# sonarqube server (default localhost)
sonar.externalIssuesReportPaths=gosec-report.json
sonar.go.golangci-lint.reportPaths=golangci-report.xml
sonar.go.coverage.reportPaths=cov-report.out

0 comments on commit bf7b92c

Please sign in to comment.