Skip to content

Commit

Permalink
fix: lint-package-and-examples target (#2208)
Browse files Browse the repository at this point in the history
## Description

- Fix make target `lint-packages-and-examples`
- Remove `-skeleton` references
- Some small variable renaming + spelling fixes

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Other (security config, docs update, etc)

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed

---------

Signed-off-by: razzle <[email protected]>
Co-authored-by: Wayne Starr <[email protected]>
  • Loading branch information
Noxsios and Racer159 authored Jan 3, 2024
1 parent 3cf929f commit 5e99a86
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ docs-and-schema: ## Generate the Zarf Documentation and Schema
hack/gen-cli-docs.sh
ZARF_CONFIG=hack/empty-config.toml hack/create-zarf-schema.sh

lint-packages-and-examples: build-cli-for-system ## Recursively lint all zarf.yaml files in the repo except for those dedicated to tests
lint-packages-and-examples: build ## Recursively lint all zarf.yaml files in the repo except for those dedicated to tests
hack/lint_all_zarf_packages.sh $(ZARF_BIN)

# INTERNAL: a shim used to build the agent image only if needed on Windows using the `test` command
Expand Down
2 changes: 1 addition & 1 deletion examples/composable-packages/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ components:
# default: false # the initial value overrides the child component
import:
# The URL to the skeleton package containing this component's package definition
url: oci://🦄/dos-games:1.0.0-skeleton
url: oci://🦄/dos-games:1.0.0
# Example optional custom name to point to in the imported package (default is to use this component's name)
name: baseline
# Un'name'd Zarf primitives will be appended to the end of the primitive's list for that component.
Expand Down
6 changes: 3 additions & 3 deletions src/pkg/packager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (p *Packager) archivePackage(destinationTarball string) error {
}
spinner.Updatef("Wrote %s to %s", p.layout.Base, destinationTarball)

f, err := os.Stat(destinationTarball)
fi, err := os.Stat(destinationTarball)
if err != nil {
return fmt.Errorf("unable to read the package archive: %w", err)
}
Expand All @@ -341,7 +341,7 @@ func (p *Packager) archivePackage(destinationTarball string) error {
chunkSize := p.cfg.CreateOpts.MaxPackageSizeMB * 1000 * 1000

// If a chunk size was specified and the package is larger than the chunk size, split it into chunks.
if p.cfg.CreateOpts.MaxPackageSizeMB > 0 && f.Size() > int64(chunkSize) {
if p.cfg.CreateOpts.MaxPackageSizeMB > 0 && fi.Size() > int64(chunkSize) {
spinner.Updatef("Package is larger than %dMB, splitting into multiple files", p.cfg.CreateOpts.MaxPackageSizeMB)
chunks, sha256sum, err := utils.SplitFile(destinationTarball, chunkSize)
if err != nil {
Expand All @@ -359,7 +359,7 @@ func (p *Packager) archivePackage(destinationTarball string) error {
// Marshal the data into a json file.
jsonData, err := json.Marshal(types.ZarfSplitPackageData{
Count: len(chunks),
Bytes: f.Size(),
Bytes: fi.Size(),
Sha256Sum: sha256sum,
})
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions src/pkg/packager/sources/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func (s *SplitTarballSource) Collect(dir string) (string, error) {
// Ensure the files are in order so they are appended in the correct order
sort.Strings(fileList)

reassmbled := filepath.Join(dir, filepath.Base(strings.Replace(s.PackageSource, ".part000", "", 1)))
reassembled := filepath.Join(dir, filepath.Base(strings.Replace(s.PackageSource, ".part000", "", 1)))
// Create the new package
pkgFile, err := os.Create(reassmbled)
pkgFile, err := os.Create(reassembled)
if err != nil {
return "", fmt.Errorf("unable to create new package file: %s", err)
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func (s *SplitTarballSource) Collect(dir string) (string, error) {
}
}

if err := utils.SHAsMatch(reassmbled, pkgData.Sha256Sum); err != nil {
if err := utils.SHAsMatch(reassembled, pkgData.Sha256Sum); err != nil {
return "", fmt.Errorf("package integrity check failed: %w", err)
}

Expand All @@ -97,9 +97,9 @@ func (s *SplitTarballSource) Collect(dir string) (string, error) {
}

// communicate to the user that the package was reassembled
message.Infof("Reassembled package to: %q", reassmbled)
message.Infof("Reassembled package to: %q", reassembled)

return reassmbled, nil
return reassembled, nil
}

// LoadPackage loads a package from a split tarball.
Expand Down
1 change: 0 additions & 1 deletion src/pkg/packager/sources/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (s *TarballSource) LoadPackage(dst *layout.PackagePaths, unarchiveAll bool)

pathsExtracted := []string{}

// Walk the package so that was can dynamically load a .tar or a .tar.zst without caring about filenames.
err = archiver.Walk(s.PackageSource, func(f archiver.File) error {
if f.IsDir() {
return nil
Expand Down
4 changes: 4 additions & 0 deletions src/pkg/packager/sources/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func RenameFromMetadata(path string) (string, error) {
return "", err
}

if pkg.Metadata.Name == "" {
return "", fmt.Errorf("%q does not contain a zarf.yaml", path)
}

name := NameFromMetadata(&pkg, false)

name = fmt.Sprintf("%s%s", name, ext)
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/12_lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestLint(t *testing.T) {
require.Contains(t, strippedStderr, "image-in-good-flavor-component:unpinned")

// Check reported filepaths
require.Contains(t, strippedStderr, "Linting package \"dos-games\" at oci://🦄/dos-games:1.0.0-skeleton")
require.Contains(t, strippedStderr, "Linting package \"dos-games\" at oci://🦄/dos-games:1.0.0")
require.Contains(t, strippedStderr, fmt.Sprintf("Linting package \"lint\" at %s", testPackagePath))

})
Expand Down
2 changes: 1 addition & 1 deletion src/test/packages/12-lint/linted-import/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ components:

- name: oci-games-url
import:
url: oci://🦄/dos-games:1.0.0-skeleton
url: oci://🦄/dos-games:1.0.0
name: baseline
2 changes: 1 addition & 1 deletion src/test/packages/12-lint/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ components:

- name: oci-games-url
import:
url: oci://🦄/dos-games:1.0.0-skeleton
url: oci://🦄/dos-games:1.0.0
name: baseline

- name: oci-games-url
Expand Down

0 comments on commit 5e99a86

Please sign in to comment.