Skip to content

Commit 3c9e933

Browse files
authored
Automatically detect NT version based on MX version (#268)
2 parents 47a1052 + e0f8d8d commit 3c9e933

File tree

4 files changed

+200
-57
lines changed

4 files changed

+200
-57
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import sys
2+
import json
3+
import os
4+
import requests
5+
from packaging import version
6+
import re
7+
8+
mendix_version = sys.argv[1]
9+
mendix_version_base = re.match(r'(\d+\.\d+\.\d+)', mendix_version).group(1)
10+
11+
print(f"Mendix version: {mendix_version}")
12+
print(f"Mendix base version: {mendix_version_base}")
13+
14+
# Parse the JSON file
15+
try:
16+
with open('mendix_version.json', 'r') as file:
17+
version_data = json.load(file)
18+
except FileNotFoundError:
19+
print("mendix_version.json not found")
20+
sys.exit(1)
21+
22+
# Find the best matching version range
23+
best_match = None
24+
highest_min_version = version.parse("0.0.0")
25+
mendix_version_obj = version.parse(mendix_version_base)
26+
27+
for range_str, data in version_data.items():
28+
if range_str.startswith(">="):
29+
min_ver_str = range_str[2:]
30+
min_ver = version.parse(min_ver_str)
31+
32+
if mendix_version_obj >= min_ver and min_ver > highest_min_version:
33+
best_match = range_str
34+
highest_min_version = min_ver
35+
print(f"Found matching range: {range_str}")
36+
37+
if best_match:
38+
print(f"Best matching range: {best_match}")
39+
40+
# Get the major version to look for in tags
41+
max_pattern = version_data[best_match].get("max", "")
42+
major_version = max_pattern.split('.')[0]
43+
44+
print(f"Looking for latest version with major version: {major_version}")
45+
46+
# Get available tags from native-template repository
47+
response = requests.get('https://api.github.com/repos/mendix/native-template/tags')
48+
if response.status_code == 200:
49+
all_tags = response.json()
50+
tag_names = [tag['name'] for tag in all_tags]
51+
print(f"Available tags: {tag_names}")
52+
53+
# Find the latest version matching the major version
54+
matching_tags = []
55+
56+
for tag in tag_names:
57+
# Remove 'v' prefix if present for comparison
58+
clean_tag = tag[1:] if tag.startswith('v') else tag
59+
60+
# Check if the tag starts with the major version
61+
if clean_tag.startswith(f"{major_version}."):
62+
try:
63+
# Try to parse as a version (this handles proper version numbers)
64+
tag_version = version.parse(clean_tag)
65+
matching_tags.append((tag, tag_version))
66+
except:
67+
# Skip tags that don't parse as proper versions
68+
pass
69+
70+
if matching_tags:
71+
# Sort by version (highest last) and get the last one
72+
matching_tags.sort(key=lambda x: x[1])
73+
latest_version = matching_tags[-1][0]
74+
print(f"Selected Native Template version: {latest_version}")
75+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
76+
f.write(f"nt_branch={latest_version}\n")
77+
else:
78+
# Fallback to min version if no matching tag found
79+
min_version = version_data[best_match].get("min", "")
80+
print(f"No matching tag found, using minimum version: {min_version}")
81+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
82+
f.write(f"nt_branch={min_version}\n")
83+
else:
84+
print(f"Failed to get tags: {response.status_code}")
85+
print("Using master as fallback")
86+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
87+
f.write("nt_branch=master\n")
88+
else:
89+
print("No matching version range found, using master")
90+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
91+
f.write("nt_branch=master\n")
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: 55 additions & 56 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:
11-
description: "Native Template branch to use (Default: master)"
12-
default: "master"
10+
description: "Native Template branch/tag to use (Leave empty to auto-select based on Mendix version)"
11+
default: ""
1312
required: false
1413
type: string
15-
1614
workspace:
1715
description: "Select a widget to test (Default will run all)"
1816
required: true
@@ -59,13 +57,13 @@ on:
5957
- video-player-native
6058
- web-view-native
6159

60+
# Run at 0:00 UTC (2:00 AM CET time during summer, 1:00 AM during winter)
61+
schedule:
62+
- cron: '0 0 * * *'
6263
# Trigger on PR
6364
# pull_request:
64-
65-
6665
permissions:
6766
packages: write
68-
6967
jobs:
7068
scope:
7169
runs-on: ubuntu-latest
@@ -77,56 +75,15 @@ jobs:
7775
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
7876
with:
7977
fetch-depth: 2 # Fetch the latest two commits and its parent commit
80-
8178
- name: "Determine scope"
8279
id: scope
8380
run: |
84-
if [ "${{ github.event_name }}" == "pull_request" ]; then
85-
if git cat-file -e ${{ github.event.before }} 2>/dev/null; then
86-
changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
87-
else
88-
echo "Previous commit not found, using HEAD~1 as fallback"
89-
changed_files=$(git diff --name-only HEAD~1 ${{ github.sha }})
90-
fi
91-
92-
selected_workspaces=""
93-
for file in $changed_files; do
94-
if [[ $file == packages/pluggableWidgets/* ]]; then
95-
widget=$(echo $file | cut -d'/' -f3)
96-
if [[ ! $selected_workspaces =~ $widget ]]; then
97-
selected_workspaces="$selected_workspaces $widget"
98-
fi
99-
fi
100-
done
101-
102-
# Trim leading and trailing spaces from selected_workspaces
103-
selected_workspaces=$(echo $selected_workspaces | xargs)
104-
105-
if [[ -n "$selected_workspaces" ]]; then
106-
echo "scope=--all --include '$selected_workspaces'" >> $GITHUB_OUTPUT
107-
echo "widgets=[\"$selected_workspaces\"]" >> $GITHUB_OUTPUT
108-
else
109-
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"]'
110-
echo "scope=--all --include '*-native'" >> $GITHUB_OUTPUT
111-
echo "widgets=${widgets}" >> $GITHUB_OUTPUT
112-
fi
113-
else
114-
if [ -n "${{ github.event.inputs.workspace }}" ] && [ "${{ github.event.inputs.workspace }}" != "*-native" ]; then
115-
selected_workspaces=$(echo "${{ github.event.inputs.workspace }}" | sed 's/,/ /g')
116-
echo "scope=--all --include '${selected_workspaces}'" >> $GITHUB_OUTPUT
117-
echo "widgets=[\"${{ github.event.inputs.workspace }}\"]" >> $GITHUB_OUTPUT
118-
else
119-
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"]'
120-
echo "scope=--all --include '*-native'" >> $GITHUB_OUTPUT
121-
echo "widgets=${widgets}" >> $GITHUB_OUTPUT
122-
fi
123-
fi
124-
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 }}"
12583
- name: "Debug Scope Output"
12684
run: |
12785
echo "Scope is: ${{ steps.scope.outputs.scope }}"
12886
echo "Widgets are: ${{ steps.scope.outputs.widgets }}"
129-
13087
mendix-version:
13188
runs-on: ubuntu-22.04
13289
outputs:
@@ -151,9 +108,49 @@ jobs:
151108
- name: "Debug Mendix Version"
152109
run: |
153110
echo "Mendix Version: ${{ steps.set-mendix-version.outputs.MENDIX_VERSION }}"
154-
111+
determine-nt-version:
112+
needs: [mendix-version]
113+
runs-on: ubuntu-latest
114+
outputs:
115+
nt_branch: ${{ steps.set-output.outputs.nt_branch }}
116+
steps:
117+
- name: "Check out code"
118+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
119+
- name: "Check if nt_branch was specified"
120+
id: check-input
121+
run: |
122+
if [[ -n "${{ github.event.inputs.nt_branch }}" ]]; then
123+
echo "Using specified nt_branch: ${{ github.event.inputs.nt_branch }}"
124+
echo "nt_branch=${{ github.event.inputs.nt_branch }}" >> $GITHUB_OUTPUT
125+
echo "source=input" >> $GITHUB_OUTPUT
126+
else
127+
echo "No nt_branch specified, will determine from mendix_version"
128+
echo "source=auto" >> $GITHUB_OUTPUT
129+
fi
130+
- name: "Download mendix_version.json from native-template repo"
131+
if: steps.check-input.outputs.source == 'auto'
132+
run: |
133+
curl -s -o mendix_version.json https://raw.githubusercontent.com/mendix/native-template/master/mendix_version.json
134+
cat mendix_version.json
135+
- name: "Determine Native Template version based on Mendix version"
136+
if: steps.check-input.outputs.source == 'auto'
137+
id: determine-nt-branch
138+
run: |
139+
pip install requests packaging
140+
python ./.github/scripts/determine-nt-version.py "${{ needs.mendix-version.outputs.mendix_version }}"
141+
- name: "Set output nt_branch"
142+
id: set-output
143+
run: |
144+
if [[ "${{ steps.check-input.outputs.source }}" == "input" ]]; then
145+
echo "nt_branch=${{ github.event.inputs.nt_branch }}" >> $GITHUB_OUTPUT
146+
else
147+
echo "nt_branch=${{ steps.determine-nt-branch.outputs.nt_branch }}" >> $GITHUB_OUTPUT
148+
fi
149+
- name: "Debug final branch output"
150+
run: |
151+
echo "Final nt_branch value: ${{ steps.set-output.outputs.nt_branch }}"
155152
docker-images:
156-
needs: mendix-version
153+
needs: [mendix-version]
157154
runs-on: ubuntu-22.04
158155
steps:
159156
- name: "Login to GitHub Container Registry"
@@ -311,14 +308,16 @@ jobs:
311308
platform: ios
312309
mda-file: automation.mda
313310
android-app:
314-
needs: [android-bundle]
311+
needs: [android-bundle, determine-nt-version]
315312
runs-on: ubuntu-22.04
316313
steps:
314+
- name: Debug branch value
315+
run: echo "Using branch ${{ needs.determine-nt-version.outputs.nt_branch }}"
317316
- name: "Check out Native Template for Native Components Test Project"
318317
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
319318
with:
320319
repository: mendix/native-template
321-
ref: ${{ github.event.inputs.nt_branch || 'master' }}
320+
ref: ${{ needs.determine-nt-version.outputs.nt_branch }}
322321
path: native-template
323322
- name: "Check out code"
324323
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
@@ -377,14 +376,14 @@ jobs:
377376
name: android-app
378377
path: native-template/android/app/build/outputs/apk/**/*.apk
379378
ios-app:
380-
needs: [ios-bundle]
379+
needs: [ios-bundle, determine-nt-version]
381380
runs-on: macos-13
382381
steps:
383382
- name: "Check out Native Template for Native Components Test Project"
384383
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
385384
with:
386385
repository: mendix/native-template
387-
ref: ${{ github.event.inputs.nt_branch || 'master' }}
386+
ref: ${{ needs.determine-nt-version.outputs.nt_branch }}
388387
path: native-template
389388
- name: "Check out code"
390389
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

configs/e2e/mendix-versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"latest": "10.21.1.64969",
2+
"latest": "10.22.0.68245",
33
"8": "8.18.23.62193"
44
}

0 commit comments

Comments
 (0)