[Linting] Enforce 120 max lines, and import order with custom linting #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The reason the linting step has been moved to its own file is due to this | ||
# aside in the golangci-lint action repo underneath the first code block: | ||
# Ref: https://github.com/golangci/golangci-lint-action#how-to-use | ||
# tl;dr: "We recommend running this action in a job separate from other jobs | ||
# (go test, etc) because different jobs run in parallel." | ||
Name: Linter | ||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }} | ||
cancel-in-progress: true | ||
# Ref: https://github.com/golangci/golangci-lint-action#comments-and-annotations | ||
permissions: | ||
contents: read | ||
pull-requests: read | ||
checks: write | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Firstly setup the repo to a point where golangci-lint is able to lint | ||
# properly without getting typeerror's from revive everywhere. | ||
- name: install ignite | ||
# TODO_TECHDEBT: upgrade to the latest Ignite (the latest at the moment of creating a note is 0.28). Need to downgrade to fix CI pipelines. Might be done in scope of #240. | ||
run: | | ||
# curl https://get.ignite.com/cli! | bash | ||
wget https://github.com/ignite/cli/releases/download/v0.27.2/ignite_0.27.2_linux_amd64.tar.gz | ||
tar -xzf ignite_0.27.2_linux_amd64.tar.gz | ||
sudo mv ignite /usr/local/bin/ignite | ||
ignite version | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: "0" # Per https://github.com/ignite/cli/issues/1674#issuecomment-1144619147 | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: "1.20.10" | ||
cache: false # Per https://github.com/golangci/golangci-lint-action#how-to-use | ||
- name: Install CI dependencies | ||
run: make install_ci_deps | ||
- name: Generate protobufs | ||
run: make proto_regen | ||
# Fetch a list of all modified files in this PR. | ||
- name: Get Modified Files | ||
run: git diff --name-only ${{ github.event.before }} ${{ github.sha }} > modified_files.txt | ||
# Filter the list of files modified in this PR to exclude those that have | ||
# ignite scaffold comments in their import block, this is because gci | ||
# (golangci-lint's import formatter) doesn't support this kind of filtering | ||
# and removes all comments from import blocks. | ||
- name: Filter For Lintable Files | ||
run: go run ./tools/scripts/scaffold_filter/main.go $(cat modified_files.txt) > files_to_lint.txt | ||
# Run golangci-lint on the filtered files from this PR - allowing gci to | ||
# catch any improperly formatted import blocks in this PR. | ||
- name: Run golangci-lint (filtered for scaffold comments) | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: latest | ||
args: --timeout=15m --config=.golangci.yml $(cat files_to_lint.txt) | ||
only-new-issues: true | ||
# Do a second lint pass without import checking (after filtered lint) to | ||
# catcy any linter errors in files that were excluded in the first pass. | ||
# This step disables gci checks, to check for all other linter errors, | ||
# on every file in the PR, without filtering. | ||
- name: Run golangci-lint (without import checking) | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: latest | ||
args: --timeout=15m --config=.golangci.yml --disable gci $(cat modified_files.txt) | ||
only-new-issues: true |