Implement pagination support #14
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: CI | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
env: | |
R4_PATTERN: '*/*' | |
UTILS_PATTERN: 'utils/*/*' | |
GITHUB_WORKFLOWS_DIR: '.github' | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
project-matrix: ${{ steps.unique-project-paths.outputs.BALLERINA_PROJECT_PATHS }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Extract Unique Ballerina Project Paths from Changed Files | |
id: unique-project-paths | |
run: | | |
# Get changed files of PR from github API | |
PR_DETAILS=$(curl -sSL \ | |
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files") | |
CHANGED_FILES=$(echo "$PR_DETAILS" | jq -r '.[].filename') | |
echo "Changed Files: " | |
echo "${CHANGED_FILES}" | |
# Convert CHANGED_FILES to an array | |
readarray -t CHANGED_FILES_ARRAY <<<"${CHANGED_FILES}" | |
# Remove duplicates from the CHANGED_FILES_ARRAY | |
declare -A UNIQUE_PATHS_MAP | |
for file in "${CHANGED_FILES_ARRAY[@]}"; do | |
if [[ $file == $UTILS_PATTERN ]]; then | |
EXTRACTED_PATH=$(echo "$file" | cut -d '/' -f 1-2) | |
elif [[ $file == $R4_PATTERN ]]; then | |
EXTRACTED_PATH=$(echo "$file" | cut -d '/' -f 1) | |
fi | |
if [[ $EXTRACTED_PATH && $EXTRACTED_PATH != $GITHUB_WORKFLOWS_DIR ]]; then | |
UNIQUE_PATHS_MAP[$EXTRACTED_PATH]=1 | |
fi | |
done | |
# Print the unique ballerina project paths | |
echo "Extracted Unique Ballerina Project Paths: " | |
for EXTRACTED_PATH in "${!UNIQUE_PATHS_MAP[@]}"; do | |
echo "$EXTRACTED_PATH" | |
done | |
# Create the JSON array with elements enclosed in double quotes | |
UNIQUE_PATHS_JSON=$(for key in "${!UNIQUE_PATHS_MAP[@]}"; do echo "\"$key\""; done | jq -s -c .) | |
echo "UNIQUE_PATHS_JSON: " | |
echo "${UNIQUE_PATHS_JSON}" | |
echo "BALLERINA_PROJECT_PATHS=${UNIQUE_PATHS_JSON}" >> $GITHUB_OUTPUT | |
build: | |
needs: [ setup ] | |
runs-on: ubuntu-latest | |
env: | |
JAVA_OPTS: -Xmx4G | |
if: ${{ needs.setup.outputs.project-matrix != '[]' }} | |
strategy: | |
matrix: | |
path: ${{ fromJson(needs.setup.outputs.project-matrix) }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Ballerina Build | |
uses: ballerina-platform/[email protected] | |
with: | |
args: pack | |
env: | |
WORKING_DIR: ./${{ matrix.path }} | |
JAVA_HOME: /usr/lib/jvm/default-jvm | |
test: | |
needs: [ setup ] | |
runs-on: ubuntu-latest | |
env: | |
JAVA_OPTS: -Xmx4G | |
if: ${{ needs.setup.outputs.project-matrix != '[]' }} | |
strategy: | |
matrix: | |
path: ${{ fromJson(needs.setup.outputs.project-matrix) }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Ballerina Test | |
uses: ballerina-platform/[email protected] | |
with: | |
args: test --code-coverage | |
env: | |
WORKING_DIR: ./${{ matrix.path }} | |
JAVA_HOME: /usr/lib/jvm/default-jvm | |
- name: Read Ballerina Test Results | |
id: test_results | |
run: | | |
if [ -f "./${{ matrix.path }}/target/report/test_results.json" ]; then | |
content=`cat ./${{ matrix.path }}/target/report/test_results.json` | |
content="${content//'%'/'%25'}" | |
content="${content//$'\n'/'%0A'}" | |
content="${content//$'\r'/'%0D'}" | |
echo "Covered Code Lines : $(echo "$content" | jq -r '.coveredLines')" | |
echo "Total Code Lines : $(echo "$content" | jq -r '.missedLines') + $(echo "$content" | jq -r '.coveredLines')" | |
echo "Code Coverage Percentage : $(echo "$content" | jq -r '.coveragePercentage')" | |
else | |
# echo "TEST_RESULTS_JSON=" >> $GITHUB_OUTPUT | |
echo "No test results file found." | |
fi |