This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
PLPT-582 Updates to test workflow #97
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "DONE!" | |
- name: 1. Artifact with Sub1 and Sub2 | |
if: always() | |
uses: ./ | |
with: | |
name: with-sub1-and-sub2 | |
path: subfolder | |
retention-days: 1 | |
- name: 2. Artifact with Root | |
if: always() | |
uses: ./ | |
with: | |
name: with-root | |
path: test-root.txt | |
retention-days: 1 | |
- name: 3. Artifact with Root and Sub1 no Sub2 | |
if: always() | |
uses: ./ | |
with: | |
name: with-root-sub2-no-sub1 | |
path: | | |
test-root.txt | |
subfolder/ | |
!subfolder/test-sub2.txt | |
retention-days: 1 | |
- name: Test for Existence of zip files | |
if: always() | |
shell: python | |
run: | | |
import os | |
import sys | |
import zipfile | |
def unzip_file(name: str, out_path: str): | |
print("") | |
print(f"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) | |
print(f"Expected {name} to exist: {expected}. Does file exist? {file_exists}") | |
if file_exists != expected: | |
should_fail = True | |
print("-----------------------------------------------------------------------") | |
return should_fail | |
file_root = "test-root.txt" | |
file_sub1 = "subfolder/test-sub1.txt" | |
file_sub2 = "subfolder/test-sub2.txt" | |
test_1 = "with-sub1-and-sub2.zip" | |
out_1 = "test1" | |
unzip_file(test_1, out_1) | |
fail_1 = fail_workflow( | |
out_1, | |
{ | |
file_root: False, | |
file_sub1: True, | |
file_sub2: True | |
} | |
) | |
test_2 = "with-root.zip" | |
out_2 = "test2" | |
unzip_file(test_2, out_2) | |
fail_2 = fail_workflow( | |
out_2, | |
{ | |
file_root: True, | |
file_sub1: False, | |
file_sub2: False | |
} | |
) | |
test_3 = "with-root-sub2-no-sub1.zip" | |
out_3 = "test3" | |
unzip_file(test_3, out_3) | |
fail_3 = fail_workflow( | |
out_3, | |
{ | |
file_root: True, | |
file_sub1: True, | |
file_sub2: False | |
} | |
) | |
if fail_1 or fail_2 or fail_3: | |
print("ERROR: One or more zip file checks failed") | |
sys.exit(1) |