Skip to content
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

[6.4.0] Add formatted timestamp entries to volatile workspace status file. #19499

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions site/en/docs/user-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,8 @@ The contract is:
Bazel always outputs the following volatile keys:
* `BUILD_TIMESTAMP`: time of the build in seconds since the Unix Epoch (the value
of `System.currentTimeMillis()` divided by a thousand)
* `FORMATTED_DATE`: time of the build Formatted as
`yyyy MMM d HH mm ss EEE`(for example 2023 Jun 2 01 44 29 Fri) in UTC.

On Linux/macOS you can pass `--workspace_status_command=/bin/true` to
disable retrieving workspace status, because `true` does nothing, successfully (exits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.TreeMap;
import javax.annotation.Nullable;
Expand All @@ -80,6 +83,13 @@ static class BazelWorkspaceStatusAction extends WorkspaceStatusAction {
private final String username;
private final String hostname;

private static final DateTimeFormatter TIME_FORMAT =
DateTimeFormatter.ofPattern("yyyy MMM d HH mm ss EEE");

private static String format(long timestamp) {
return Instant.ofEpochMilli(timestamp).atZone(ZoneOffset.UTC).format(TIME_FORMAT);
}

BazelWorkspaceStatusAction(
Artifact stableStatus, Artifact volatileStatus, String username, String hostname) {
super(
Expand Down Expand Up @@ -182,6 +192,7 @@ public ActionResult execute(ActionExecutionContext actionExecutionContext)
stableMap.put(BuildInfo.BUILD_USER, username);
volatileMap.put(
BuildInfo.BUILD_TIMESTAMP, Long.toString(getCurrentTimeMillis(clientEnv) / 1000));
volatileMap.put("FORMATTED_DATE", format(getCurrentTimeMillis(clientEnv) / 1000 * 1000));
buildbreaker2021 marked this conversation as resolved.
Show resolved Hide resolved
try {
Map<String, String> statusMap =
parseWorkspaceStatus(getAdditionalWorkspaceStatus(options, actionExecutionContext));
Expand Down