This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
generated from im-open/composite-action-template
-
Notifications
You must be signed in to change notification settings - Fork 0
179 lines (154 loc) · 4.95 KB
/
test-zip-upload-artifact.yml
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Test Zip Upload Artifact
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
jobs:
test-zip-upload-artifact:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Test Files for Zip
shell: bash
run: |
echo "################################"
echo "Setup Test files for Zip"
echo "################################"
echo ""
echo "Create subfolder"
mkdir "subfolder"
echo "Create test-root.txt"
echo "################ Test Root ################" > test-root.txt
echo ""
echo "Create subfolder/test-sub1.txt"
echo "################ Test Sub1 ################" > subfolder/test-sub1.txt
echo ""
echo "Create subfolder/test-sub2.txt"
echo "################ Test Sub2 ################" > subfolder/test-sub2.txt
echo ""
echo "Create subfolder/sub-subfolder/test-sub-sub1.txt"
mkdir "subfolder/sub-subfolder"
echo "################ Test Sub Sub1 ################" > subfolder/sub-subfolder/test-sub-sub1.txt
echo ""
echo "Create subfolder/sub-subfolder/test-sub-sub2.txt"
echo "################ Test Sub Sub2 ################" > subfolder/sub-subfolder/test-sub-sub2.txt
echo ""
echo "DONE!"
- name: 1. Artifact with Sub1 and Sub2
if: always()
uses: ./
with:
name: 1-with-sub1-and-sub2
path: subfolder
retention-days: 1
- name: 2. Artifact with Root
if: always()
uses: ./
with:
name: 2-with-root
path: test-root.txt
retention-days: 1
- name: 3. Artifact with Root and Sub1 no Sub2
if: always()
uses: ./
with:
name: 3-with-root-sub2-no-sub1
path: |
test-root.txt
subfolder/
!subfolder/test-sub2.txt
retention-days: 1
- name: 4. Artifact with Sub Sub files
if: always()
uses: ./
with:
name: 4-with-sub-sub-files
path: |
subfolder/sub-subfolder
retention-days: 1
- name: Show Results from Previous Step Tests
if: always()
shell: python
run: |
import os
import sys
import zipfile
def unzip_file(name: str, out_path: str):
print("")
print(f"{out_path} - Unzipping {name}")
os.makedirs(out_path, exist_ok=True)
with zipfile.ZipFile(name, 'r') as zip_ref:
zip_ref.extractall(out_path)
def check_file_exists(name: str, out_path: str) -> bool:
has_file = os.path.exists(os.path.join(out_path, name))
return has_file
def fail_workflow(out_dir: str, name_expected: dict) -> bool:
print("-----------------------------------------------------------------------")
should_fail = False
for name, expected in name_expected.items():
file_exists = check_file_exists(name, out_dir)
outcome = "PASS" if expected == file_exists else "FAIL"
print(f"{outcome} - Expected to find {name}? {expected}")
if file_exists != expected:
should_fail = True
print("-----------------------------------------------------------------------")
return should_fail
dir_sub = "subfolder"
dir_sub_sub = "subfolder/sub-subfolder"
file_root = "test-root.txt"
file_sub1 = "test-sub1.txt"
file_sub2 = "test-sub2.txt"
file_sub_sub2 = "test-sub-sub2.txt"
test_1 = "1-with-sub1-and-sub2.zip"
out_1 = "Test-1"
unzip_file(test_1, out_1)
fail_1 = fail_workflow(
out_1,
{
file_root: False,
file_sub1: True,
file_sub2: True,
dir_sub: False,
}
)
test_2 = "2-with-root.zip"
out_2 = "Test-2"
unzip_file(test_2, out_2)
fail_2 = fail_workflow(
out_2,
{
file_root: True,
file_sub1: False,
file_sub2: False
}
)
test_3 = "3-with-root-sub2-no-sub1.zip"
out_3 = "Test-3"
unzip_file(test_3, out_3)
fail_3 = fail_workflow(
out_3,
{
file_root: True,
file_sub1: True,
file_sub2: False,
dir_sub: False,
}
)
test_4 = "4-with-sub-sub-files.zip"
out_4 = "Test-4"
unzip_file(test_4, out_4)
fail_4 = fail_workflow(
out_4,
{
file_root: False,
file_sub1: False,
file_sub2: False,
file_sub_sub2: True,
dir_sub: False,
dir_sub_sub: False,
}
)
if fail_1 or fail_2 or fail_3 or fail_4:
print("ERROR: One or more zip file checks failed")
sys.exit(1)