Skip to content

Commit 418d1a4

Browse files
author
Murat
committed
fix(states): do not set state to done if it was changed since progress
1 parent 0f697eb commit 418d1a4

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/__tests__/unit/utils/setState.spec.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@ import { setState } from '../../../utils/setState';
55
import { variables } from '../../../variables';
66

77
describe('setState', () => {
8-
it('should not set state to done if it is not progress', () => {
8+
it('should set state to done if it is progress', () => {
99
variables.clear();
10-
variables.set('test', {
11-
state: 'skipped',
12-
} as TaskState);
10+
setState('test', {
11+
state: 'progress',
12+
});
1313
setState('test', {
1414
state: 'done',
1515
});
16-
expect(variables.get<TaskState>('test')).toEqual({
16+
expect(variables.get<TaskState['state']>('test')).toEqual('done');
17+
});
18+
it('should not set state to done if it is not progress', () => {
19+
variables.clear();
20+
setState('test', {
1721
state: 'skipped',
1822
});
23+
setState('test', {
24+
state: 'done',
25+
});
26+
expect(variables.get<TaskState['state']>('test')).toEqual('skipped');
1927
});
2028
});

src/utils/setState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { variables } from '../variables';
44
export function setState(name: string | undefined, state: TaskState): void {
55
if (name) {
66
if (state.state == 'done') {
7-
const currentState = variables.get<TaskState>(name);
8-
if (currentState && currentState.state != 'progress') return;
7+
const currentState = variables.get<TaskState['state']>(name);
8+
if (currentState && currentState != 'progress') return;
99
}
1010
variables.set(name, state.state);
1111
variables.set('reason.' + name, state.reason);

website/docs/guides/states.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ steps:
4646

4747
- task: build_gradle
4848
when:
49-
fs_google.state: done
49+
fs_google: done
5050
```
5151
5252
In this example, we have two tasks. The first task, `fs_google`, has a name assigned to it. The second task, `build_gradle`, uses the `when` condition to check the state of the `fs_google` task. It will only execute when the `fs_google` task is in the `done` state (completed successfully).

0 commit comments

Comments
 (0)