Skip to content

Commit 6bc4430

Browse files
committed
add lint
1 parent 097417c commit 6bc4430

6 files changed

Lines changed: 125 additions & 6 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- main
8+
pull_request:
9+
jobs:
10+
golangci:
11+
name: golangci-lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: golangci-lint
16+
uses: golangci/golangci-lint-action@v2
17+
with:
18+
version: latest

.github/workflows/release.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: create release binaries
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
linux:
10+
name: create linux binaries
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- name: checkout code
14+
uses: actions/checkout@v2
15+
- name: build amd64
16+
run: |
17+
set -eu
18+
bazelisk build //:bazel-differ-linux-amd64
19+
bazelisk run --run_under "cp -f " //cli:bazel-differ-linux-amd64 $(pwd)/bazel-differ-linux-amd64
20+
- name: build arm64
21+
run: |
22+
set -eu
23+
bazelisk build //:bazel-differ-linux-arm64
24+
bazelisk run --run_under "cp -f " //cli:bazel-differ-linux-arm64 $(pwd)/bazel-differ-linux-arm64
25+
- name: get release URL
26+
id: get_release
27+
uses: bruceadams/get-release@v1.2.2
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
- name: get release version
31+
id: release_version
32+
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
33+
- name: upload linux amd64
34+
id: upload-release-asset-linux-amd64
35+
uses: actions/upload-release-asset@v1
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
with:
39+
upload_url: ${{ steps.get_release.outputs.upload_url }}
40+
asset_path: bazel-differ-linux-amd64
41+
asset_name: bazel-differ-${{ steps.release_version.outputs.VERSION }}-linux-x86_64
42+
asset_content_type: application/octet-stream
43+
- name: upload linux arm64
44+
id: upload-release-asset-linux-arm64
45+
uses: actions/upload-release-asset@v1
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
with:
49+
upload_url: ${{ steps.get_release.outputs.upload_url }}
50+
asset_path: bazel-differ-linux-arm64
51+
asset_name: bazel-differ-${{ steps.release_version.outputs.VERSION }}-linux-arm64
52+
asset_content_type: application/octet-stream
53+
54+
mac:
55+
name: create mac binaries
56+
runs-on: macos-10.15
57+
steps:
58+
- name: checkout
59+
uses: actions/checkout@v2
60+
- name: build amd64
61+
run: |
62+
set -eu
63+
bazelisk build //cli:bazel-differ-darwin-amd64
64+
bazelisk run --run_under "cp -f " //:bazel-differ-darwin-amd64 $(pwd)/bazel-differ-darwin-amd64
65+
- name: build arm64
66+
run: |
67+
set -eu
68+
bazelisk build //cli:bazel-differ-darwin-arm64
69+
bazelisk run --run_under "cp -f " //:bazel-differ-darwin-arm64 $(pwd)/bazel-differ-darwin-arm64
70+
- name: get release URL
71+
id: get_release
72+
uses: bruceadams/get-release@v1.2.2
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
- name: get release version
76+
id: release_version
77+
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
78+
- name: upload darwin amd64
79+
id: upload-release-asset-darwin-amd64
80+
uses: actions/upload-release-asset@v1
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
with:
84+
upload_url: ${{ steps.get_release.outputs.upload_url }}
85+
asset_path: bazel-differ-darwin-amd64
86+
asset_name: bazel-differ-${{ steps.release_version.outputs.VERSION }}-darwin-x86_64
87+
asset_content_type: application/octet-stream
88+
- name: upload darwin arm64
89+
id: upload-release-asset-darwin-arm64
90+
uses: actions/upload-release-asset@v1
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
with:
94+
upload_url: ${{ steps.get_release.outputs.upload_url }}
95+
asset_path: bazel-differ-darwin-arm64
96+
asset_name: bazel-differ-${{ steps.release_version.outputs.VERSION }}-darwin-arm64
97+
asset_content_type: application/octet-stream

cmd/diff.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ var diffCmd = &cobra.Command{
5353

5454
func writeFile(targets map[string]bool, output string) {
5555
file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
56-
defer file.Close()
5756

5857
if err != nil {
5958
log.Fatalf("failed creating file: %s", err)
6059
}
6160

61+
defer file.Close()
62+
6263
datawriter := bufio.NewWriter(file)
6364
defer datawriter.Flush()
6465

65-
for k, _ := range targets {
66+
for k := range targets {
6667
_, _ = datawriter.WriteString(k + "\n")
6768
}
6869
}

cmd/generate_hashes.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ var generateHashesCmd = &cobra.Command{
5252

5353
func readSeedFile() map[string]bool {
5454
readFile, err := os.Open(SeedFilepaths)
55-
defer readFile.Close()
55+
5656
if err != nil {
5757
panic(err)
5858
}
59+
60+
defer readFile.Close()
61+
5962
fileScanner := bufio.NewScanner(readFile)
6063
fileScanner.Split(bufio.ScanLines)
6164
seedFilepaths := make(map[string]bool)

internal/target_hashing_client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (t targetHashingClient) GetImpactedTargets(startHashes map[string]string, e
6060
}
6161

6262
func createSeedForFilepaths(filesys fs.FS, seedFilepaths []string) ([]byte, error) {
63-
if seedFilepaths == nil || len(seedFilepaths) == 0 {
63+
if len(seedFilepaths) == 0 {
6464
return []byte{}, nil
6565
}
6666
buffer := bytes.NewBuffer([]byte{})
@@ -253,8 +253,7 @@ func getDigestForSourceTargetName(sourceTargetName string, bazelSourcefileTarget
253253
}
254254

255255
func convertByteArrayToString(bytes []byte) string {
256-
var hexChars []byte
257-
hexChars = make([]byte, len(bytes)*2)
256+
hexChars := make([]byte, len(bytes)*2)
258257
for i := 0; i < len(bytes); i++ {
259258
v := bytes[i] & 0xFF
260259
hexChars[i*2] = HexArray[v>>4]

internal/target_hashing_client_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func createRuleTarget(name string, inputs []string, digest string, ctrl *gomock.
263263
return target
264264
}
265265

266+
//nolint
266267
func createGeneratedTarget(name string, generatingRuleName string) *internal.Target {
267268
generatingFileName := generatingRuleName + "_file"
268269
target := &internal.Target{

0 commit comments

Comments
 (0)