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

Move linting to a Github action for better integration #30985

Merged
merged 3 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: golangci-lint
on:
#push:
# branches:
# - main
# - 8.*
# - 7.17
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
jobs:
golangci:
strategy:
matrix:
include:
- GOOS: windows
- GOOS: linux
- GOOS: darwin
Comment on lines +18 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rdner, is there any specific platform dependency while running golang-lint on windows and darwin? If so, I see down below the runs-on: ubuntu-latest, is that expected while running on windows/darwin too? I wonder if this matrix could be reduced to one OS (linux) if the outcome is the same for the other two platforms

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@v1v We have to run the linter against every platform (GOOS) we have any Go code for, otherwise any platform-specific code is not inspected and issues are not reported.

It does not matter on which OS it's running physically (ubuntu-latest), it's just an environment variable that tells the Go compiler which files to compile.

For Darwin we have these:

./metricbeat/internal/metrics/memory/memory_darwin.go
./metricbeat/internal/metrics/cpu/metrics_darwin.go
./auditbeat/module/file_integrity/fileorigin_darwin.go
./libbeat/statestore/backend/memlog/util_darwin.go
./libbeat/metric/system/process/process_darwin.go
./x-pack/osquerybeat/ext/osquery-extension/main_darwin.go

For Windows we have these:

./metricbeat/module/windows/service/zservice_windows.go
./metricbeat/module/windows/service/defs_service_windows.go
./metricbeat/internal/metrics/memory/memory_windows.go
./metricbeat/internal/metrics/cpu/metrics_windows.go
./metricbeat/internal/sysinit/system_windows.go
./metricbeat/helper/privileges_windows.go
./metricbeat/helper/dialer/dialer_windows.go
./metricbeat/helper/windows/pdh/zpdh_windows.go
./metricbeat/helper/windows/pdh/pdh_windows.go
./metricbeat/helper/windows/pdh/pdh_query_windows.go
./metricbeat/helper/windows/pdh/defs_pdh_windows.go
./filebeat/input/file/identifier_test_windows.go
./filebeat/input/file/identifier_inode_deviceid_windows.go
./filebeat/input/default-inputs/inputs_windows.go
./filebeat/input/filestream/fswatch_test_non_windows.go
./filebeat/input/filestream/identifier_inode_deviceid_windows.go
./filebeat/input/filestream/filestream_test_non_windows.go
./filebeat/input/filestream/identifier_test_non_windows.go
./auditbeat/module/file_integrity/fileinfo_windows.go
./auditbeat/module/file_integrity/security_windows.go
./auditbeat/module/file_integrity/zsecurity_windows.go
./winlogbeat/checkpoint/file_windows.go
./winlogbeat/sys/winevent/sid_windows.go
./winlogbeat/sys/wineventlog/syscall_windows.go
./winlogbeat/sys/wineventlog/zsyscall_windows.go
./winlogbeat/sys/wineventlog/wineventlog_windows.go
./winlogbeat/eventlog/errors_windows.go
./packetbeat/npcap/npcap_windows.go
./packetbeat/procs/syscall_windows.go
./packetbeat/procs/zsyscall_windows.go
./packetbeat/procs/procs_windows.go
./libbeat/logp/eventlog_windows.go
./libbeat/statestore/backend/memlog/util_windows.go
./libbeat/processors/decode_xml_wineventlog/decoder_windows.go
./libbeat/common/file/helper_windows.go
./libbeat/common/file/fileinfo_windows.go
./libbeat/common/file/stderr_windows.go
./libbeat/common/file/file_windows.go
./libbeat/api/npipe/listener_windows.go
./libbeat/api/make_listener_windows.go
./libbeat/service/service_windows.go
./libbeat/metric/system/numcpu/cpu_windows.go
./libbeat/metric/system/diskio/diskstat_windows.go
./libbeat/metric/system/process/process_windows.go
./x-pack/osquerybeat/ext/osquery-extension/main_windows.go
./x-pack/osquerybeat/internal/install/install_windows.go
./x-pack/osquerybeat/internal/osqd/osqueryd_windows.go
./x-pack/auditbeat/module/system/package/package_windows.go
./x-pack/winlogbeat/module/testing_windows.go
./x-pack/packetbeat/npcap/npcap_windows.go
./x-pack/libbeat/common/proc/job_windows.go

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification! It makes totally sense now :)

name: lint
runs-on: ubuntu-latest
steps:
- name: Echo details
env:
GOOS: ${{ matrix.GOOS }}
run: echo Go GOOS=$GOOS

- uses: actions/checkout@v2

# Uses Go version from the repository.
- name: Read .go-version file
id: goversion
run: echo "::set-output name=version::$(cat .go-version)"

- uses: actions/setup-go@v2
with:
go-version: "${{ steps.goversion.outputs.version }}"

- name: golangci-lint
env:
GOOS: ${{ matrix.GOOS }}
uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.44.2

# Give the job more time to execute.
# Regarding `--whole-files`, the linter is supposed to support linting of changed a patch only but,
# for some reason, it's very unreliable this way - sometimes it does not report any or some
# issues without linting the whole files, so we have to use `--whole-files`
# which can lead to some frustration from developers who would like to
# fix a single line in an existing codebase and the linter would force them
# into fixing all linting issues in the whole file instead
args: --timeout=30m --whole-files

# Optional: if set to true then the action will use pre-installed Go.
skip-go-installation: true

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only.
- Add gcp firestore metricset. {pull}29918[29918]
- Added TESTING_FILEBEAT_FILEPATTERN option for filebeat module pytests {pull}30103[30103]
- Add gcp dataproc metricset. {pull}30008[30008]
- Add Github action for linting
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is needed, we have not been filled any details in the changelog related to the CI/CD, if it helps

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I put it there the last time I changed the CI. Since it's just for developers, I think it would not hurt.


==== Deprecated

Expand Down
3 changes: 0 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,6 @@ def runLinting() {
}
mapParallelTasks['default'] = {
cmd(label: 'make check-default', script: 'make check-default')
cmd(label: 'Lint Last Change [Linux]', script: 'GOOS=linux mage -v llc')
cmd(label: 'Lint Last Change [Darwin]', script: 'GOOS=darwin mage -v llc')
cmd(label: 'Lint Last Change [Windows]', script: 'GOOS=windows mage -v llc')
}
mapParallelTasks['pre-commit'] = runPreCommit()
parallel(mapParallelTasks)
Expand Down