-
Notifications
You must be signed in to change notification settings - Fork 137
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: npm builder updates #1206
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
09b2175
update
laurentsimon a45f68b
update
laurentsimon 18097c9
update
laurentsimon fe21e1b
update
laurentsimon 5af0bd4
update
laurentsimon 3d9bec7
update
laurentsimon a95dbad
Merge branch 'main' into feat/simplify
laurentsimon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// 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" | ||
) | ||
|
||
// buildCmd runs the 'build' command. | ||
func buildCmd(check func(error)) *cobra.Command { | ||
var dryRun bool | ||
|
||
c := &cobra.Command{ | ||
Use: "build", | ||
Short: "build a project", | ||
Long: `build a project. Example: ./binary build --dry-run"`, | ||
|
||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := build(dryRun); err != nil { | ||
panic(err) | ||
} | ||
}, | ||
} | ||
|
||
c.Flags().BoolVarP(&dryRun, "dry-run", "d", false, | ||
"Perform a dry run only. Do not build. Output provenance metadata (steps and provenance filenames)") | ||
return c | ||
} | ||
|
||
func build(dryRun bool) error { | ||
// 1. Retrieve the workflow inputs from env variable SLSA_WORKFLOW_INPUTS. | ||
|
||
// 2. Install dependencies via `npm ci <inputs.ci-arguments>` | ||
|
||
// 3. Build via `npm run <inputs.run-scripts>` | ||
|
||
// 4. Create the final package tarball. | ||
/* TODO: only run if non-empty. | ||
Note: pack-destination only supported version 7.x above. | ||
https://docs.npmjs.com/cli/v7/commands/npm-pack. | ||
This outputs a .tgz. Before running this command, let's record the .tgz | ||
files and their hashes, so that we can identify the new file without the need to parse | ||
the manifest.json. | ||
echo "npm pack --pack-destination="./out" | ||
copy tarball to upper folder to make the tarball accessible to next step. | ||
*/ | ||
// TODO: output the list of artifacts and their corresponding build steps. | ||
// The tarball name into a step output: echo "filename=$TARBALL" >> "$GITHUB_OUTPUT" | ||
|
||
if dryRun { | ||
// 1. Retrieve artifacts and their hases from env variable SLSA_BUILD_ARTIFACTS. | ||
|
||
// 2. Output the proveance metadata in a format: | ||
/* METADATA={ | ||
"provenance1.intoto.jsonl":{ | ||
"artifact-1":{ | ||
"digest": { | ||
"sha256": "abcdef" | ||
}, | ||
"buildSteps":[]Steps{ | ||
"workingDir": string, | ||
"env": map[string]string, | ||
"command": []string | ||
} | ||
}, | ||
"artifact-2":{ | ||
"digest": { | ||
"sha256": "abcdef" | ||
}, | ||
"buildSteps":[]Steps{ | ||
"workingDir": string, | ||
"env": map[string]string, | ||
"command": []string | ||
} | ||
} | ||
}, | ||
"provenance2.intoto.jsonl":{ | ||
"artifact-3":{ | ||
"digest": { | ||
"sha256": "abcdef" | ||
}, | ||
"buildSteps":[]Steps{ | ||
"workingDir": string, | ||
"env": map[string]string, | ||
"command": []string | ||
} | ||
}, | ||
} | ||
} | ||
*/ | ||
return nil | ||
} | ||
|
||
// 4. Output the list of artifacts in a format TBD (sha256sum?). | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you planning on setting these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not in this PR. The output of the builder can theoretically contain multiple artifacts, so I think we need to write code to process severals artifacts at once. For nodejs, I think it will always be a single artifact. But in general I'm trying to see what's needed to build a "generic workflow" that generalizes for any builder (nodejs, Java, goreleaser, container images, etc)