Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add github pipeline for go project #13

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions .github/workflows/go_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: Go CI

on:
workflow_call:
inputs:
go-version:
required: true
type: string
os:
required: true
type: string

jobs:
build:
runs-on: ${{ inputs.os }}

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

- name: Set up Go ${{ inputs.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}

- name: Install dependencies
run: go mod tidy

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libx11-dev \
libxext-dev \
libxrender-dev \
libxrandr-dev \
libxtst-dev \
libxt-dev \
libgl1-mesa-dev \
libglu1-mesa-dev \
freeglut3-dev \
libxcursor-dev \
libxinerama-dev \
libxxf86vm-dev

- name: Build
run: go build $(go list ./... | grep -v /internal/ | grep -v /examples/)

- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.os }}-${{ inputs.go-version }}-build
path: .

test:
runs-on: ${{ inputs.os }}
needs: build

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

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
libx11-dev \
libxext-dev \
libxrender-dev \
libxrandr-dev \
libxtst-dev \
libxt-dev \
libgl1-mesa-dev \
libglu1-mesa-dev \
freeglut3-dev \
libxcursor-dev \
libxinerama-dev \
libxxf86vm-dev

- name: Set up Go ${{ inputs.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}

- name: Set up gotestfmt
uses: GoTestTools/gotestfmt-action@v2

- uses: actions/download-artifact@v4
with:
name: ${{ inputs.os }}-${{ inputs.go-version }}-build

- name: Test with Go
run: go test $(go list ./... | grep -v /internal/ | grep -v /examples/) -race -json -v -coverprofile=coverage.txt ./... 2>&1 | tee /tmp/gotest.log | gotestfmt

- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.os }}-${{ inputs.go-version }}-coverage
path: coverage.txt

coverage:
runs-on: ${{ inputs.os }}
needs: test

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

- name: Set up Go ${{ inputs.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}

- uses: actions/download-artifact@v4
with:
name: ${{ inputs.os }}-${{ inputs.go-version }}-coverage

- name: Install gocover-cobertura
run: |
go get github.com/boumenot/gocover-cobertura && go install github.com/boumenot/gocover-cobertura

- name: Convert go coverage to corbetura format
run: gocover-cobertura < coverage.txt > coverage.xml

- name: Generate code coverage report
uses: irongut/[email protected]
with:
filename: coverage.xml
badge: false
fail_below_min: false
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
34 changes: 34 additions & 0 deletions .github/workflows/gosec_security_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Gosec Security Check

on:
workflow_call:
inputs:
go-version:
required: true
type: string

jobs:
gosec-security-analysis:
runs-on: 'ubuntu-latest'
env:
GO111MODULE: on
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}

- name: Install Gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest

- name: Run Gosec Security Scanner
run: |
gosec -exclude=G404 -fmt=sarif -out=gosec-results.sarif ./... || true

- name: Upload SARIF report to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: gosec-results.sarif
24 changes: 24 additions & 0 deletions .github/workflows/master_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Master Workflow

on:
push:
branches: [ main ]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
version-matrix:
strategy:
fail-fast: false
matrix:
os: [ 'ubuntu-latest' ]
go-version: [ '1.23.5' ]
uses: ./.github/workflows/go_ci.yml
with:
go-version: ${{ matrix.go-version }}
os: ${{ matrix.os }}

security-analysis:
uses: ./.github/workflows/gosec_security_check.yml
with:
go-version: '1.23.5'
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Master Workflow](https://github.com/rodd-oss/gomp/actions/workflows/master_workflow.yml/badge.svg?event=push)

# Golang MultiPlayer Game Engine Framework
Modern way to create fullstack multiplayer games using Go.

Expand Down