Skip to content

Commit

Permalink
Merge pull request #22 from rock-core/ignore_failed_tests
Browse files Browse the repository at this point in the history
Add option to allow ignoring packages with failed tests on cache push
  • Loading branch information
g-arjones authored Jun 22, 2023
2 parents 8f4c780 + f382497 commit 3ca2344
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/autoproj/cli/ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def cache_pull(dir, ignore: [])
results
end

def cache_push(dir)
def cache_push(dir, ignore_failed_tests: false)
packages = resolve_packages
metadata = consolidated_report["packages"]

Expand All @@ -92,6 +92,12 @@ def cache_push(dir)
elsif !build_info["success"]
pkg.message "%s: build failed, not pushing", :magenta
next
elsif ignore_failed_tests &&
pkg_metadata["test"] &&
pkg_metadata["test"]["invoked"] &&
!pkg_metadata["test"]["success"]
pkg.message "%s: test failed, not pushing", :magenta
next
end

# Remove cached flags before saving
Expand Down
2 changes: 2 additions & 0 deletions lib/autoproj/cli/main_ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ def cache_pull(dir, ignore: [])
"cache-pull"
option :report, type: "string", default: "cache-push.json",
desc: "a file which describes what has been done"
option :ignore_failed_tests, type: "boolean", default: false,
desc: "ignore packages with failed tests"
def cache_push(dir)
dir = File.expand_path(dir)

Expand Down
42 changes: 42 additions & 0 deletions test/autoproj/cli/ci_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,48 @@ module Autoproj::CLI # rubocop:disable Style/ClassAndModuleChildren
File.join(@archive_dir, @pkg.name, "contents")
)
end
it "updates packages with no tests when ignoring failed tests" do
make_build_report
make_archive("a", "TEST")
make_prefix(File.join(@ws.prefix_dir, @pkg.name))
results = @cli.cache_push(@archive_dir, ignore_failed_tests: true)
assert_equal({ "a" => { "updated" => true, "fingerprint" => "TEST" } },
results)

system("tar", "xzf", "TEST", chdir: File.join(@archive_dir, @pkg.name))
assert_equal "prefix", File.read(
File.join(@archive_dir, @pkg.name, "contents")
)
end
it "updates packages with tests that have not been invoked when ignoring "\
"failed tests" do
make_build_report
make_test_report(add: { "invoked" => false, "success" => false },
timestamp: Time.now + 2)
make_archive("a", "TEST")
make_prefix(File.join(@ws.prefix_dir, @pkg.name))
results = @cli.cache_push(@archive_dir, ignore_failed_tests: true)
assert_equal({ "a" => { "updated" => true, "fingerprint" => "TEST" } },
results)

system("tar", "xzf", "TEST", chdir: File.join(@archive_dir, @pkg.name))
assert_equal "prefix", File.read(
File.join(@archive_dir, @pkg.name, "contents")
)
end
it "ignores packages which test was not successful" do
make_build_report
make_test_report(add: { "success" => false }, timestamp: Time.now + 2)
make_archive("a", "TEST")
make_prefix(File.join(@ws.prefix_dir, @pkg.name))
results = @cli.cache_push(@archive_dir, ignore_failed_tests: true)
assert_equal({}, results)

system("tar", "xzf", "TEST", chdir: File.join(@archive_dir, @pkg.name))
assert_equal "archive", File.read(
File.join(@archive_dir, @pkg.name, "contents")
)
end
it "deals with race conditions on push" do
make_prefix(File.join(@ws.prefix_dir, @pkg.name))
make_build_report
Expand Down

0 comments on commit 3ca2344

Please sign in to comment.