Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 19 additions & 37 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,49 @@ on:
pull_request:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1

codespell:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: codespell-project/actions-codespell@master
- uses: mlugg/setup-zig@v2
with:
check_filenames: true
skip: ./.git,./vendor,*_test.go,go.sum,go.mod
version: 0.15.2
- run: zig build

build:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v2
with:
version: 0.14.1
- run: |
make build
version: 0.15.2
- run: zig build fmt

fmt:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v2
with:
version: 0.14.1
- run: |
make fmt
version: 0.15.2
- run: zig build test

unit_test:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v2
with:
version: 0.14.1
- run: |
sudo apt-get install binutils-dev libssl-dev libcurl4-openssl-dev libelf-dev libstdc++-12-dev zlib1g-dev libdw-dev libiberty-dev git
version: 0.15.2
- name: Install kcov
run: |
sudo apt-get install -y binutils-dev libssl-dev libcurl4-openssl-dev libelf-dev libstdc++-12-dev zlib1g-dev libdw-dev libiberty-dev cmake
git clone https://github.com/SimonKagstrom/kcov.git
cd kcov
git checkout v43
mkdir build
cd build
cmake ..
make
sudo make install
- run: |
make test
make coverage

- name: Upload coverage reports to Codecov
cd kcov && git checkout v43 && mkdir build && cd build && cmake .. && make && sudo make install
- run: zig build cov
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: .coverage/test/cov.xml
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-umbrella
fail_ci_if_error: true
fail_ci_if_error: false
44 changes: 21 additions & 23 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// add library
const lib = b.addStaticLibrary(.{
.name = "ocispec",
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = b.path("src/distribution/lib.zig"),
.target = target,
.optimize = optimize,
.single_threaded = false,
});

b.installArtifact(lib);

const oci_spec_module = b.addModule("ocispec", .{
.root_source_file = b.path("src/lib.zig"),
});

// Library object for documentation generation
const lib = b.addObject(.{
.name = "ocispec",
.root_module = b.createModule(.{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
}),
});

// step generate docs
const install_docs = b.addInstallDirectory(.{
.source_dir = lib.getEmittedDocs(),
Expand All @@ -46,36 +43,37 @@ pub fn build(b: *std.Build) void {
}) |example_name| {
const example = b.addExecutable(.{
.name = example_name,
.root_source_file = b.path(b.fmt("examples/{s}.zig", .{example_name})),
.target = target,
.optimize = optimize,
.root_module = b.createModule(.{
.root_source_file = b.path(b.fmt("examples/{s}.zig", .{example_name})),
.target = target,
.optimize = optimize,
}),
});

example.root_module.addImport("ocispec", oci_spec_module);
b.installArtifact(example);
}

// step run tests
const lib_unit_tests = b.addTest(.{
// Assuming this needs to be the same root file as the library,
// since it's the library we're building tests for?
const test_module = b.createModule(.{
.root_source_file = b.path("tests/lib.zig"),
.target = target,
.optimize = optimize,
});
lib_unit_tests.root_module.addImport("ocispec", oci_spec_module);
test_module.addImport("ocispec", oci_spec_module);
const lib_unit_tests = b.addTest(.{
.root_module = test_module,
});

const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);

const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);

// step generate code cov
// step generate code coverage
const cov_step = b.step("cov", "Generate code coverage");

const cov_run = b.addSystemCommand(&.{ "kcov", "--clean", "--include-pattern=src/", ".coverage/" });
cov_run.addArtifactArg(lib_unit_tests);

cov_step.dependOn(&cov_run.step);

// step check formatting
Expand Down
10 changes: 4 additions & 6 deletions examples/artifact_manifest.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ pub fn main() !void {

const config_content = try artifact_manifest.toStringPretty(allocator);

const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
var write_buf: [4096]u8 = undefined;
var stdout = std.fs.File.stdout().writer(&write_buf);
try stdout.interface.print("{s}\n", .{config_content});
stdout.interface.flush() catch {};

try stdout.print("{s}\n", .{config_content});

try bw.flush();
}
10 changes: 4 additions & 6 deletions examples/image_config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ pub fn main() !void {
const image_config = try image.Configuration.initFromFile(allocator, file_path);
const config_content = try image_config.toStringPretty(allocator);

const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
var write_buf: [4096]u8 = undefined;
var stdout = std.fs.File.stdout().writer(&write_buf);
try stdout.interface.print("{s}\n", .{config_content});
stdout.interface.flush() catch {};

try stdout.print("{s}\n", .{config_content});

try bw.flush();
}
16 changes: 7 additions & 9 deletions examples/image_index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub fn main() !void {
.digest = try image.Digest.initFromString(allocator, "sha256:9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0"),
};

var manifests = std.ArrayList(image.Descriptor).init(allocator);
var manifests: std.ArrayListUnmanaged(image.Descriptor) = .{};

try manifests.append(index_manifest);
try manifests.append(allocator, index_manifest);

const image_manifests: []image.Descriptor = try manifests.toOwnedSlice();
const image_manifests: []image.Descriptor = try manifests.toOwnedSlice(allocator);

const image_index = image.Index{
.mediaType = image.MediaType.ImageIndex,
Expand All @@ -33,11 +33,9 @@ pub fn main() !void {

const image_index_content = try image_index.toStringPretty(allocator);

const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
var write_buf: [4096]u8 = undefined;
var stdout = std.fs.File.stdout().writer(&write_buf);
try stdout.interface.print("{s}\n", .{image_index_content});
stdout.interface.flush() catch {};

try stdout.print("{s}\n", .{image_index_content});

try bw.flush();
}
16 changes: 7 additions & 9 deletions examples/image_manifest.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub fn main() !void {
const media_config = image.MediaType.ImageConfig;
const media_layer = image.MediaType.ImageLayerGzip;

var mlayers = std.ArrayList(image.Descriptor).init(allocator);
try mlayers.append(image.Descriptor{
var mlayers: std.ArrayListUnmanaged(image.Descriptor) = .{};
try mlayers.append(allocator, image.Descriptor{
.mediaType = media_layer,
.digest = try image.Digest.initFromString(
allocator,
Expand All @@ -22,7 +22,7 @@ pub fn main() !void {
.size = 32654,
});

const manifest_layers: []image.Descriptor = try mlayers.toOwnedSlice();
const manifest_layers: []image.Descriptor = try mlayers.toOwnedSlice(allocator);

const manifest = image.Manifest{
.mediaType = media_manifest,
Expand All @@ -39,11 +39,9 @@ pub fn main() !void {

const manifest_content = try manifest.toStringPretty(allocator);

const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
var write_buf: [4096]u8 = undefined;
var stdout = std.fs.File.stdout().writer(&write_buf);
try stdout.interface.print("{s}\n", .{manifest_content});
stdout.interface.flush() catch {};

try stdout.print("{s}\n", .{manifest_content});

try bw.flush();
}
10 changes: 4 additions & 6 deletions examples/image_oci_layout.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ pub fn main() !void {

const oci_layout_content = try oci_layout.toStringPretty(allocator);

const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
var write_buf: [4096]u8 = undefined;
var stdout = std.fs.File.stdout().writer(&write_buf);
try stdout.interface.print("{s}\n", .{oci_layout_content});
stdout.interface.flush() catch {};

try stdout.print("{s}\n", .{oci_layout_content});

try bw.flush();
}
10 changes: 4 additions & 6 deletions examples/runtime_config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ pub fn main() !void {

const config_content = try spec.toStringPretty(allocator);

const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
var write_buf: [4096]u8 = undefined;
var stdout = std.fs.File.stdout().writer(&write_buf);
try stdout.interface.print("{s}\n", .{config_content});
stdout.interface.flush() catch {};

try stdout.print("{s}\n", .{config_content});

try bw.flush();
}
Loading
Loading