-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__test-action-working-directory.yml
More file actions
105 lines (93 loc) · 4.21 KB
/
Copy path__test-action-working-directory.yml
File metadata and controls
105 lines (93 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Internal - Tests for working-directory action
on:
workflow_call:
permissions:
contents: read
jobs:
tests:
name: Tests for working-directory action
runs-on: ubuntu-latest
steps:
- name: Arrange - Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Act - Resolve workspace root directory
id: working-directory
uses: ./actions/working-directory
with:
working-directory: .
- name: Assert - Check workspace root outputs
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
GITHUB_WORKSPACE_VALUE: ${{ github.workspace }}
STEPS_WORKING_DIRECTORY_OUTPUTS_ABSOLUTE_PATH: ${{ steps.working-directory.outputs.absolute-path }}
STEPS_WORKING_DIRECTORY_OUTPUTS_WORKSPACE_RELATIVE_PATH: ${{ steps.working-directory.outputs.workspace-relative-path }}
with:
script: |
const assert = require('node:assert/strict');
const absolutePath = process.env.STEPS_WORKING_DIRECTORY_OUTPUTS_ABSOLUTE_PATH;
const relativePath = process.env.STEPS_WORKING_DIRECTORY_OUTPUTS_WORKSPACE_RELATIVE_PATH;
const workspacePath = process.env.GITHUB_WORKSPACE_VALUE;
try {
assert.strictEqual(absolutePath, workspacePath, 'working-directory absolute-path output is not valid');
assert.strictEqual(relativePath, '.', 'working-directory workspace-relative-path output is not valid');
} catch (error) {
core.setFailed(error.message);
return;
}
- name: Act - Run outside-workspace path with enforcement enabled
id: outside-workspace-disallowed
continue-on-error: true
uses: ./actions/working-directory
with:
working-directory: /tmp
enforce-path-in-workspace: true
- name: Assert - Check enforcement failure outside workspace
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
STEPS_OUTSIDE_WORKSPACE_DISALLOWED_OUTCOME: ${{ steps.outside-workspace-disallowed.outcome }}
with:
script: |
const assert = require('node:assert/strict');
const outcome = process.env.STEPS_OUTSIDE_WORKSPACE_DISALLOWED_OUTCOME;
try {
assert.strictEqual(
outcome,
'failure',
'working-directory should fail when path is outside workspace and enforcement is enabled'
);
} catch (error) {
core.setFailed(error.message);
return;
}
- name: Act - Run outside-workspace path with enforcement disabled
id: outside-workspace-allowed
uses: ./actions/working-directory
with:
working-directory: /tmp
enforce-path-in-workspace: false
- name: Assert - Check enforcement opt-out outside workspace
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
STEPS_OUTSIDE_WORKSPACE_ALLOWED_OUTPUTS_ABSOLUTE_PATH: ${{ steps.outside-workspace-allowed.outputs.absolute-path }}
STEPS_OUTSIDE_WORKSPACE_ALLOWED_OUTPUTS_WORKSPACE_RELATIVE_PATH: ${{ steps.outside-workspace-allowed.outputs.workspace-relative-path }}
with:
script: |
const assert = require('node:assert/strict');
const absolutePath = process.env.STEPS_OUTSIDE_WORKSPACE_ALLOWED_OUTPUTS_ABSOLUTE_PATH;
const relativePath = process.env.STEPS_OUTSIDE_WORKSPACE_ALLOWED_OUTPUTS_WORKSPACE_RELATIVE_PATH;
try {
assert.strictEqual(
absolutePath,
'/tmp',
'working-directory absolute-path output is not valid when enforcement is disabled'
);
assert.ok(
relativePath.startsWith('..'),
'working-directory workspace-relative-path should be outside workspace when enforcement is disabled'
);
} catch (error) {
core.setFailed(error.message);
return;
}