Skip to content

Commit 888e63f

Browse files
committed
Update logic
1 parent 3719eb8 commit 888e63f

File tree

3 files changed

+162
-87
lines changed

3 files changed

+162
-87
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Get Mendix version from arguments
5+
mendix_version="$1"
6+
# Extract just the major.minor.patch part without any suffixes
7+
mendix_version_base=$(echo $mendix_version | sed -E 's/([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
8+
9+
echo "Mendix version: $mendix_version"
10+
echo "Mendix base version: $mendix_version_base"
11+
12+
# Find all matches based on version ranges in JSON
13+
matching_range=""
14+
highest_min_value=0
15+
16+
# Process each version range in the JSON
17+
while read -r range; do
18+
# Skip empty lines
19+
[ -z "$range" ] && continue
20+
21+
if [[ $range == \>=* ]]; then
22+
# Extract minimum version from range (e.g. ">=10.22.0" -> "10.22.0")
23+
min_version=${range#>=}
24+
25+
# Convert version to comparable numeric value
26+
IFS='.' read -r major minor patch <<< "$min_version"
27+
min_numeric=$((major*1000000 + minor*1000 + patch))
28+
29+
# Convert Mendix version to comparable numeric value
30+
IFS='.' read -r mx_major mx_minor mx_patch <<< "$mendix_version_base"
31+
mx_numeric=$((mx_major*1000000 + mx_minor*1000 + mx_patch))
32+
33+
# Check if Mendix version is greater than or equal to min version
34+
# AND if this is the highest minimum version we've seen so far
35+
if [ $mx_numeric -ge $min_numeric ] && [ $min_numeric -gt $highest_min_value ]; then
36+
matching_range="$range"
37+
highest_min_value=$min_numeric
38+
echo "Found matching range: $range (min_value: $min_numeric)"
39+
fi
40+
fi
41+
done < <(cat mendix_version.json | grep -o '"[^"]*":' | sed 's/"//g' | sed 's/://g')
42+
43+
if [ -n "$matching_range" ]; then
44+
echo "Best matching range: $matching_range"
45+
46+
# Extract the major version from max value
47+
max_pattern=$(cat mendix_version.json | grep -A 2 "\"$matching_range\":" | grep "\"max\":" | cut -d'"' -f4)
48+
major_version=$(echo "$max_pattern" | cut -d'.' -f1)
49+
50+
echo "Looking for latest version with major version: $major_version"
51+
52+
# Get available tags from native-template repository
53+
all_tags=$(curl -s https://api.github.com/repos/mendix/native-template/tags | grep '"name"' | cut -d'"' -f4)
54+
echo "Available tags: $all_tags"
55+
56+
# Find the latest version matching the major version
57+
latest_version=""
58+
highest_numeric=0
59+
60+
while read -r tag; do
61+
# Check for both tags with and without "v" prefix
62+
if [[ $tag == v$major_version.* || $tag == $major_version.* ]]; then
63+
echo "Found tag matching major version: $tag"
64+
65+
# Remove "v" prefix if present
66+
clean_tag=${tag#v}
67+
68+
# Convert version to numeric for comparison
69+
IFS='.' read -r t_major t_minor t_patch <<< "$clean_tag"
70+
# Handle cases where patch might contain non-numeric parts
71+
t_patch=$(echo "$t_patch" | sed 's/[^0-9].*$//')
72+
tag_numeric=$((t_major*1000000 + t_minor*1000 + t_patch))
73+
74+
echo "Tag numeric value: $tag_numeric"
75+
76+
if [ $tag_numeric -gt $highest_numeric ]; then
77+
highest_numeric=$tag_numeric
78+
latest_version="$tag"
79+
echo "New highest version: $latest_version ($highest_numeric)"
80+
fi
81+
fi
82+
done <<< "$all_tags"
83+
84+
if [ -n "$latest_version" ]; then
85+
echo "Selected Native Template version: $latest_version"
86+
echo "nt_branch=$latest_version" >> $GITHUB_OUTPUT
87+
else
88+
# Fallback to min version if no matching tag found
89+
min_version=$(cat mendix_version.json | grep -A 2 "\"$matching_range\":" | grep "\"min\":" | cut -d'"' -f4)
90+
echo "No matching tag found, using minimum version: $min_version"
91+
echo "nt_branch=$min_version" >> $GITHUB_OUTPUT
92+
fi
93+
else
94+
echo "No matching version range found, using master"
95+
echo "nt_branch=master" >> $GITHUB_OUTPUT
96+
fi
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Get parameters from arguments
5+
event_name="$1"
6+
input_workspace="$2"
7+
before_commit="$3"
8+
current_commit="$4"
9+
10+
# List of all native widgets
11+
all_widgets='["accordion-native","activity-indicator-native","animation-native","app-events-native","background-gradient-native","background-image-native","badge-native","bar-chart-native","barcode-scanner-native","bottom-sheet-native","carousel-native","color-picker-native","column-chart-native","feedback-native","floating-action-button-native","gallery-native","gallery-text-filter-native","image-native","intro-screen-native","line-chart-native","listview-swipe-native","maps-native","pie-doughnut-chart-native","popup-menu-native","progress-bar-native","progress-circle-native","qr-code-native","radio-buttons-native","range-slider-native","rating-native","repeater-native","safe-area-view-native","signature-native","slider-native","switch-native","toggle-buttons-native","video-player-native","web-view-native"]'
12+
13+
if [ "$event_name" == "pull_request" ]; then
14+
if git cat-file -e "$before_commit" 2>/dev/null; then
15+
changed_files=$(git diff --name-only "$before_commit" "$current_commit")
16+
else
17+
echo "Previous commit not found, using HEAD~1 as fallback"
18+
changed_files=$(git diff --name-only HEAD~1 "$current_commit")
19+
fi
20+
21+
selected_workspaces=""
22+
for file in $changed_files; do
23+
if [[ $file == packages/pluggableWidgets/* ]]; then
24+
widget=$(echo $file | cut -d'/' -f3)
25+
if [[ ! $selected_workspaces =~ $widget ]]; then
26+
selected_workspaces="$selected_workspaces $widget"
27+
fi
28+
fi
29+
done
30+
31+
# Trim leading and trailing spaces from selected_workspaces
32+
selected_workspaces=$(echo $selected_workspaces | xargs)
33+
34+
if [[ -n "$selected_workspaces" ]]; then
35+
echo "scope=--all --include '$selected_workspaces'" >> $GITHUB_OUTPUT
36+
echo "widgets=[\"$selected_workspaces\"]" >> $GITHUB_OUTPUT
37+
else
38+
echo "scope=--all --include '*-native'" >> $GITHUB_OUTPUT
39+
echo "widgets=${all_widgets}" >> $GITHUB_OUTPUT
40+
fi
41+
else
42+
if [ -n "$input_workspace" ] && [ "$input_workspace" != "*-native" ]; then
43+
selected_workspaces=$(echo "$input_workspace" | sed 's/,/ /g')
44+
echo "scope=--all --include '${selected_workspaces}'" >> $GITHUB_OUTPUT
45+
echo "widgets=[\"$input_workspace\"]" >> $GITHUB_OUTPUT
46+
else
47+
echo "scope=--all --include '*-native'" >> $GITHUB_OUTPUT
48+
echo "widgets=${all_widgets}" >> $GITHUB_OUTPUT
49+
fi
50+
fi
51+
52+
echo "Determined scope: $(cat $GITHUB_OUTPUT | grep scope= | cut -d= -f2)"
53+
echo "Widgets: $(cat $GITHUB_OUTPUT | grep widgets= | cut -d= -f2)"

.github/workflows/NativePipeline.yml

Lines changed: 13 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ on:
66
description: "Provide the SP version to be used (e.g., 10.14.0.43709) - has to be a released version (Default: latest from Mendix versions.json)"
77
required: false
88
default: ""
9-
109
nt_branch:
1110
description: "Native Template branch/tag to use (Leave empty to auto-select based on Mendix version)"
1211
default: ""
1312
required: false
1413
type: string
15-
1614
workspace:
1715
description: "Select a widget to test (Default will run all)"
1816
required: true
@@ -64,11 +62,8 @@ on:
6462
- cron: '0 0 * * *'
6563
# Trigger on PR
6664
# pull_request:
67-
68-
6965
permissions:
7066
packages: write
71-
7267
jobs:
7368
scope:
7469
runs-on: ubuntu-latest
@@ -80,56 +75,15 @@ jobs:
8075
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
8176
with:
8277
fetch-depth: 2 # Fetch the latest two commits and its parent commit
83-
8478
- name: "Determine scope"
8579
id: scope
8680
run: |
87-
if [ "${{ github.event_name }}" == "pull_request" ]; then
88-
if git cat-file -e ${{ github.event.before }} 2>/dev/null; then
89-
changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
90-
else
91-
echo "Previous commit not found, using HEAD~1 as fallback"
92-
changed_files=$(git diff --name-only HEAD~1 ${{ github.sha }})
93-
fi
94-
95-
selected_workspaces=""
96-
for file in $changed_files; do
97-
if [[ $file == packages/pluggableWidgets/* ]]; then
98-
widget=$(echo $file | cut -d'/' -f3)
99-
if [[ ! $selected_workspaces =~ $widget ]]; then
100-
selected_workspaces="$selected_workspaces $widget"
101-
fi
102-
fi
103-
done
104-
105-
# Trim leading and trailing spaces from selected_workspaces
106-
selected_workspaces=$(echo $selected_workspaces | xargs)
107-
108-
if [[ -n "$selected_workspaces" ]]; then
109-
echo "scope=--all --include '$selected_workspaces'" >> $GITHUB_OUTPUT
110-
echo "widgets=[\"$selected_workspaces\"]" >> $GITHUB_OUTPUT
111-
else
112-
widgets='["accordion-native","activity-indicator-native","animation-native","app-events-native","background-gradient-native","background-image-native","badge-native","bar-chart-native","barcode-scanner-native","bottom-sheet-native","carousel-native","color-picker-native","column-chart-native","feedback-native","floating-action-button-native","gallery-native","gallery-text-filter-native","image-native","intro-screen-native","line-chart-native","listview-swipe-native","maps-native","pie-doughnut-chart-native","popup-menu-native","progress-bar-native","progress-circle-native","qr-code-native","radio-buttons-native","range-slider-native","rating-native","repeater-native","safe-area-view-native","signature-native","slider-native","switch-native","toggle-buttons-native","video-player-native","web-view-native"]'
113-
echo "scope=--all --include '*-native'" >> $GITHUB_OUTPUT
114-
echo "widgets=${widgets}" >> $GITHUB_OUTPUT
115-
fi
116-
else
117-
if [ -n "${{ github.event.inputs.workspace }}" ] && [ "${{ github.event.inputs.workspace }}" != "*-native" ]; then
118-
selected_workspaces=$(echo "${{ github.event.inputs.workspace }}" | sed 's/,/ /g')
119-
echo "scope=--all --include '${selected_workspaces}'" >> $GITHUB_OUTPUT
120-
echo "widgets=[\"${{ github.event.inputs.workspace }}\"]" >> $GITHUB_OUTPUT
121-
else
122-
widgets='["accordion-native","activity-indicator-native","animation-native","app-events-native","background-gradient-native","background-image-native","badge-native","bar-chart-native","barcode-scanner-native","bottom-sheet-native","carousel-native","color-picker-native","column-chart-native","feedback-native","floating-action-button-native","gallery-native","gallery-text-filter-native","image-native","intro-screen-native","line-chart-native","listview-swipe-native","maps-native","pie-doughnut-chart-native","popup-menu-native","progress-bar-native","progress-circle-native","qr-code-native","radio-buttons-native","range-slider-native","rating-native","repeater-native","safe-area-view-native","signature-native","slider-native","switch-native","toggle-buttons-native","video-player-native","web-view-native"]'
123-
echo "scope=--all --include '*-native'" >> $GITHUB_OUTPUT
124-
echo "widgets=${widgets}" >> $GITHUB_OUTPUT
125-
fi
126-
fi
127-
81+
chmod +x ./.github/scripts/determine-widget-scope.sh
82+
./.github/scripts/determine-widget-scope.sh "${{ github.event_name }}" "${{ github.event.inputs.workspace }}" "${{ github.event.before }}" "${{ github.sha }}"
12883
- name: "Debug Scope Output"
12984
run: |
13085
echo "Scope is: ${{ steps.scope.outputs.scope }}"
13186
echo "Widgets are: ${{ steps.scope.outputs.widgets }}"
132-
13387
mendix-version:
13488
runs-on: ubuntu-22.04
13589
outputs:
@@ -154,14 +108,14 @@ jobs:
154108
- name: "Debug Mendix Version"
155109
run: |
156110
echo "Mendix Version: ${{ steps.set-mendix-version.outputs.MENDIX_VERSION }}"
157-
158-
159111
determine-nt-version:
160112
needs: [mendix-version]
161113
runs-on: ubuntu-latest
162114
outputs:
163-
nt_branch: ${{ steps.determine-nt-branch.outputs.nt_branch }}
115+
nt_branch: ${{ steps.set-output.outputs.nt_branch }}
164116
steps:
117+
- name: "Check out code"
118+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
165119
- name: "Check if nt_branch was specified"
166120
id: check-input
167121
run: |
@@ -173,58 +127,28 @@ jobs:
173127
echo "No nt_branch specified, will determine from mendix_version"
174128
echo "source=auto" >> $GITHUB_OUTPUT
175129
fi
176-
177130
- name: "Download mendix_version.json from native-template repo"
178131
if: steps.check-input.outputs.source == 'auto'
179132
run: |
180133
curl -s -o mendix_version.json https://raw.githubusercontent.com/mendix/native-template/master/mendix_version.json
181134
cat mendix_version.json
182-
183135
- name: "Determine Native Template version based on Mendix version"
184136
if: steps.check-input.outputs.source == 'auto'
185137
id: determine-nt-branch
186138
run: |
187-
mendix_version="${{ needs.mendix-version.outputs.mendix_version }}"
188-
# Extract just the major.minor.patch part without any suffixes
189-
mendix_version_base=$(echo $mendix_version | sed -E 's/([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
190-
191-
echo "Mendix version: $mendix_version"
192-
echo "Mendix base version: $mendix_version_base"
193-
194-
# Use jq to find the appropriate NT version
195-
nt_version=$(jq -r --arg mv "$mendix_version_base" '
196-
# Define version comparison function first
197-
def version_to_int(v): v | split(".") | map(tonumber) | .[0]*1000000 + .[1]*1000 + .[2];
198-
199-
# Convert input Mendix version to comparable format
200-
($mv | version_to_int) as $mv_int |
201-
202-
# Find matching range
203-
to_entries |
204-
map(
205-
select(
206-
(.value.min_mendix_version | version_to_int) <= $mv_int and
207-
(if .value.max_mendix_version then (.value.max_mendix_version | version_to_int) >= $mv_int else true end)
208-
)
209-
) |
210-
211-
# Get the latest matching NT version
212-
sort_by(.key | split(".") | map(tonumber)) |
213-
last |
214-
if . then .key else "master" end
215-
' mendix_version.json)
216-
217-
echo "Selected Native Template version: $nt_version"
218-
echo "nt_branch=$nt_version" >> $GITHUB_OUTPUT
219-
139+
chmod +x ./.github/scripts/determine-nt-version.sh
140+
./.github/scripts/determine-nt-version.sh "${{ needs.mendix-version.outputs.mendix_version }}"
220141
- name: "Set output nt_branch"
221142
id: set-output
222143
run: |
223144
if [[ "${{ steps.check-input.outputs.source }}" == "input" ]]; then
224-
echo "nt_branch=${{ steps.check-input.outputs.nt_branch }}" >> $GITHUB_OUTPUT
145+
echo "nt_branch=${{ github.event.inputs.nt_branch }}" >> $GITHUB_OUTPUT
225146
else
226147
echo "nt_branch=${{ steps.determine-nt-branch.outputs.nt_branch }}" >> $GITHUB_OUTPUT
227148
fi
149+
- name: "Debug final branch output"
150+
run: |
151+
echo "Final nt_branch value: ${{ steps.set-output.outputs.nt_branch }}"
228152
docker-images:
229153
needs: [mendix-version]
230154
runs-on: ubuntu-22.04
@@ -387,6 +311,8 @@ jobs:
387311
needs: [android-bundle, determine-nt-version]
388312
runs-on: ubuntu-22.04
389313
steps:
314+
- name: Debug branch value
315+
run: echo "Using branch ${{ needs.determine-nt-version.outputs.nt_branch }}"
390316
- name: "Check out Native Template for Native Components Test Project"
391317
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
392318
with:

0 commit comments

Comments
 (0)