Skip to content

Commit

Permalink
Introduce static code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Kovacs committed Jan 3, 2024
1 parent 7a4b2e5 commit ce33402
Show file tree
Hide file tree
Showing 13 changed files with 584 additions and 104 deletions.
89 changes: 88 additions & 1 deletion .github/workflows/build_test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,31 @@ on:
pull_request:
branches: [ "main" ]

jobs:
permissions:
contents: read
pull-requests: read
actions: read

concurrency:
group: build-test-ci-${{ github.ref }}-1
cancel-in-progress: true

jobs:
go-build-test:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
proxy.golang.org:443
sum.golang.org:443
objects.githubusercontent.com:443
- uses: actions/checkout@v4

- name: Set up Go
Expand All @@ -24,9 +44,76 @@ jobs:
- name: Test
run: make test

go-analyse:
needs: go-build-test
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
proxy.golang.org:443
sum.golang.org:443
objects.githubusercontent.com:443
registry-1.docker.io:443
vuln.go.dev:443
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 'stable'

- name: Docker cache
uses: ScribeMD/[email protected]
with:
key: docker-${{ runner.os }}-${{ hashFiles('Makefile') }}}

- name: Lint
run: make lint

- name: Gosec
run: make gosec

# Retry is a workaround, because sometimes nilaway randomly killed.
- uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 3
command: make nilcheck

- name: Vulncheck
run: make vulncheck

docker-build:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
proxy.golang.org:443
sum.golang.org:443
objects.githubusercontent.com:443
registry-1.docker.io:443
auth.docker.io:443
gcr.io:443
- uses: actions/checkout@v4

- name: Docker cache
uses: ScribeMD/[email protected]
with:
key: docker-${{ runner.os }}-${{ hashFiles('Dockerfile') }}

- name: Build the Docker image
run: make docker-build
69 changes: 69 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: "CodeQL"

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

permissions:
contents: read

concurrency:
group: codeql-${{ github.ref }}-1
cancel-in-progress: true

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false

steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
proxy.golang.org:443
sum.golang.org:443
objects.githubusercontent.com:443
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 'stable'

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
languages: go
# 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

- name: Build
run: make build

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:go"
Loading

0 comments on commit ce33402

Please sign in to comment.