Skip to content

Commit bc17f2a

Browse files
author
katermart
committed
Downloading cirrus cache to local (cirruslabs#461)
1 parent 221fac6 commit bc17f2a

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

src/components/tasks/TaskCommandLogs.tsx

+31-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ import createStyles from '@mui/styles/createStyles';
1313
import withStyles from '@mui/styles/withStyles';
1414
import GetApp from '@mui/icons-material/GetApp';
1515
import Fab from '@mui/material/Fab';
16-
import { TaskCommandLogsTailQuery } from './__generated__/TaskCommandLogsTailQuery.graphql';
17-
import { TaskCommandStatus } from './__generated__/TaskCommandList_task.graphql';
16+
import {
17+
TaskCommandLogsTailQuery,
18+
TaskCommandLogsTailQueryResponse,
19+
} from './__generated__/TaskCommandLogsTailQuery.graphql';
20+
import { TaskCommandStatus, TaskCommandType } from './__generated__/TaskCommandList_task.graphql';
1821

1922
function logURL(taskId: string, command) {
2023
return 'https://api.cirrus-ci.com/v1/task/' + taskId + '/logs/' + command.name + '.log';
2124
}
2225

26+
function cacheURL(taskId: string, executionInfo) {
27+
let cacheKey = executionInfo.cacheRetrievalAttempts.hits[0].key;
28+
return 'https://api.cirrus-ci.com/v1/task/' + taskId + '/caches/' + cacheKey + '.tar.gz';
29+
}
30+
2331
let styles = theme =>
2432
createStyles({
2533
actionButtons: {
@@ -36,8 +44,10 @@ interface RealTimeLogsProps extends WithStyles<typeof styles> {
3644
command: {
3745
name: string;
3846
status: TaskCommandStatus;
47+
type: TaskCommandType;
3948
};
4049
initialLogLines: ReadonlyArray<string>;
50+
executionInfo: TaskCommandLogsTailQueryResponse['task']['executionInfo'];
4151
}
4252

4353
function TaskCommandRealTimeLogs(props: RealTimeLogsProps) {
@@ -55,14 +65,15 @@ function TaskCommandRealTimeLogs(props: RealTimeLogsProps) {
5565
return () => closable();
5666
}, [realTimeLogs, props.taskId, props.command.name, additionalLogs]);
5767

58-
let { classes, taskId, command, initialLogLines } = props;
68+
let { classes, taskId, command, initialLogLines, executionInfo } = props;
69+
5970
let inProgress = !isTaskCommandFinalStatus(command.status);
6071
let downloadButton = (
6172
<div className={classes.actionButtons}>
6273
<Fab
6374
variant="circular"
6475
className={classes.downloadButton}
65-
href={logURL(taskId, command)}
76+
href={command.type === 'UPLOAD_CACHE' ? cacheURL(taskId, executionInfo) : logURL(taskId, command)}
6677
target="_blank"
6778
rel="noopener noreferrer"
6879
>
@@ -86,6 +97,7 @@ interface TaskCommandLogsProps extends WithStyles<typeof styles> {
8697
command: {
8798
name: string;
8899
status: TaskCommandStatus;
100+
type: TaskCommandType;
89101
};
90102
}
91103

@@ -98,6 +110,14 @@ function TaskCommandLogs(props: TaskCommandLogsProps) {
98110
query TaskCommandLogsTailQuery($taskId: ID!, $commandName: String!) {
99111
task(id: $taskId) {
100112
commandLogsTail(name: $commandName)
113+
executionInfo {
114+
cacheRetrievalAttempts {
115+
hits {
116+
key
117+
valid
118+
}
119+
}
120+
}
101121
}
102122
}
103123
`}
@@ -109,7 +129,13 @@ function TaskCommandLogs(props: TaskCommandLogsProps) {
109129
</div>
110130
);
111131
}
112-
return <TaskCommandRealTimeLogs initialLogLines={response.props.task.commandLogsTail || []} {...props} />;
132+
return (
133+
<TaskCommandRealTimeLogs
134+
initialLogLines={response.props.task.commandLogsTail || []}
135+
executionInfo={response.props.task.executionInfo}
136+
{...props}
137+
/>
138+
);
113139
}}
114140
/>
115141
);

0 commit comments

Comments
 (0)