From 171e0e089d75fb835da944192fa113875e914c0e Mon Sep 17 00:00:00 2001 From: Justin Hammond Date: Wed, 21 May 2025 10:23:41 +0800 Subject: [PATCH] Add GitHub Actions workflows for tests and security scans - Add go-test.yml workflow to run tests on PRs and main branch commits - Configure test coverage reporting - Add CodeQL security analysis workflow for vulnerability detection - Support multiple Go versions in the test matrix --- .github/workflows/codeql-analysis.yml | 38 ++++++++++++++++++ .github/workflows/go-test.yml | 57 +++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/go-test.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..3777772 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,38 @@ +name: "CodeQL Analysis" + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + schedule: + - cron: '0 0 * * 0' # Run once per week at midnight on Sunday + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + security-events: write + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 \ No newline at end of file diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml new file mode 100644 index 0000000..18353dd --- /dev/null +++ b/.github/workflows/go-test.yml @@ -0,0 +1,57 @@ +name: Go Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + name: Run Tests + runs-on: ubuntu-latest + strategy: + matrix: + go-version: ['1.22', '1.23', '1.24'] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + cache: true + + - name: Get dependencies + run: go mod download + + - name: Verify dependencies + run: go mod verify + + - name: Run vet + run: go vet ./... + + - name: Run tests with coverage + run: go test -race -coverprofile=coverage.out -covermode=atomic ./... + + - name: Upload coverage report + uses: codecov/codecov-action@v3 + with: + file: ./coverage.out + name: codecov-umbrella + fail_ci_if_error: false + + security-scan: + name: Security Scan + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Run Gosec Security Scanner + uses: securego/gosec@master + with: + args: ./... \ No newline at end of file