remote: don't upload failed action outputs. Fixes #7232

For historical reasons we are currently uploading the outputs
of failed actionsi (exit code != 0). This was mostly so that
test.log and test.xml of failed tests would be uploaded when
BES was enabled. However, we have had local file uploads in
BES for a while now and thus this (unexpected) feature is now
obsolete.

PTAL @benjaminp

Closes #7243.

PiperOrigin-RevId: 231201641
diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java
index 66a0b23..4ef09ad2 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java
@@ -189,8 +189,12 @@
         }
 
         @Override
-        public void store(SpawnResult result)
-            throws ExecException, InterruptedException, IOException {
+        public void store(SpawnResult result) throws ExecException, InterruptedException {
+          boolean uploadResults = Status.SUCCESS.equals(result.status()) && result.exitCode() == 0;
+          if (!uploadResults) {
+            return;
+          }
+
           if (options.experimentalGuardAgainstConcurrentChanges) {
             try (SilentCloseable c =
                 Profiler.instance().profile("RemoteCache.checkForConcurrentModifications")) {
@@ -200,13 +204,13 @@
               return;
             }
           }
-          boolean uploadAction = Status.SUCCESS.equals(result.status()) && result.exitCode() == 0;
+
           Context previous = withMetadata.attach();
           Collection<Path> files =
               RemoteSpawnRunner.resolveActionInputs(execRoot, spawn.getOutputFiles());
           try (SilentCloseable c = Profiler.instance().profile("RemoteCache.upload")) {
             remoteCache.upload(
-                actionKey, action, command, execRoot, files, context.getFileOutErr(), uploadAction);
+                actionKey, action, command, execRoot, files, context.getFileOutErr());
           } catch (IOException e) {
             String errorMsg = e.getMessage();
             if (isNullOrEmpty(errorMsg)) {