Skip to content

add lint workflow and fix lint issue#212

Merged
ChristopherHX merged 2 commits into
ChristopherHX:mainfrom
leslie-qiwa:lint
Aug 15, 2025
Merged

add lint workflow and fix lint issue#212
ChristopherHX merged 2 commits into
ChristopherHX:mainfrom
leslie-qiwa:lint

Conversation

@leslie-qiwa
Copy link
Copy Markdown
Contributor

@leslie-qiwa leslie-qiwa commented Aug 13, 2025

total 394 lint issues discovered by the tool. 95% fix is done by copilot , including several bugs found by lint

  1. Run method in actionsrunner/runner.go

actionsrunner/runner.go:147:3: deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop (gocritic)
defer cancelJobListening()

  1. io.Read/Write err not check: ignore most by AI but manually add logging at several places

  2. 3 files were DOS/Windows format.

protocol/results/contracts.go: ASCII text, with CRLF line terminators
protocol/results/service.go:   ASCII text, with CRLF line terminators
runnersurvey.go:               ASCII text, with CRLF line terminators

@leslie-qiwa
Copy link
Copy Markdown
Contributor Author

@ChristopherHX I really like the project, and hope to use it in our project. Understand this is a big PR, but I think it is needed to guard each PR.

Copy link
Copy Markdown
Owner

@ChristopherHX ChristopherHX left a comment

Choose a reason for hiding this comment

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

Hi,

The most dangerous part is changing the protocol structure names / saved json configuration fields.

  • if you add json tags
     `json:"myUrl"
    
    means myURL is no longer accepted by the json parser
  • not adding this means
    unexpected naming convention used in writing, causes problems with my other software interacting with this project

unresolved problem

Comment on lines +22 to +24
TarballURL string
Ref string
ZipballUrl string
ZipballURL string
Copy link
Copy Markdown
Owner

@ChristopherHX ChristopherHX Aug 13, 2025

Choose a reason for hiding this comment

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

Dangerous JSON Api public, potential problem when creating json from golang

Used by me in https://github.com/ChristopherHX/gitea-actions-runner/blob/343a633c06f22890e8133b8c999c567083ef1384/actions/server/server.go#L220

Impact seems to be minor, since this is legacy protocol and c# is case insensitive

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got you, didn't know the relationship. I can have another PR to fix that repo too if needed. :-)

@ChristopherHX
Copy link
Copy Markdown
Owner

During reading I understood almost every rename is fine, e.g. have a json tag to preserve binary compat

Comment on lines +209 to +212
_, xmlErr := ToXMLString(&ret.PKey.PublicKey)
if xmlErr != nil {
fmt.Printf("convert xml string: %v", xmlErr)
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this was dead code experimental code from myself

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we may do another cleanup next time.

}

func (logger *JobLogger) Append(record protocol.TimelineRecord) *protocol.TimelineRecord {
func (logger *JobLogger) Append(record *protocol.TimelineRecord) *protocol.TimelineRecord {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Breaking change api

Copy link
Copy Markdown
Contributor Author

@leslie-qiwa leslie-qiwa Aug 14, 2025

Choose a reason for hiding this comment

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

yes, this is one I forgot the mention in description. It is also discovered by lint tool with below warning

protocol/logger/job_logger.go:415:33: hugeParam: record is heavy (352 bytes); consider passing it by pointer (gocritic)

func (logger *JobLogger) Append(record protocol.TimelineRecord) *protocol.TimelineRecord {

thus, I made the change. Didn't realize it is also used by other repos. Let me know if you want to keep my current change. If yes, I can change other repo too if needed, otherwise, I can revert the change and add some nolint comment. But in my opinion, seems original copy may not be efficient in long live production environment.

}

func (logger *JobLogger) Insert(record protocol.TimelineRecord) *protocol.TimelineRecord {
func (logger *JobLogger) Insert(record *protocol.TimelineRecord) *protocol.TimelineRecord {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Breaking change api

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

same as above

@ChristopherHX
Copy link
Copy Markdown
Owner

Generally yes, I think this can be merged even if it is big. The change rate of this project has declined so, we could make this short and painless

@leslie-qiwa In what way do you want to use this project?

As a...

  • runner application
  • runner go library
  • something else

Normally I would decide that potential breaking changes should move to 1.0.0 milestone
Now my milestone moved months after months due to still being in a hybrid actions protocol mode.

@leslie-qiwa
Copy link
Copy Markdown
Contributor Author

@ChristopherHX Thanks for quick review. I would use it as a runner application, this is why I'm having this PR as I may create more PRs to improve stability, debug / logging, etc. We have a relative large golang based CI system, now need a self host runner to integrate with it and communicate with our internal resources. Thus your project is perfectly matching our need. :-)

@leslie-qiwa
Copy link
Copy Markdown
Contributor Author

During reading I understood almost every rename is fine, e.g. have a json tag to preserve binary compat

yes, that is why I'm making the change as json marshall/unmarshal should remain same, only public API need adapt the change.

@leslie-qiwa
Copy link
Copy Markdown
Contributor Author

Normally I would decide that potential breaking changes should move to 1.0.0 milestone Now my milestone moved months after months due to still being in a hybrid actions protocol mode.

The later the CI has static analysis, the more issues people need fix and deal with. :-) So better sooner than later imo.

@ChristopherHX
Copy link
Copy Markdown
Owner

Some change from your PR causes my runner CI to fail, stricter permissions? This is a mandatory CI check.

This readme change pr shows https://github.com/ChristopherHX/github-act-runner/actions/runs/16970040883/job/48104403780?pr=213 that CI passes today and this PR always failed due to permission denied

@ChristopherHX
Copy link
Copy Markdown
Owner

this is your CI result: https://github.com/ChristopherHX/github-act-runner/actions/runs/16945165477/job/48033615340?pr=212#step:6:1277

#​#​[​warning]github-act-runner is be unable to access "/home/runner/.cache/act". You might want set one of the following environment variables XDG_CACHE_HOME, HOME to a user read and writeable location. Details: mkdir /home/runner/.cache/act: permission denied
| Starting nektos/act
| #​#​[​error]mkdir /home/runner/.cache/act: permission denied

Running a non dockerized job after a docker job, or whatever the reason is.

@ChristopherHX
Copy link
Copy Markdown
Owner

I would merge this PR as soon as CI / run-tests (pull_request) is satisfied.

All other things are minor

Comment thread actionsdotnetactcompat/act_worker.go Outdated
maxRedirects = 10
jobTimeout = 5 * time.Minute
// File permissions
directoryPermissions = 0664
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

BUG Copilot revealed the fatal error 0775 is expected

Suggested change
directoryPermissions = 0664
directoryPermissions = 0777

It is not known if such a change will impact the runner

Suggested change
directoryPermissions = 0664
directoryPermissions = 0775

However folders need execute rights for enumerating it's content


The cause of the new error is the change in access rights when creating the cache directory:

Before the PR, os.MkdirAll(cacheDir, 0777) was probably used (full rights for everyone).
Now, os.MkdirAll(cacheDir, 0664) is used (no execute permission for directories, and no write permission for “others”).

This is a bug:
Directories require the execute (x) permission, otherwise no one (not even the owner) can enter the directory or create files in it.
0664 makes sense for files, but for directories you MUST use at least 0775 or 0777.

Conclusion:
The error was introduced in the PR by changing os.MkdirAll(cacheDir, 0777) to os.MkdirAll(cacheDir, 0664).
This is the cause of the new “permission denied” when creating ~/.cache/act.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you are right. I just pushed new change, and will see the result.

total 394 lint issues discovered by the tool. 95% fix is done by copilot
, including several bugs found by lint
1. Run method in actionsrunner/runner.go

actionsrunner/runner.go:147:3: deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop (gocritic)
                defer cancelJobListening()

2. io.Read/Write err not check:
ignore most by AI but manually add logging at several places

Signed-off-by: Leslie Qi Wang <qiwa@pensando.io>
@leslie-qiwa
Copy link
Copy Markdown
Contributor Author

my installed golangci-lint tool version seems not new as the one used in action, which identified more issues. Let me upgrade and fix.

@ChristopherHX
Copy link
Copy Markdown
Owner

As far I know golang ci lint is at v2.x already https://github.com/golangci/golangci-lint/releases

@leslie-qiwa
Copy link
Copy Markdown
Contributor Author

leslie-qiwa commented Aug 14, 2025

As far I know golang ci lint is at v2.x already https://github.com/golangci/golangci-lint/releases

yes, it need use v8.0 of golangci/golangci-lint-action and may discover more lint issues. Maybe merge this PR, and I can have another one to fix new issues identified. One complexity tool gocyclo is very useful. It is not included in current PR. I'm planning to add in next one with the latest golangci-lint tool

@ChristopherHX
Copy link
Copy Markdown
Owner

well now you broke almost all 32bit targets

@ChristopherHX
Copy link
Copy Markdown
Owner

ChristopherHX commented Aug 14, 2025

You know that len(x) of type int at least for 32bit?

casting max uint to int is an overflow or some other complaint

Do this in a bash shell to get the errors locally
GOOS=linux GOARCH=386 go build

Signed-off-by: Leslie Qi Wang <qiwa@pensando.io>
@leslie-qiwa
Copy link
Copy Markdown
Contributor Author

solved some errors introduced by AI auto fix, but seems more. Just pushed a new change, I used GOARCH=386 to verify and build is success. We can see if some other compilation error.

@ChristopherHX
Copy link
Copy Markdown
Owner

CI is passing now, ready for merge?

@leslie-qiwa
Copy link
Copy Markdown
Contributor Author

CI is passing now, ready for merge?

yes, thanks.

@leslie-qiwa
Copy link
Copy Markdown
Contributor Author

I'll have another PR to upgrade golangci-lint, and enable more lint.

@ChristopherHX ChristopherHX merged commit b291e34 into ChristopherHX:main Aug 15, 2025
46 checks passed
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

Successfully merging this pull request may close these issues.

2 participants