-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
110 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { basename } from 'path'; | ||
|
||
// Function to check if a directory is excluded | ||
function isExcluded(dir, excludeDirs) { | ||
return excludeDirs.some((exclude) => dir.includes(exclude)); | ||
} | ||
|
||
// Function to generate JSON object for each directory | ||
function generateJson(dir) { | ||
const name = basename(dir); | ||
let type = ''; | ||
let syntax = ''; | ||
let api = ''; | ||
|
||
if (dir.includes('/examples/')) { | ||
type = 'ex'; | ||
} else if (dir.includes('/property/')) { | ||
type = 'prop'; | ||
if (dir.includes('/candid_rpc/')) { | ||
syntax = 'crpc'; | ||
if (dir.includes('/functional_api/')) { | ||
api = 'functional'; | ||
} else if (dir.includes('/class_api/')) { | ||
api = 'class'; | ||
} | ||
} else if (dir.includes('/ic_api/')) { | ||
syntax = 'ic_api'; | ||
} | ||
} else if (dir.includes('/end_to_end/')) { | ||
type = 'e2e'; | ||
if (dir.includes('/http_server/')) { | ||
syntax = 'http'; | ||
} else if (dir.includes('/candid_rpc/')) { | ||
syntax = 'crpc'; | ||
} | ||
} | ||
|
||
return { | ||
path: dir, | ||
name: name, | ||
type: type, | ||
...(syntax && { syntax: syntax }), | ||
...(api && { api: api }) | ||
}; | ||
} | ||
|
||
// Get input from the command-line arguments | ||
const directories = process.argv[2].split(' ').filter((path) => path !== ''); | ||
const excludeDirs = process.argv[3].split(',').filter((path) => path !== ''); | ||
|
||
// Filter directories and generate JSON | ||
const jsonArray = directories | ||
.filter((dir) => dir && !isExcluded(dir, excludeDirs)) | ||
.map((dir) => generateJson(dir)); | ||
|
||
// Output the final JSON string | ||
console.log(JSON.stringify(jsonArray)); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
# Inputs from action.yml or environment variables | ||
DIRECTORIES=($INPUT_DIRECTORIES) | ||
EXCLUDE_DIRS=($INPUT_EXCLUDE_DIRS) | ||
|
||
# Function to discover test directories | ||
discover_directories() { | ||
local dir=$1 | ||
find "$dir" -type d -not -path "*/node_modules/*" -exec sh -c ' | ||
for pkg in "$@"; do | ||
if [ -f "$pkg/package.json" ]; then | ||
if jq -e ".scripts.test" "$pkg/package.json" > /dev/null; then | ||
echo "$pkg" | ||
fi | ||
fi | ||
done | ||
' sh {} + | ||
} | ||
|
||
# Discover directories in the provided directories, excluding specified directories | ||
all_directories="" | ||
for dir in "${DIRECTORIES[@]}"; do | ||
all_directories+=$(discover_directories "$dir") | ||
all_directories+=$'\n' | ||
done | ||
|
||
# Prepare the data to be passed into the JavaScript script | ||
sorted_directories=$(echo "$all_directories" | sort | tr '\n' ' ') # Convert into a space-separated string | ||
exclude_dirs=$(IFS=, ; echo "${EXCLUDE_DIRS[*]}") # Convert array to comma-separated | ||
|
||
# Call the JavaScript script with input directories and excluded directories | ||
json_result=$(node .github/actions/get_tests/generate_json.js "$sorted_directories" "$exclude_dirs") | ||
|
||
# Format the result | ||
result="${json_result//'%'/'%25'}" | ||
result="${result//$'\n'/'%0A'}" | ||
result="${result//$'\r'/'%0D'}" | ||
|
||
# Output the final result as base64 | ||
echo "$result" | base64 |
This file was deleted.
Oops, something went wrong.