Skip to content

Commit 54c1f58

Browse files
authored
feat: add commands to nodejs builder (#1189)
* add commands * update
1 parent e86872d commit 54c1f58

File tree

8 files changed

+300
-0
lines changed

8 files changed

+300
-0
lines changed

internal/builders/nodejs/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Commands
2+
3+
## ci
4+
`<binary> ci --directory="path/to/dir" --arguments="--ignore-scripts, --other-flag"`
5+
6+
## run
7+
`<binary> run --directory="path/to/dir" --scripts="script1, script2"`
8+
9+
## pack
10+
`<binary> pack --directory="path/to/dir"`
11+
12+
## publish
13+
`<binary> publish --directory="path/to/dir"`

internal/builders/nodejs/ci.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2022 SLSA Authors
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+
// https://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+
package main
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/spf13/cobra"
21+
)
22+
23+
// ciCmd runs the 'ci' command.
24+
func ciCmd(check func(error)) *cobra.Command {
25+
var ciArguments []string
26+
var ciDirectory string
27+
28+
c := &cobra.Command{
29+
Use: "ci",
30+
Short: "Run ci command",
31+
Long: `Run ci command to install dependencies of a node project. Example: ./binary ci --arguments="--ignore-scripts, --other-flag"`,
32+
33+
Run: func(cmd *cobra.Command, args []string) {
34+
fmt.Println(ciArguments)
35+
},
36+
}
37+
38+
c.Flags().StringArrayVarP(&ciArguments, "arguments", "a", []string{}, "Arguments to pass to ci command.")
39+
c.Flags().StringVarP(&ciDirectory, "directory", "d", "", "Working directory to issue commands.")
40+
41+
return c
42+
}

internal/builders/nodejs/main.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2022 SLSA Authors
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+
// https://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+
package main
16+
17+
import (
18+
"errors"
19+
"fmt"
20+
"os"
21+
22+
// Enable the github OIDC auth provider.
23+
_ "github.com/sigstore/cosign/pkg/providers/github"
24+
"github.com/slsa-framework/slsa-github-generator/signing/sigstore"
25+
26+
"github.com/spf13/cobra"
27+
)
28+
29+
func checkExit(err error) {
30+
if err != nil {
31+
fmt.Fprintln(os.Stderr, err)
32+
os.Exit(1)
33+
}
34+
}
35+
36+
func rootCmd() *cobra.Command {
37+
c := &cobra.Command{
38+
Use: "slsa-github-generator",
39+
Short: "Generate SLSA provenance for Github Actions",
40+
Long: `Generate SLSA provenance for Github Actions.
41+
For more information on SLSA, visit https://slsa.dev`,
42+
RunE: func(cmd *cobra.Command, args []string) error {
43+
return errors.New("expected command")
44+
},
45+
}
46+
c.AddCommand(versionCmd())
47+
c.AddCommand(provenanceCmd(nil, checkExit, sigstore.NewDefaultFulcio(), sigstore.NewDefaultRekor()))
48+
c.AddCommand(ciCmd(checkExit))
49+
c.AddCommand(packCmd(checkExit))
50+
c.AddCommand(publishCmd(checkExit))
51+
c.AddCommand(runCmd(checkExit))
52+
return c
53+
}
54+
55+
func main() {
56+
checkExit(rootCmd().Execute())
57+
}

internal/builders/nodejs/pack.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2022 SLSA Authors
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+
// https://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+
package main
16+
17+
import (
18+
"github.com/spf13/cobra"
19+
)
20+
21+
// packCmd runs the 'pack' command.
22+
func packCmd(check func(error)) *cobra.Command {
23+
var packDirectory string
24+
25+
c := &cobra.Command{
26+
Use: "pack",
27+
Short: "Run pack command",
28+
Long: `Run pack command to create a tarball for a nodejs project.`,
29+
30+
Run: func(cmd *cobra.Command, args []string) {
31+
},
32+
}
33+
34+
c.Flags().StringVarP(&packDirectory, "directory", "d", "", "Working directory to issue commands.")
35+
36+
return c
37+
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2022 SLSA Authors
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+
// https://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+
package main
16+
17+
import (
18+
"github.com/spf13/cobra"
19+
20+
"github.com/slsa-framework/slsa-github-generator/signing"
21+
"github.com/slsa-framework/slsa-github-generator/slsa"
22+
)
23+
24+
// provenanceCmd runs the 'provenance' command.
25+
func provenanceCmd(provider slsa.ClientProvider, check func(error), signer signing.Signer, tlog signing.TransparencyLog) *cobra.Command {
26+
var provenanceDirectory string
27+
28+
c := &cobra.Command{
29+
Use: "provenance",
30+
Short: "Run provenance command",
31+
Long: `Run provenance command to generate and sign provenance file.`,
32+
33+
Run: func(cmd *cobra.Command, args []string) {
34+
},
35+
}
36+
37+
c.Flags().StringVarP(&provenanceDirectory, "directory", "d", "", "Working directory to issue commands.")
38+
39+
return c
40+
}

internal/builders/nodejs/publish.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2022 SLSA Authors
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+
// https://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+
package main
16+
17+
import (
18+
"github.com/spf13/cobra"
19+
)
20+
21+
// publishCmd runs the 'publish' command.
22+
func publishCmd(check func(error)) *cobra.Command {
23+
var publishDirectory string
24+
25+
c := &cobra.Command{
26+
Use: "publish",
27+
Short: "Run publish command",
28+
Long: `Run publish command to publish a project.`,
29+
30+
Run: func(cmd *cobra.Command, args []string) {
31+
},
32+
}
33+
34+
c.Flags().StringVarP(&publishDirectory, "directory", "d", "", "Working directory to issue commands.")
35+
36+
return c
37+
}

internal/builders/nodejs/run.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2022 SLSA Authors
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+
// https://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+
package main
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/spf13/cobra"
21+
)
22+
23+
// runCmd runs the 'run' command.
24+
func runCmd(check func(error)) *cobra.Command {
25+
var runScripts []string
26+
var runDirectory string
27+
28+
c := &cobra.Command{
29+
Use: "run",
30+
Short: "Run scripts",
31+
Long: `Run scripts. Example: ./binary run --scripts="script1, script2"`,
32+
33+
Run: func(cmd *cobra.Command, args []string) {
34+
fmt.Println(runScripts)
35+
},
36+
}
37+
38+
c.Flags().StringSliceVarP(&runScripts, "scripts", "s", []string{}, "List of scripts to run.")
39+
c.Flags().StringVarP(&runDirectory, "directory", "d", "", "Working directory to issue commands.")
40+
return c
41+
}

internal/builders/nodejs/version.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2022 SLSA Authors
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+
// https://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+
package main
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/spf13/cobra"
21+
22+
"github.com/slsa-framework/slsa-github-generator/version"
23+
)
24+
25+
func versionCmd() *cobra.Command {
26+
return &cobra.Command{
27+
Use: "version",
28+
Short: "Print the version and exit",
29+
Run: func(cmd *cobra.Command, args []string) {
30+
fmt.Println(version.Version)
31+
},
32+
}
33+
}

0 commit comments

Comments
 (0)