Skip to content

Commit

Permalink
update github action trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunop committed Sep 29, 2024
1 parent a5c0fa3 commit 29f30df
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 16 deletions.
67 changes: 58 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: golangci-lint

on:
push:
branches: [main]
branches:
- main
- next/cicd
pull_request:
branches:
- main
Expand All @@ -12,23 +14,70 @@ on:
- "go.sum"
- "**.go"

env:
GO_VERSION: '1.23'

jobs:
go-static-checks:
lint-and-test:
# Only run if push to main or not previously run in a pull request
if: |
github.event_name == 'push' &&
(
github.event.pull_request.head.repo.full_name != github.repository ||
github.event.pull_request.merged != true
) ||
github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- name: Checkout code
uses: actions/checkout@v4

- name: Setup go
uses: actions/setup-go@v5
with:
go-version: 1.23
go-version: ${{ env.GO_VERSION }}
check-latest: true
cache: true
cache: false

# Cache Go modules to improve build time.
- name: Cache Go Modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# Verify go.mod and go.sum are tidy.
- name: Verify go.mod is tidy
run: |
go mod tidy -go=1.23
git diff --exit-code
cd src
go mod tidy -go=${{ env.GO_VERSION }}
git diff --exit-code go.sum
git diff --exit-code go.mod
# Due to poor unit testing, we comment out it.
#
# Run unit tests.
# - name: Run unit tests
# run: |
# go test ./... -v -race -coverprofile=coverage.out
# env:
# GOFLAGS: "-mod=readonly"

# Upload code coverage report.
# - name: Upload Coverage Report
# uses: actions/upload-artifact@v3
# with:
# name: coverage-report
# path: coverage.out

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61.0
args: --verbose --timeout=3m
args: --verbose --timeout=3m --config=.golangci.yaml ./src/
skip-cache: true
15 changes: 9 additions & 6 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ issues:

linters-settings:
goimports:
# Put imports beginning with prefix after 3rd-party packages.
# Organize imports so that local packages come after third-party packages.
local-prefixes: github.com/NJUPT-SAST/sast-link-backend
revive:
# Default to run all linters so that new rules in the future could automatically be added to the static check.
# Enable all rules but selectively disable ones that are too restrictive.
enable-all-rules: true
rules:
# The following rules are too strict and make coding harder. We do not enable them for now.
- name: file-header
disabled: true
# Rules description see revive documentation: https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
- name: line-length-limit
arguments: [120] # Set a reasonable line length limit
# Disable other rules that are too strict.
- name: file-header
disabled: true
- name: function-length
disabled: true
Expand Down Expand Up @@ -73,14 +74,16 @@ linters-settings:
- name: max-control-nesting
disabled: true
gocritic:
# Rules description see gocritic documentation: https://go-critic.com/overview#checkers-from-the-diagnostic-group
disabled-checks:
- ifElseChain
govet:
settings:
printf: # The name of the analyzer, run `go tool vet help` to see the list of all analyzers
funcs: # Run `go tool vet help printf` to see the full configuration of `printf`.
- common.Errorf
- common.Errorf # Treat common.Errorf as a printf-style function.
enable-all: true
# Rules description see govet documentation: https://pkg.go.dev/github.com/golangci/govet
disable:
- fieldalignment
- shadow
2 changes: 1 addition & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/pflag v1.0.5
github.com/subosito/gotenv v1.4.2 // indirect
)

Expand Down

0 comments on commit 29f30df

Please sign in to comment.