-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from molu8bits/feature/ci-actions
Feature/ci actions
- Loading branch information
Showing
7 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |