From 0d7ebac31ec56fcdf1d87470e1bfab5377124655 Mon Sep 17 00:00:00 2001 From: Arnoldas Grigutis Date: Thu, 11 Jul 2024 14:41:46 +0300 Subject: [PATCH] Add golangci-lint (#17) --- .github/workflows/.golangci.yml | 17 ++++++++++++++ .github/workflows/golangci-lint.yml | 35 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/.golangci.yml create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/.golangci.yml b/.github/workflows/.golangci.yml new file mode 100644 index 0000000..a0c3d25 --- /dev/null +++ b/.github/workflows/.golangci.yml @@ -0,0 +1,17 @@ +run: + go: '1.19' + +linters: + disable-all: true + enable: + - gofumpt + +issues: + # Show only new issues: if there are unstaged changes or untracked files, + # only those changes are analyzed, else only changes in HEAD~ are analyzed. + # It's a super-useful option for integration of golangci-lint into existing large codebase. + # It's not practical to fix all existing issues at the moment of integration: + # much better don't allow issues in new code. + # + # Default: false + new: true diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..a37b215 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,35 @@ +name: golangci-lint +on: + push: + +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for all branches and tags + - uses: actions/setup-go@v5 + with: + go-version: stable + - name: Find base branch + id: find_base_branch + run: | + BASE_BRANCH=$(git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)") + if [ -z "$BASE_BRANCH" ]; then + echo "BASE_BRANCH=origin/main" >> $GITHUB_ENV # Default to main if no upstream is set + else + echo "BASE_BRANCH=$BASE_BRANCH" >> $GITHUB_ENV + fi + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.59 + args: --config .github/workflows/.golangci.yml --new-from-rev ${{ env.BASE_BRANCH }}