Skip to content

Commit

Permalink
ci: 💚 consolidate github actions workflows (#47)
Browse files Browse the repository at this point in the history
- make all main jobs as reusable workflows
- update used actions versions
- use golangci-lint action for linting
  • Loading branch information
zoido authored Dec 10, 2023
1 parent 6f217e9 commit ce48d06
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 139 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/go-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "Go: Build"
on:
workflow_call: {}

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
cache: false
go-version-file: go.mod


- id: go-cache-paths
run: |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
mkdir -p "$(go env GOMODCACHE)"
mkdir -p "$(go env GOCACHE)"
- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-gobuild-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-gobuild-build
- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-gomod-build-${{ hashFiles('**/go.sum') }}

- run: |
go build -v .
20 changes: 20 additions & 0 deletions .github/workflows/go-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Go: Lint"
on:
workflow_call: {}

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
cache: false
go-version-file: go.mod


- name: Run golangci-lint
id: golangci-lint
uses: golangci/golangci-lint-action@v3
51 changes: 51 additions & 0 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Go: Test"
on:
workflow_call: {}

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
cache: false
go-version-file: go.mod


- name: Determine Go Cache Paths
id: go-cache-paths
run: |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
mkdir -p "$(go env GOMODCACHE)"
mkdir -p "$(go env GOCACHE)"
- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-gobuild-test-${{ github.sha }}
restore-keys: |
${{ runner.os }}-gobuild-test
- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-gomod-test-${{ hashFiles('**/go.sum') }}

- run: |
go test -v \
-coverprofile=coverage.txt \
-covermode=atomic \
-coverpkg=./... \
./...
- name: Collect Code Coverage
uses: codecov/codecov-action@v2
with:
file: ./coverage.txt
20 changes: 20 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Go
on:
push:
branches: [main]
pull_request:

jobs:
lint:
name: "Go: Lint"
uses: ./.github/workflows/go-lint.yaml

build:
name: "Go: Build"
uses: ./.github/workflows/go-build.yaml

test:
name: "Go: Test"
uses: ./.github/workflows/go-test.yaml

secrets: inherit
139 changes: 0 additions & 139 deletions .github/workflows/go.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/markdown-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "Markdown: Lint"
on:
workflow_call: {}

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: markdownlint
uses: nosborn/github-action-markdown-cli@v2
with:
files: .
10 changes: 10 additions & 0 deletions .github/workflows/markdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Markdown
on:
push:
branches: [main]
pull_request:

jobs:
lint:
name: "Markdown: Lint"
uses: ./.github/workflows/markdown-lint.yaml
54 changes: 54 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
linters:
# Disable all default linters and enable only revive and formatters before
# new findings by default linters are addressed.
disable-all: true
enable:
- gofumpt
- goimports
- revive

issues:
exclude-use-default: false

linters-settings:
revive:
confidence: 0.8
ignore-generated-header: false
severity: error

rules:
- name: blank-imports
- name: confusing-naming
- name: confusing-results
- name: context-as-argument
- name: context-keys-type
- name: deep-exit
- name: dot-imports
- name: empty-block
- name: empty-lines
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: get-return
- name: if-return
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: modifies-parameter
- name: modifies-value-receiver
- name: package-comments
- name: range
- name: receiver-naming
- name: redefines-builtin-id
- name: struct-tag
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unnecessary-stmt
- name: unreachable-code
- name: unused-parameter
- name: unused-receiver
- name: var-declaration
- name: var-naming

0 comments on commit ce48d06

Please sign in to comment.