Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Test Zip Upload Artifact #72

Test Zip Upload Artifact

Test Zip Upload Artifact #72

name: Test Zip Upload Artifact
on:
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: |
mkdir "subfolder"
echo "################ Test Root ################" > test-root.txt
echo "################ Test Sub1 ################" > subfolder/test-sub1.txt
echo "################ Test Sub2 ################" > subfolder/test-sub2.txt
- 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-sub-2-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):
print(f"Unzipping {name}")
out_path = f"dir_{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:
if not out_path.startswith("dir_"):
out_path = f"dir_{out_path}"
has_file = os.path.exists(os.path.join(out_path, name))
print(f"Does {name} exist in {out_path}? {has_file}")
return has_file
def fail_workflow(out_dir: str, name_expected: dict) -> bool:
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
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"
unzip_file(test_1)
fail_1 = fail_workflow(
test_1,
{
file_root: False,
file_sub1: True,
file_sub2: True
}
)
test_2 = "with-root"
unzip_file(test_2)
fail_2 = fail_workflow(
test_2,
{
file_root: True,
file_sub1: False,
file_sub2: False
}
)
test_3 = "with-root-sub-2-no-sub1"
unzip_file(test_3)
fail_3 = fail_workflow(
test_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)