Skip to content

Instantly share code, notes, and snippets.

@flowchartsman
Created March 16, 2023 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flowchartsman/26b5cb60b6022ddb2b009923e2db9100 to your computer and use it in GitHub Desktop.
Save flowchartsman/26b5cb60b6022ddb2b009923e2db9100 to your computer and use it in GitHub Desktop.
Golang testing and github workflow w/ coverage, dependencies and badges
version: 2
updates:
- package-ecosystem: github-actions
directory: /
labels:
- dependencies
- actions
- Skip Changelog
schedule:
interval: weekly
day: sunday
- package-ecosystem: gomod
directory: /
labels:
- dependencies
- go
- Skip Changelog
schedule:
interval: weekly
day: sunday
# - package-ecosystem: docker
# directory: /<docker directory>
# labels:
# - dependencies
# - docker
# - Skip Changelog
# schedule:
# interval: weekly
# day: sunday
# Note: to ensure coverage is only pushed once, you need to constrain on one matrix combination.
name: Go Workflows
on:
push:
branches:
- master
pull_request:
workflow_dispatch:
jobs:
gotest:
name: Go
runs-on: ${{ matrix.os }}
env:
CGO_ENABLED: 0
strategy:
matrix:
go-version: [ "1.16", "1.18", "1.20", "1.x" ]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Code checkout
uses: actions/checkout@v3
- name: Cache Go modules
uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ matrix.go-version }}-go-
- name: Test
run: go test ./...
#run: make test
- name: Update Coverage
uses: ncruces/go-coverage-report@main
if: |
matrix.os == 'ubuntu-latest' &&
matrix.go-version == '1.x' &&
github.event_name == 'push'
continue-on-error: true

Go Reference Workflow Status Coverage GoReportCard [//]: # (Keep one of these) License: MIT License License License: GPL v3 License: LGPL v3 License: AGPL v3

- Enabling Coverage
- You need a wiki, so create at least one page. If it doesn't exist, just accept the "Welcome!..." default.
- Give workflows read/write permissions:
- Settings -> General -> Workflow permissions -> Read and write permissions -> [Save]
- Enablint Dependabot
- Settings -> Security -> Code security and analysis ->
-> Dependabot security updates [Enable]
-> Dependabot version updates [Enable]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment