Skip to content

Commit 6e45c5a

Browse files
authored
Add scripts and pipeline workflows (#10)
* Add script files * Add a workflow job for linting
1 parent 05524b3 commit 6e45c5a

35 files changed

+601
-29
lines changed

.github/workflows/go.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2024 Morébec
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
# This workflow will build a golang project
216
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
317

@@ -10,6 +24,31 @@ on:
1024
branches: [ "main" ]
1125

1226
jobs:
27+
lint:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v3
31+
32+
- name: Set up Go
33+
uses: actions/setup-go@v3
34+
with:
35+
go-version: 1.19
36+
37+
- name: Add License
38+
run: ./scripts/add_license.sh
39+
40+
- name: Check Format
41+
run: ./scripts/check_gofmt.sh
42+
43+
- name: Check for changes
44+
id: check_changes
45+
run: |
46+
if [[ -n $(git status --porcelain) ]]; then
47+
echo "::set-output name=invalidCommit::true"
48+
fi
49+
50+
- name: Lint
51+
run: ./scripts/golangci_lint.sh
1352

1453
build:
1554
runs-on: ubuntu-latest

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@
1818
.vscode/
1919
.idea/
2020

21-
.specter.json
21+
# Specter
22+
.specter.json
23+
24+
# Utilities
25+
.husky
26+

Taskfile.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2024 Morébec
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
version: '3'
16+
17+
tasks:
18+
dev:install:
19+
cmds:
20+
- chmod +x ./scripts/*
21+
- ./scripts/husky.sh
22+
23+
dev:lint:
24+
cmds:
25+
- ./scripts/add_license.sh
26+
- ./scripts/check_gofmt.sh
27+
- ./scripts/golangci_lint.sh

artifactregistry.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Morébec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package specter
216

317
import (
@@ -113,10 +127,7 @@ func (r *JSONArtifactRegistry) Add(processorName string, e ArtifactRegistryEntry
113127
r.Entries[processorName] = make([]JsonArtifactRegistryEntry, 0)
114128
}
115129

116-
r.Entries[processorName] = append(r.Entries[processorName], JsonArtifactRegistryEntry{
117-
ArtifactID: e.ArtifactID,
118-
Metadata: e.Metadata,
119-
})
130+
r.Entries[processorName] = append(r.Entries[processorName], JsonArtifactRegistryEntry(e))
120131

121132
return nil
122133
}
@@ -151,10 +162,7 @@ func (r *JSONArtifactRegistry) FindByID(processorName string, artifactID Artifac
151162

152163
for _, entry := range r.Entries[processorName] {
153164
if entry.ArtifactID == artifactID {
154-
return ArtifactRegistryEntry{
155-
ArtifactID: entry.ArtifactID,
156-
Metadata: entry.Metadata,
157-
}, true, nil
165+
return ArtifactRegistryEntry(entry), true, nil
158166
}
159167
}
160168

@@ -171,10 +179,7 @@ func (r *JSONArtifactRegistry) FindAll(processorName string) ([]ArtifactRegistry
171179

172180
var entries []ArtifactRegistryEntry
173181
for _, entry := range r.Entries[processorName] {
174-
entries = append(entries, ArtifactRegistryEntry{
175-
ArtifactID: entry.ArtifactID,
176-
Metadata: entry.Metadata,
177-
})
182+
entries = append(entries, ArtifactRegistryEntry(entry))
178183
}
179184

180185
return entries, nil

artifactregistry_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Morébec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package specter
216

317
import (
@@ -157,6 +171,7 @@ func TestJSONArtifactRegistry_Save(t *testing.T) {
157171
require.NoError(t, err)
158172
}
159173
actualJSON, err := fs.ReadFile(filePath)
174+
require.NoError(t, err)
160175
assert.JSONEq(t, tt.then.expectedJSON, string(actualJSON))
161176
})
162177
}

assembly.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Morébec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package specter
216

317
import (

depresolve_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Morébec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package specter
216

317
import (

fileartifactprocessor.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Morébec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package specter
216

317
import (
@@ -182,7 +196,7 @@ func (p FileArtifactProcessor) cleanRegistry(ctx ArtifactProcessingContext) erro
182196
var wg sync.WaitGroup
183197
var errs errors.Group
184198

185-
ctx.Logger.Info(fmt.Sprintf("Cleaning file artifacts ..."))
199+
ctx.Logger.Info("Cleaning file artifacts ...")
186200
entries, err := ctx.ArtifactRegistry.FindAll()
187201
if err != nil {
188202
return err
@@ -230,7 +244,7 @@ func (p FileArtifactProcessor) cleanArtifact(ctx ArtifactProcessingContext, entr
230244
return nil
231245
}
232246

233-
ctx.Logger.Info(fmt.Sprintf(fmt.Sprintf("cleaning file artifact %q ...", entry.ArtifactID)))
247+
ctx.Logger.Info(fmt.Sprintf("cleaning file artifact %q ...", entry.ArtifactID))
234248
if err := p.FileSystem.Remove(path); err != nil {
235249
return err
236250
}

fileartifactprocessor_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Morébec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package specter
216

317
import (

filesystem.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Morébec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package specter
216

317
import (

filesystem_test.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Morébec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package specter
216

317
import (
@@ -16,11 +30,10 @@ var _ FileSystem = (*mockFileSystem)(nil)
1630
// Mock implementations to use in tests.
1731
type mockFileInfo struct {
1832
os.FileInfo
19-
name string
20-
size int64
21-
mode os.FileMode
22-
modTime int64
23-
isDir bool
33+
name string
34+
size int64
35+
mode os.FileMode
36+
isDir bool
2437
}
2538

2639
func (m mockFileInfo) Type() fs.FileMode {

hcl.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Morébec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package specter
216

317
import (
@@ -116,7 +130,7 @@ func (l HCLGenericSpecLoader) extractAttributesFromBlock(ctx *hcl.EvalContext, b
116130
for _, a := range block.Body.Attributes {
117131
value, d := a.Expr.Value(ctx)
118132
if d != nil && d.HasErrors() {
119-
d = append(diags, d...)
133+
diags = append(diags, d...)
120134
continue
121135
}
122136

linting.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Morébec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package specter
216

317
import (
@@ -183,7 +197,7 @@ func SpecificationsMustHaveUniqueNames(severity LinterResultSeverity) Specificat
183197
fnMap[fn] = struct{}{}
184198
}
185199
var fileNames []string
186-
for fn, _ := range fnMap {
200+
for fn := range fnMap {
187201
fileNames = append(fileNames, fn)
188202
}
189203

linting_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2024 Morébec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package specter
216

317
import (

0 commit comments

Comments
 (0)