Skip to content

Commit

Permalink
feat: add commands to nodejs builder (#1189)
Browse files Browse the repository at this point in the history
* add commands

* update
  • Loading branch information
laurentsimon authored Nov 4, 2022
1 parent e86872d commit 54c1f58
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/builders/nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Commands

## ci
`<binary> ci --directory="path/to/dir" --arguments="--ignore-scripts, --other-flag"`

## run
`<binary> run --directory="path/to/dir" --scripts="script1, script2"`

## pack
`<binary> pack --directory="path/to/dir"`

## publish
`<binary> publish --directory="path/to/dir"`
42 changes: 42 additions & 0 deletions internal/builders/nodejs/ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2022 SLSA 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
//
// https://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"

"github.com/spf13/cobra"
)

// ciCmd runs the 'ci' command.
func ciCmd(check func(error)) *cobra.Command {
var ciArguments []string
var ciDirectory string

c := &cobra.Command{
Use: "ci",
Short: "Run ci command",
Long: `Run ci command to install dependencies of a node project. Example: ./binary ci --arguments="--ignore-scripts, --other-flag"`,

Run: func(cmd *cobra.Command, args []string) {
fmt.Println(ciArguments)
},
}

c.Flags().StringArrayVarP(&ciArguments, "arguments", "a", []string{}, "Arguments to pass to ci command.")
c.Flags().StringVarP(&ciDirectory, "directory", "d", "", "Working directory to issue commands.")

return c
}
57 changes: 57 additions & 0 deletions internal/builders/nodejs/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2022 SLSA 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
//
// https://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 (
"errors"
"fmt"
"os"

// Enable the github OIDC auth provider.
_ "github.com/sigstore/cosign/pkg/providers/github"
"github.com/slsa-framework/slsa-github-generator/signing/sigstore"

"github.com/spf13/cobra"
)

func checkExit(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func rootCmd() *cobra.Command {
c := &cobra.Command{
Use: "slsa-github-generator",
Short: "Generate SLSA provenance for Github Actions",
Long: `Generate SLSA provenance for Github Actions.
For more information on SLSA, visit https://slsa.dev`,
RunE: func(cmd *cobra.Command, args []string) error {
return errors.New("expected command")
},
}
c.AddCommand(versionCmd())
c.AddCommand(provenanceCmd(nil, checkExit, sigstore.NewDefaultFulcio(), sigstore.NewDefaultRekor()))
c.AddCommand(ciCmd(checkExit))
c.AddCommand(packCmd(checkExit))
c.AddCommand(publishCmd(checkExit))
c.AddCommand(runCmd(checkExit))
return c
}

func main() {
checkExit(rootCmd().Execute())
}
37 changes: 37 additions & 0 deletions internal/builders/nodejs/pack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2022 SLSA 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
//
// https://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 (
"github.com/spf13/cobra"
)

// packCmd runs the 'pack' command.
func packCmd(check func(error)) *cobra.Command {
var packDirectory string

c := &cobra.Command{
Use: "pack",
Short: "Run pack command",
Long: `Run pack command to create a tarball for a nodejs project.`,

Run: func(cmd *cobra.Command, args []string) {
},
}

c.Flags().StringVarP(&packDirectory, "directory", "d", "", "Working directory to issue commands.")

return c
}
40 changes: 40 additions & 0 deletions internal/builders/nodejs/provenance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2022 SLSA 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
//
// https://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 (
"github.com/spf13/cobra"

"github.com/slsa-framework/slsa-github-generator/signing"
"github.com/slsa-framework/slsa-github-generator/slsa"
)

// provenanceCmd runs the 'provenance' command.
func provenanceCmd(provider slsa.ClientProvider, check func(error), signer signing.Signer, tlog signing.TransparencyLog) *cobra.Command {
var provenanceDirectory string

c := &cobra.Command{
Use: "provenance",
Short: "Run provenance command",
Long: `Run provenance command to generate and sign provenance file.`,

Run: func(cmd *cobra.Command, args []string) {
},
}

c.Flags().StringVarP(&provenanceDirectory, "directory", "d", "", "Working directory to issue commands.")

return c
}
37 changes: 37 additions & 0 deletions internal/builders/nodejs/publish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2022 SLSA 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
//
// https://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 (
"github.com/spf13/cobra"
)

// publishCmd runs the 'publish' command.
func publishCmd(check func(error)) *cobra.Command {
var publishDirectory string

c := &cobra.Command{
Use: "publish",
Short: "Run publish command",
Long: `Run publish command to publish a project.`,

Run: func(cmd *cobra.Command, args []string) {
},
}

c.Flags().StringVarP(&publishDirectory, "directory", "d", "", "Working directory to issue commands.")

return c
}
41 changes: 41 additions & 0 deletions internal/builders/nodejs/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2022 SLSA 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
//
// https://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"

"github.com/spf13/cobra"
)

// runCmd runs the 'run' command.
func runCmd(check func(error)) *cobra.Command {
var runScripts []string
var runDirectory string

c := &cobra.Command{
Use: "run",
Short: "Run scripts",
Long: `Run scripts. Example: ./binary run --scripts="script1, script2"`,

Run: func(cmd *cobra.Command, args []string) {
fmt.Println(runScripts)
},
}

c.Flags().StringSliceVarP(&runScripts, "scripts", "s", []string{}, "List of scripts to run.")
c.Flags().StringVarP(&runDirectory, "directory", "d", "", "Working directory to issue commands.")
return c
}
33 changes: 33 additions & 0 deletions internal/builders/nodejs/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2022 SLSA 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
//
// https://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"

"github.com/spf13/cobra"

"github.com/slsa-framework/slsa-github-generator/version"
)

func versionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print the version and exit",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version.Version)
},
}
}

0 comments on commit 54c1f58

Please sign in to comment.