-
Notifications
You must be signed in to change notification settings - Fork 13
143 lines (123 loc) · 4.6 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: CI
on:
pull_request:
types:
- opened
- synchronize
env:
HL7V2_PATTERN: '*/*'
UTILS_PATTERN: 'utils/*/*'
GITHUB_WORKFLOWS_DIR: '.github'
BALLERINA_VERSION: 2201.10.2
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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get changed files of PR from github API
CHANGED_FILES=$(gh api graphql -f query='
query($owner: String!, $repo: String!, $pr: Int!, $endCursor: String) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
files(first: 100, after: $endCursor) {
pageInfo{ hasNextPage, endCursor }
nodes {
path
}
}
}
}
}' -F owner='ballerina-platform' -F repo='module-ballerinax-health.hl7v2' -F pr=${{ github.event.pull_request.number }} --paginate --jq '.data.repository.pullRequest.files.nodes.[].path')
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 == $HL7V2_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: Set Up Ballerina
uses: ballerina-platform/[email protected]
with:
version: $BALLERINA_VERSION
- name: Ballerina Build
run: |
pushd "${{ matrix.path }}"
bal pack
popd
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: Set Up Ballerina
uses: ballerina-platform/[email protected]
with:
version: $BALLERINA_VERSION
- name: Ballerina Test
run: |
pushd "${{ matrix.path }}"
bal test --code-coverage
popd
- 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