Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Golang static checks and linting GitHub Actions #33

Closed
avinal opened this issue Jan 5, 2024 · 7 comments
Closed

Add Golang static checks and linting GitHub Actions #33

avinal opened this issue Jan 5, 2024 · 7 comments
Assignees

Comments

@avinal
Copy link
Member

avinal commented Jan 5, 2024

Configure and use https://github.com/golangci/golangci-lint-action for static checks and linting on pull requests and push.

@avinal avinal self-assigned this Jan 5, 2024
@dvjsharma
Copy link
Contributor

Hi @avinal
I’m interested in tackling this feature. I have previous experience with GitHub Actions, where I automated the SBOM generation process. I’d appreciate the opportunity to work on this.

@dvjsharma
Copy link
Contributor

Hi @avinal,

I hope you're doing well! 👋

I wanted to update you on the progress for the "Static Checks and Linting" workflow. Currently, I've implemented it using the golangci-lint GitHub Action. There are two main approaches for this:

  1. Using Marketplace GolangCI Action:
    This approach involves leveraging the golangci/golangci-lint-action from the GitHub Marketplace. It's a common choice among many projects as it provides a standard set of linters with a straightforward setup. However, it's worth noting that this method has some limitations in terms of customization. Please refer https://golangci-lint.run/usage/configuration/

  2. Manual Installation and Configuration:
    Alternatively, we can manually install golangci-lint inside the action and configure a YML file to customize linters. This approach provides more flexibility in configuring specific linters according to our project needs. Interestingly, I've observed that most projects tend to use the first method for its simplicity and standard linters. In contrast, the second approach, though more flexible, is less commonly adopted, possibly due to the perceived complexity.

Here's the YML configuration for our "Static Checks and Linting" GitHub Action, designed using approach 1:

# SPDX-FileCopyrightText: 2024 Divij Sharma <[email protected]>
# SPDX-License-Identifier: GPL-2.0-only

name: Static Checks and Linting

concurrency:
  group: lint-${{ github.head_ref }}
  cancel-in-progress: true

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]
  workflow_dispatch:

jobs:
  golangci-lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: '1.20'
          check-latest: true
          cache: true

      - name: lint
        uses: golangci/golangci-lint-action@v3
        with:
          version: v1.51

It's important to note that before deploying this action, we need to take into account the existing errors in the code.
Screenshot from 2024-01-11 14-01-43

I need assistance in deciding which approach (1 or 2) to use. Your insights are highly appreciated!
CC @GMishx

@avinal
Copy link
Member Author

avinal commented Jan 11, 2024

I favor the 1st method. It will be a good starting point and later, if needed, we can switch to manual.

@GMishx
Copy link
Member

GMishx commented Jan 11, 2024

I also agree with @avinal here. 1st approach will be a good start and if required, can switch to the manual approach.

PS, the fix for api_test.go is in #34 if you are going to open the PR 😉
https://github.com/fossology/LicenseDb/pull/34/files#diff-445f75dbda6fe7b9191d0b2cb94a621ae7a41eb786d6796540df4c6aa7a38d72

@dvjsharma
Copy link
Contributor

I also agree with @avinal here. 1st approach will be a good start and if required, can switch to the manual approach.

PS, the fix for api_test.go is in #34 if you are going to open the PR 😉 https://github.com/fossology/LicenseDb/pull/34/files#diff-445f75dbda6fe7b9191d0b2cb94a621ae7a41eb786d6796540df4c6aa7a38d72

Thank you, @GMishx!
I also addressed some warnings related to potential errors during unmarshaling JSON in api_test.go
Currently working on resolving the following issues:

image

Moreover, I wanted to confirm if the proposed YML file for the action is acceptable, or if it requires any modifications. Please advise on that aspect.

P.S. I will open a PR as soon as the codebase is error-free, and lint check doesn't fail during every run.
CC @avinal

@GMishx
Copy link
Member

GMishx commented Jan 11, 2024

Awesome! Also, the YAML file looks correct to me.

@GMishx
Copy link
Member

GMishx commented Jan 12, 2024

Closed by #36

@GMishx GMishx closed this as completed Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants