Skip to content
41 changes: 35 additions & 6 deletions go/lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,47 @@ runs:
- name: Setup safe directory
shell: bash
run: git config --global --add safe.directory ${{ inputs.WORKSPACE || github.workspace }}
- name: Grab golangci-lint version
if: ${{ hashFiles('.tool-versions') != '' }}
- name: Determine golangci-lint and config version
run: |
GOLANGCI_LINT_VERSION=$(awk '/^golangci-lint[[:space:]]+/ {print "v"$2}' .tool-versions)
# Default to empty version and v1 config
GOLANGCI_LINT_VERSION=""
IS_V2=false

# Check for GOLANG_CI_LINT_VERSION input
if [ -n "${{ inputs.GOLANG_CI_LINT_VERSION }}" ]; then
GOLANGCI_LINT_VERSION="${{ inputs.GOLANG_CI_LINT_VERSION }}"
echo "Using GOLANG_CI_LINT_VERSION=${GOLANGCI_LINT_VERSION} from input"
fi

# Check .tool-versions for golangci-lint version
if [ -z "$GOLANGCI_LINT_VERSION" ] && [ -f ".tool-versions" ] && [ -s ".tool-versions" ]; then
GOLANGCI_LINT_VERSION=$(awk '/^golangci-lint[[:space:]]+/ {print "v"$2}' .tool-versions)
echo "Using GOLANG_CI_LINT_VERSION=${GOLANGCI_LINT_VERSION} from .tool-versions"
fi

# Check .golangci.yml for version 2 config of golangci-lint
if [ -f ".golangci.yml" ] && grep -q 'version: "2"' .golangci.yml; then
IS_V2=true
echo "Found golangci-lint v2 config in .golangci.yml"
fi

echo "IS_V2=${IS_V2}" >> $GITHUB_ENV
echo "GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION}" >> $GITHUB_ENV
shell: bash
- name: Run Go linter
uses: golangci/golangci-lint-action@v4
- name: Run v1 Go linter
if : ${{ env.IS_V2 == 'false' }}
uses: golangci/golangci-lint-action@v6
with:
skip-cache: true
args: --verbose
version: ${{ env.GOLANGCI_LINT_VERSION }} # Optional - if blank, will use the action's default version resolution
- name: Run v2 Go linter
if : ${{ env.IS_V2 == 'true' }}
uses: golangci/golangci-lint-action@v7 # Note: v7 and up require golangci-lint v2 config
with:
skip-cache: true
args: --verbose
version: ${{ env.GOLANGCI_LINT_VERSION || inputs.GOLANG_CI_LINT_VERSION }} # Optional - if blank, will use the action's default version resolution
version: ${{ env.GOLANGCI_LINT_VERSION }} # Optional - if blank, will use the action's default version resolution
- name: Notify slack channel on failure
if: failure() && inputs.SLACK_CHANNEL_ID != null && github.ref == 'refs/heads/main'
uses: slackapi/slack-github-action@v1.24.0
Expand Down
Loading