-
Notifications
You must be signed in to change notification settings - Fork 64
feat: add validate-release debug command #314
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
Open
upils
wants to merge
3
commits into
canonical:main
Choose a base branch
from
upils:validate-debug
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,46 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/jessevdk/go-flags" | ||
| ) | ||
|
|
||
| var ( | ||
| shortValidateReleaseHelp = "Validate a Chisel release" | ||
| longValidateReleaseHelp = ` | ||
| The validate-release command performs the static validation of a Chisel | ||
| release, checking the slice definition files (SDFs) and the chisel.yaml | ||
| file for structural issues without downloading any package. | ||
|
|
||
| By default it fetches the slices for the same Ubuntu version as the | ||
| current host, unless the --release flag is used. Pointing --release to a | ||
| local directory avoids any network access. | ||
| ` | ||
| ) | ||
|
|
||
| var validateReleaseDescs = map[string]string{ | ||
| "release": "Chisel release name or directory (e.g. ubuntu-22.04)", | ||
| } | ||
|
|
||
| type cmdDebugValidateRelease struct { | ||
| Release string `long:"release" value-name:"<branch|dir>"` | ||
| } | ||
|
|
||
| func init() { | ||
| addDebugCommand("validate-release", shortValidateReleaseHelp, longValidateReleaseHelp, func() flags.Commander { return &cmdDebugValidateRelease{} }, validateReleaseDescs, nil) | ||
| } | ||
|
|
||
| func (cmd *cmdDebugValidateRelease) Execute(args []string) error { | ||
| if len(args) > 0 { | ||
| return ErrExtraArgs | ||
| } | ||
|
|
||
| _, err := obtainRelease(cmd.Release) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| fmt.Fprintln(Stdout, "Release is valid") | ||
| return nil | ||
| } | ||
This file contains hidden or 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,93 @@ | ||
| package main_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| . "gopkg.in/check.v1" | ||
|
|
||
| chisel "github.com/canonical/chisel/cmd/chisel" | ||
| "github.com/canonical/chisel/internal/testutil" | ||
| ) | ||
|
|
||
| // writeRelease writes the provided release files into a temporary directory | ||
| // and returns its path. | ||
| func writeRelease(c *C, files map[string]string) string { | ||
| dir := c.MkDir() | ||
| for path, data := range files { | ||
| fpath := filepath.Join(dir, path) | ||
| err := os.MkdirAll(filepath.Dir(fpath), 0o755) | ||
| c.Assert(err, IsNil) | ||
| err = os.WriteFile(fpath, testutil.Reindent(data), 0o644) | ||
| c.Assert(err, IsNil) | ||
| } | ||
| err := os.MkdirAll(filepath.Join(dir, "slices"), 0o755) | ||
| c.Assert(err, IsNil) | ||
| return dir | ||
| } | ||
|
|
||
| func (s *ChiselSuite) TestValidateReleaseSuccess(c *C) { | ||
| s.ResetStdStreams() | ||
|
|
||
| dir := writeRelease(c, map[string]string{ | ||
| "chisel.yaml": testutil.DefaultChiselYaml, | ||
| "slices/mydir/pkg-a.yaml": ` | ||
| package: pkg-a | ||
| slices: | ||
| myslice: | ||
| contents: | ||
| /file/path: | ||
| `, | ||
| }) | ||
| _, err := chisel.Parser().ParseArgs( | ||
| []string{"debug", "validate-release", "--release", dir}, | ||
| ) | ||
| c.Assert(err, IsNil) | ||
| c.Assert(s.Stdout(), Equals, "Release is valid\n") | ||
| } | ||
|
|
||
| func (s *ChiselSuite) TestValidateReleaseErrorPropagation(c *C) { | ||
| s.ResetStdStreams() | ||
|
|
||
| dir := writeRelease(c, map[string]string{ | ||
| "chisel.yaml": testutil.DefaultChiselYaml, | ||
| "slices/mydir/pkg-a.yaml": ` | ||
| package: pkg-a | ||
| slices: | ||
| myslice: | ||
| contents: | ||
| /path1: | ||
| `, | ||
| "slices/mydir/pkg-b.yaml": ` | ||
| package: pkg-b | ||
| slices: | ||
| myslice: | ||
| contents: | ||
| /path1: | ||
| `, | ||
| }) | ||
| _, err := chisel.Parser().ParseArgs( | ||
| []string{"debug", "validate-release", "--release", dir}, | ||
| ) | ||
| c.Assert(err, ErrorMatches, `slices pkg-a_myslice and pkg-b_myslice conflict on /path1`) | ||
| c.Assert(s.Stdout(), Equals, "") | ||
| } | ||
|
|
||
| func (s *ChiselSuite) TestValidateReleaseExtraArgs(c *C) { | ||
| s.ResetStdStreams() | ||
|
|
||
| dir := writeRelease(c, map[string]string{ | ||
| "chisel.yaml": testutil.DefaultChiselYaml, | ||
| "slices/mydir/pkg-a.yaml": ` | ||
| package: pkg-a | ||
| slices: | ||
| myslice: | ||
| contents: | ||
| /file/path: | ||
| `, | ||
| }) | ||
| _, err := chisel.Parser().ParseArgs( | ||
| []string{"debug", "validate-release", "--release", dir, "extra"}, | ||
| ) | ||
| c.Assert(err, ErrorMatches, `too many arguments for command`) | ||
| } |
This file contains hidden or 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,4 @@ | ||
| summary: Validate a Chisel release statically | ||
|
|
||
| execute: | | ||
| chisel debug validate-release --release ${OS}-${RELEASE} 2>&1 | MATCH "Release is valid" |
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.
Do we have a convention established for such messages? Lower/upper? Punctuation?
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.
I did not find one for this type of message but looking again for it made me realize displaying this message in stdout looks inconsistent with other commands. So this is now using
logf(sending to stderr by default) and I added a period at the end of the message. This is more consistent with the behavior ofcheck-release-archives. Output of a successful execution looks like this: