Skip to content

Commit

Permalink
Merge branch 'pipeline-scripts'
Browse files Browse the repository at this point in the history
  • Loading branch information
jwillp committed Aug 29, 2024
2 parents 88a7a65 + 3e88b0f commit 3020594
Show file tree
Hide file tree
Showing 35 changed files with 601 additions and 29 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2024 Morébec
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

Expand All @@ -10,6 +24,31 @@ on:
branches: [ "main" ]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Add License
run: ./scripts/add_license.sh

- name: Check Format
run: ./scripts/check_gofmt.sh

- name: Check for changes
id: check_changes
run: |
if [[ -n $(git status --porcelain) ]]; then
echo "::set-output name=invalidCommit::true"
fi
- name: Lint
run: ./scripts/golangci_lint.sh

build:
runs-on: ubuntu-latest
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@
.vscode/
.idea/

.specter.json
# Specter
.specter.json

# Utilities
.husky

27 changes: 27 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2024 Morébec
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version: '3'

tasks:
dev:install:
cmds:
- chmod +x ./scripts/*
- ./scripts/husky.sh

dev:lint:
cmds:
- ./scripts/add_license.sh
- ./scripts/check_gofmt.sh
- ./scripts/golangci_lint.sh
29 changes: 17 additions & 12 deletions artifactregistry.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Morébec
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specter

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

r.Entries[processorName] = append(r.Entries[processorName], JsonArtifactRegistryEntry{
ArtifactID: e.ArtifactID,
Metadata: e.Metadata,
})
r.Entries[processorName] = append(r.Entries[processorName], JsonArtifactRegistryEntry(e))

return nil
}
Expand Down Expand Up @@ -151,10 +162,7 @@ func (r *JSONArtifactRegistry) FindByID(processorName string, artifactID Artifac

for _, entry := range r.Entries[processorName] {
if entry.ArtifactID == artifactID {
return ArtifactRegistryEntry{
ArtifactID: entry.ArtifactID,
Metadata: entry.Metadata,
}, true, nil
return ArtifactRegistryEntry(entry), true, nil
}
}

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

var entries []ArtifactRegistryEntry
for _, entry := range r.Entries[processorName] {
entries = append(entries, ArtifactRegistryEntry{
ArtifactID: entry.ArtifactID,
Metadata: entry.Metadata,
})
entries = append(entries, ArtifactRegistryEntry(entry))
}

return entries, nil
Expand Down
15 changes: 15 additions & 0 deletions artifactregistry_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Morébec
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specter

import (
Expand Down Expand Up @@ -157,6 +171,7 @@ func TestJSONArtifactRegistry_Save(t *testing.T) {
require.NoError(t, err)
}
actualJSON, err := fs.ReadFile(filePath)
require.NoError(t, err)
assert.JSONEq(t, tt.then.expectedJSON, string(actualJSON))
})
}
Expand Down
14 changes: 14 additions & 0 deletions assembly.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Morébec
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specter

import (
Expand Down
14 changes: 14 additions & 0 deletions depresolve_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Morébec
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specter

import (
Expand Down
18 changes: 16 additions & 2 deletions fileartifactprocessor.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Morébec
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specter

import (
Expand Down Expand Up @@ -182,7 +196,7 @@ func (p FileArtifactProcessor) cleanRegistry(ctx ArtifactProcessingContext) erro
var wg sync.WaitGroup
var errs errors.Group

ctx.Logger.Info(fmt.Sprintf("Cleaning file artifacts ..."))
ctx.Logger.Info("Cleaning file artifacts ...")
entries, err := ctx.ArtifactRegistry.FindAll()
if err != nil {
return err
Expand Down Expand Up @@ -230,7 +244,7 @@ func (p FileArtifactProcessor) cleanArtifact(ctx ArtifactProcessingContext, entr
return nil
}

ctx.Logger.Info(fmt.Sprintf(fmt.Sprintf("cleaning file artifact %q ...", entry.ArtifactID)))
ctx.Logger.Info(fmt.Sprintf("cleaning file artifact %q ...", entry.ArtifactID))
if err := p.FileSystem.Remove(path); err != nil {
return err
}
Expand Down
14 changes: 14 additions & 0 deletions fileartifactprocessor_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Morébec
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specter

import (
Expand Down
14 changes: 14 additions & 0 deletions filesystem.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Morébec
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specter

import (
Expand Down
23 changes: 18 additions & 5 deletions filesystem_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Morébec
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specter

import (
Expand All @@ -16,11 +30,10 @@ var _ FileSystem = (*mockFileSystem)(nil)
// Mock implementations to use in tests.
type mockFileInfo struct {
os.FileInfo
name string
size int64
mode os.FileMode
modTime int64
isDir bool
name string
size int64
mode os.FileMode
isDir bool
}

func (m mockFileInfo) Type() fs.FileMode {
Expand Down
16 changes: 15 additions & 1 deletion hcl.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Morébec
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specter

import (
Expand Down Expand Up @@ -116,7 +130,7 @@ func (l HCLGenericSpecLoader) extractAttributesFromBlock(ctx *hcl.EvalContext, b
for _, a := range block.Body.Attributes {
value, d := a.Expr.Value(ctx)
if d != nil && d.HasErrors() {
d = append(diags, d...)
diags = append(diags, d...)
continue
}

Expand Down
16 changes: 15 additions & 1 deletion linting.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Morébec
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specter

import (
Expand Down Expand Up @@ -183,7 +197,7 @@ func SpecificationsMustHaveUniqueNames(severity LinterResultSeverity) Specificat
fnMap[fn] = struct{}{}
}
var fileNames []string
for fn, _ := range fnMap {
for fn := range fnMap {
fileNames = append(fileNames, fn)
}

Expand Down
14 changes: 14 additions & 0 deletions linting_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Morébec
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package specter

import (
Expand Down
Loading

0 comments on commit 3020594

Please sign in to comment.