Skip to content

Commit

Permalink
Add all build, test, codeql, and linter github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
erikostien-pingidentity committed Jan 26, 2024
1 parent 26253fa commit 17f7033
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 56 deletions.
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See GitHub's docs for more information on this file:
# https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"

# Maintain dependencies for Go modules
- package-ecosystem: "gomod"
directory: "/"
schedule:
# Check for updates to Go modules every week
interval: "weekly"
98 changes: 98 additions & 0 deletions .github/workflows/code-check-and-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Code Check and Acceptance Tests

on:
push:
branches: [ "main", "go-cli" ]
pull_request:
paths:
- '.github/workflows/code-check-and-tests.yaml'
- '**.go'
- 'go.mod'
- 'go.sum'
- '.golangci.yml'
schedule:
- cron: '44 8 * * 6'

permissions:
contents: read

jobs:
# Ensure the project can build first
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- name: Get dependencies
run: |
go mod tidy
git diff --compact-summary --exit-code || \
(echo; echo "Unexpected difference after 'go mod tidy'. Run 'go mod tidy' command and commit."; exit 1)
- name: Build
run: |
make install
fmt:
name: go fmt
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- run: |
if [ "$(go fmt ./... | wc -l)" -gt 0 ]; then
echo "::error::'go fmt' found required formatting changes. Run 'make fmt' on your branch."
exit 1;
fi
vet:
name: go vet
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- run: make vet
lint:
name: golangcli-lint
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- run: make golangcilint
importfmt:
name: importfmt
needs: [build]
runs-on:ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- run: make importfmtlint
acceptance:
name: Tests
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- run:
make test
83 changes: 83 additions & 0 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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", "go-cli" ]
pull_request:
paths:
- '.github/workflows/codeql.yaml'
- '**.go'
- 'go.mod'
- 'go.sum'
schedule:
- cron: '44 8 * * 6'

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

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
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@v3

# ℹ️ 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@v3
with:
category: "/language:${{matrix.language}}"
56 changes: 0 additions & 56 deletions .github/workflows/golangci-lint.yml

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/gosec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Run Gosec
on:
push:
branches: [ "main", "go-cli" ]
pull_request:
paths:
- '.github/workflows/codeql.yaml'
- '**.go'
- 'go.mod'
- 'go.sum'
schedule:
- cron: '44 8 * * 6'
jobs:
tests:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout Source
uses: actions/checkout@v3
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: ./...
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
SHELL := /bin/bash

.PHONY: install fmt vet test devchecknotest devcheck golangcilint importfmtlint

default: install

install:
go mod tidy
go install .

fmt:
go fmt ./...

vet:
go vet ./...

test:
go test -parallel=4 ./...

devchecknotest: install golangcilint importfmtlint

devcheck: devchecknotest test

golangcilint:
go run github.com/golangci/golangci-lint/cmd/golangci-lint run --timeout 10m ./...

importfmtlint:
go run github.com/pavius/impi/cmd/impi --local . --scheme stdThirdPartyLocal ./...

0 comments on commit 17f7033

Please sign in to comment.