Skip to content

Commit 2558ef1

Browse files
authored
🐛 QD-11458: 3rd party linters should update their binary in cache (#567)
* 🐛 QD-11464: Fix tests for clang not running on GitHub * 🐛 QD-11464: Fix failing test * 🐛 QD-11464: Revert "Fix tests for clang not running on GitHub" This reverts commit 91a7143. * Fix .NET tests * 🐛 QD-11464: Minor fixes * 🐛 QD-11464: Fix TestDirLanguagesExcluded being dependent on languages in repo * 🐛 QD-11464: Fix unused import * 🐛 QD-11464: Perform an explicit build in CI to avoid panics on test * 🐛 QD-11464: Fix recognizeDirLanguages not excluding folders with backslashes * ♻️ QD-11464: Use the same shell on all machines in CI * 🐛 QD-11464: Do not rely on tar's BSD extension for opening zip files * 🐛 Add linter field to cdnet test project * 🐛 QD-11464: Add back forgotten commandline switch * ♻️ QD-11464: Use built-in functionality for temp test dirs * ✨ QD-11458: Embed clang-tidy hashes in addition to binaries themselves * ✨ QD-11458: Check sha256 of clang-tidy binary if it exists * 🙈 QD-11458: Add gitignore for clang folder * 🐛 QD-11458: Fix unhandled errors and resource management * ✅ QD-11458: Add a test for correct hash * ✨ QD-11458: Implement a new method of embedding clang-tidy * ✨ QD-11458: Implement hashsum check for cdnet * 🐛 QD-11458: Update build process to include generate step * ♻️ QD-11458: Refactor the test selection process for GitHub * ✨ QD-11458: Support mocking artifacts in CI * 🐛 QD-11458: Fix unhandled errors * 🐛 QD-11458: Fix CI * 🐛 QD-11458: Revert unnecessary change * 🐛 QD-11458: Fix tests
1 parent a96093a commit 2558ef1

File tree

21 files changed

+437
-116
lines changed

21 files changed

+437
-116
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,18 @@ jobs:
3434
distribution: 'temurin' # Use the Temurin JDK distribution
3535
java-version: '17' # Java version 17
3636
- name: Overwrite tools (to run tests only on gh repo)
37-
run: |
38-
touch cdnet/clt.zip tooling/baseline-cli.jar tooling/intellij-report-converter.jar tooling/qodana-fuser.jar
39-
rm go.work && mv go.work.github go.work
37+
run: >-
38+
touch
39+
cdnet/clt.zip
40+
tooling/baseline-cli.jar
41+
tooling/intellij-report-converter.jar
42+
tooling/qodana-fuser.jar
43+
clang/clang-tidy-linux-amd64.tar.gz
44+
clang/clang-tidy-linux-arm64.tar.gz
45+
clang/clang-tidy-windows-amd64.zip
46+
clang/clang-tidy-windows-arm64.zip
47+
clang/clang-tidy-darwin-amd64.tar.gz
48+
clang/clang-tidy-darwin-arm64.tar.gz
4049
shell: bash
4150
- name: Set up gotestfmt
4251
uses: gotesttools/gotestfmt-action@v2
@@ -82,9 +91,18 @@ jobs:
8291
with:
8392
fetch-depth: 0
8493
- name: Overwrite tools (to run tests only on gh repo)
85-
run: |
86-
touch cdnet/clt.zip tooling/baseline-cli.jar tooling/intellij-report-converter.jar tooling/qodana-fuser.jar
87-
rm go.work && mv go.work.github go.work
94+
run: >-
95+
touch
96+
cdnet/clt.zip
97+
tooling/baseline-cli.jar
98+
tooling/intellij-report-converter.jar
99+
tooling/qodana-fuser.jar
100+
clang/clang-tidy-linux-amd64.tar.gz
101+
clang/clang-tidy-linux-arm64.tar.gz
102+
clang/clang-tidy-windows-amd64.zip
103+
clang/clang-tidy-windows-arm64.zip
104+
clang/clang-tidy-darwin-amd64.tar.gz
105+
clang/clang-tidy-darwin-arm64.tar.gz
88106
- uses: docker/login-action@v3
89107
with:
90108
registry: registry.jetbrains.team
@@ -131,7 +149,6 @@ jobs:
131149
# - name: Overwrite tools (to run tests only on gh repo)
132150
# run: |
133151
# touch cdnet/clt.zip tooling/baseline-cli.jar tooling/intellij-report-converter.jar tooling/qodana-fuser.jar
134-
# rm go.work && mv go.work.github go.work
135152
# - run: |
136153
# ./download_deps.sh
137154
# export TARGETARCH=$(uname -m)

cdnet/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# build artifacts
2+
*.zip
3+
4+
## go generate artifacs
5+
*.sha256.bin

cdnet/clt.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

cdnet/run.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ package main
1919
import (
2020
"encoding/json"
2121
"fmt"
22+
"os"
23+
"path/filepath"
24+
25+
_ "embed"
26+
2227
"github.com/JetBrains/qodana-cli/v2025/platform"
2328
"github.com/JetBrains/qodana-cli/v2025/platform/nuget"
2429
"github.com/JetBrains/qodana-cli/v2025/platform/strutil"
2530
"github.com/JetBrains/qodana-cli/v2025/platform/thirdpartyscan"
2631
"github.com/JetBrains/qodana-cli/v2025/platform/utils"
2732
"github.com/JetBrains/qodana-cli/v2025/sarif"
28-
"os"
29-
"path/filepath"
3033
)
3134

3235
type CdnetLinter struct {
@@ -61,19 +64,23 @@ func (l CdnetLinter) RunAnalysis(c thirdpartyscan.Context) error {
6164
return err
6265
}
6366

67+
var CltDllRelativePath = "tools/netcoreapp3.1/any/JetBrains.CommandLine.Products.dll"
68+
69+
//go:generate go run scripts/compute-sha256.go tools/netcoreapp3.1/any/JetBrains.CommandLine.Products.dll
70+
71+
//go:embed clt.zip
72+
var CltArchive []byte
73+
74+
//go:embed clt.sha256.bin
75+
var CltSha256 []byte
76+
6477
func (l CdnetLinter) MountTools(path string) (map[string]string, error) {
6578
val := make(map[string]string)
66-
val[thirdpartyscan.Clt] = filepath.Join(
67-
path,
68-
"tools",
69-
"netcoreapp3.1",
70-
"any",
71-
"JetBrains.CommandLine.Products.dll",
72-
)
79+
val[thirdpartyscan.Clt] = filepath.Join(path, CltDllRelativePath)
7380

7481
if _, err := os.Stat(val["clt"]); err != nil {
7582
if os.IsNotExist(err) {
76-
archivePath := platform.ProcessAuxiliaryTool(archive, moniker, path, Clt)
83+
archivePath := platform.ProcessAuxiliaryTool(archive, moniker, path, CltArchive)
7784
if err := platform.Decompress(archivePath, path); err != nil {
7885
return nil, fmt.Errorf("failed to decompress %s archive: %w", moniker, err)
7986
}

cdnet/run_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/JetBrains/qodana-cli/v2025/platform/thirdpartyscan"
8+
"github.com/JetBrains/qodana-cli/v2025/platform/utils"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestMountTools(t *testing.T) {
13+
// skip this test on GitHub due to missing artifacts
14+
if os.Getenv("GITHUB_ACTIONS") == "true" {
15+
t.Skip()
16+
}
17+
18+
linter := CdnetLinter{}
19+
tempdir := t.TempDir()
20+
21+
mountInfo, err := linter.MountTools(tempdir)
22+
if err != nil {
23+
t.Fatal(err)
24+
}
25+
26+
path := mountInfo[thirdpartyscan.Clt]
27+
expectedHash := CltSha256
28+
actualHash, err := utils.GetFileSha256(path)
29+
if err != nil {
30+
t.Fatal(err)
31+
}
32+
assert.Equal(t, expectedHash, actualHash[:])
33+
}

cdnet/scripts/compute-sha256.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Compute SHA-256 checksum for clt.zip artifact.
2+
package main
3+
4+
import (
5+
"encoding/hex"
6+
"fmt"
7+
"io"
8+
"log"
9+
"os"
10+
11+
"github.com/JetBrains/qodana-cli/v2025/platform/utils"
12+
)
13+
14+
func main() {
15+
if len(os.Args) <= 1 {
16+
log.Fatalf("Expected path of the file to hash as argv[1] (relative from clt.zip root)")
17+
}
18+
targetPath := os.Args[1]
19+
20+
// Compute hash for the clang-tidy binary
21+
var hash [32]byte
22+
callback := func(path string, info os.FileInfo, stream io.Reader) {
23+
if info.IsDir() {
24+
return
25+
}
26+
if path != targetPath {
27+
return
28+
}
29+
30+
err := (error)(nil)
31+
hash, err = utils.GetSha256(stream)
32+
if err != nil {
33+
log.Fatalf("sha256 error: %s", err)
34+
}
35+
}
36+
37+
stat, err := os.Stat("clt.zip")
38+
if err != nil {
39+
log.Fatal(err)
40+
}
41+
if stat.Size() == 0 {
42+
// Assume someone does not have clt.zip and just `touch`-ed it to proceed with the build.
43+
_, err = fmt.Fprintln(os.Stderr, "clt.zip is a 0-byte file, will generate mock hashsum.")
44+
if err != nil {
45+
log.Fatal(err)
46+
}
47+
} else {
48+
err = utils.WalkZipArchive("clt.zip", callback)
49+
if err != nil {
50+
log.Fatal(err)
51+
}
52+
}
53+
54+
err = os.WriteFile("clt.sha256.bin", hash[:], 0666)
55+
if err != nil {
56+
log.Fatal(err)
57+
}
58+
59+
_, err = fmt.Fprintf(os.Stderr, "sha256 of the contents of clt.zip: %s\n", hex.EncodeToString(hash[:]))
60+
if err != nil {
61+
log.Fatal(err)
62+
}
63+
}

clang/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# build artifacts
2+
*.tar.gz
3+
*.zip
4+
5+
## go generate artifacs
6+
*.archive
7+
*.sha256.bin

clang/clang_darwin_amd64.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

clang/clang_darwin_arm64.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

clang/clang_linux_amd64.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)