Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡 Add script to set up probe boilerplate #3948

Merged
merged 7 commits into from May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -174,6 +174,9 @@ validate-docs: docs/checks/internal/generate/main.go
# Validating checks.yaml
go run ./docs/checks/internal/validate/main.go

setup-probe:
go run ./probes/internal/scripts/setup.go $(probeName)

SCORECARD_DEPS = $(shell find . -iname "*.go" | grep -v tools/)
build-scorecard: ## Build Scorecard CLI
build-scorecard: scorecard
Expand Down
136 changes: 136 additions & 0 deletions probes/internal/scripts/setup.go
@@ -0,0 +1,136 @@
// Copyright 2024 OpenSSF Scorecard Authors
//
// 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 main

import (
"fmt"
"os"
"path"
"time"
)

func main() {
if len(os.Args) != 2 {
panic("usage: make setup-probe probeName=arg")
}
pn := os.Args[1]

pd := path.Join("probes", pn)
err := os.Mkdir(pd, 0o700)
if err != nil {
panic(err)
}

y := time.Now().Year()

implBoilerplate := fmt.Sprintf(`// Copyright %d OpenSSF Scorecard Authors
//
// 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.

//nolint:stylecheck
package %s

import (
"embed"

"github.com/ossf/scorecard/v5/checker"
"github.com/ossf/scorecard/v5/finding"
)

//go:embed *.yml
var fs embed.FS

const (
Probe = "%s"
)

raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
func Run(raw *checker.RawResults) ([]finding.Finding, string, error) {
return nil, "", nil
}
`, y, pn, pn)
err = os.WriteFile(path.Join(pd, "impl.go"), []byte(implBoilerplate), 0o600)
if err != nil {
panic(err)
}

implTestBoilerplate := fmt.Sprintf(`// Copyright %d OpenSSF Scorecard Authors
//
// 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.

//nolint:stylecheck
package %s
`, y, pn)
err = os.WriteFile(path.Join(pd, "impl_test.go"), []byte(implTestBoilerplate), 0o600)
if err != nil {
panic(err)
}

defYmlBoilerplate := fmt.Sprintf(`# Copyright %d OpenSSF Scorecard Authors
#
# 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.

id: %s
short: A short description of this probe
motivation: >
What is the motivation for this probe?
implementation: >
How does this probe work under-the-hood?
outcome:
-
remediation:
effort: # High, Medium, Low
text:
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
-
ecosystem:
languages:
- all
clients:
- github
- gitlab
raghavkaul marked this conversation as resolved.
Show resolved Hide resolved
`, y, pn)
err = os.WriteFile(path.Join(pd, "def.yml"), []byte(defYmlBoilerplate), 0o600)
if err != nil {
panic(err)
}
}