Skip to content

Commit

Permalink
Add API directory test (#8141)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlgo11 authored Jul 30, 2024
1 parent 4dade42 commit 732594a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ jobs:
PGP_PASSWORD: ${{ secrets.PGP_PASSWORD }}
PGP_KEY_ID: ${{ steps.pgp.outputs.keyid }}

- name: Validate API file structure
run: bash tests/api_files.sh

- name: Prepare publish directory
run: |
rsync -av {robots.txt,api/} public/
Expand Down
30 changes: 30 additions & 0 deletions tests/api_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

status=0

# Expected files in directories
declare -A expected_files
expected_files[api/v3]="all.json all.json.sig call.json call.json.sig custom-hardware.json custom-hardware.json.sig custom-software.json custom-software.json.sig email.json email.json.sig regions.json regions.json.sig sms.json sms.json.sig tfa.json tfa.json.sig totp.json totp.json.sig u2f.json u2f.json.sig"
expected_files[api/v4]="all.json all.json.sig call.json call.json.sig custom-hardware.json custom-hardware.json.sig custom-software.json custom-software.json.sig email.json email.json.sig sms.json sms.json.sig totp.json totp.json.sig u2f.json u2f.json.sig"

# $1 = directory
# $2 = expected files (space-separated)
function checkFiles(){
dir="$1";
shift;
missing_files=();
for file in "$@"; do
[[ ! -f "${dir}/${file}" ]] && missing_files+=("$file");
done;
if [[ ${#missing_files[@]} -gt 0 ]]; then
echo "Directory '$dir' is missing the following files: ${missing_files[*]}"
status=1
fi
}

# Validate expected files in directories
for dir in "${!expected_files[@]}"; do
checkFiles "$dir" "${expected_files[$dir]}"
done

exit $status

0 comments on commit 732594a

Please sign in to comment.