gowalk-cicd 1.0.14 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -205,6 +205,29 @@ committed back. If the module computes its `versionCode` instead of declaring a
205
205
  literal, the action emits a `::warning::` and leaves the project's own value
206
206
  alone.
207
207
 
208
+ ### Gradle wrapper floor (Flutter apps)
209
+
210
+ The Flutter Gradle plugin refuses to apply to a project whose wrapper is older
211
+ than the SDK's floor:
212
+
213
+ ```
214
+ Your project's Gradle version (8.11.1) is lower than Flutter's minimum
215
+ supported version of 8.14.0.
216
+ ```
217
+
218
+ CI installs the current `stable` Flutter, so that floor rises on Flutter's
219
+ release cadence rather than the app's — every app in a fleet breaks on the same
220
+ day, long after the last commit that could have anticipated it. Before building,
221
+ the action reads the floor out of the runner's Flutter SDK and, when the
222
+ project's `gradle-wrapper.properties` is below it, rewrites `distributionUrl`
223
+ **in the checkout** with a `::warning::`. Same policy as the versionCode
224
+ rewrite: the edit is never committed back, so the project keeps whatever
225
+ version its authors chose. Commit the bump yourself to silence the warning.
226
+
227
+ (The rewritten name is verified against `services.gradle.org` because Gradle's
228
+ own naming is inconsistent across majors — `gradle-8.14-all.zip` but
229
+ `gradle-9.0.0-all.zip`.)
230
+
208
231
  ### iOS delivery
209
232
 
210
233
  The iOS composite action runs on `macos-15` and:
@@ -1 +1 @@
1
- 1.0.14
1
+ 1.0.15
@@ -1 +1 @@
1
- 1.0.14
1
+ 1.0.15
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env python3
2
+ """Raise a Flutter app's Gradle wrapper to the version its Flutter SDK requires.
3
+
4
+ The Flutter Gradle plugin refuses to apply when the project's wrapper is older
5
+ than the SDK's floor:
6
+
7
+ Your project's Gradle version (8.11.1) is lower than Flutter's minimum
8
+ supported version of 8.14.0.
9
+
10
+ CI installs the current `stable` Flutter, so that floor rises on Flutter's
11
+ release cadence, not the app's. Every app in a fleet then breaks on the same
12
+ day — long after the last commit that could have anticipated it.
13
+
14
+ This raises the wrapper inside the CI checkout, the same way the action already
15
+ rewrites versionCode there. The edit is never committed back; the project keeps
16
+ whatever version its authors chose, and the build stops depending on the
17
+ project having been touched since the last Flutter release.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import re
23
+ from pathlib import Path
24
+
25
+ # `stable` moves the floor over time, so read it from the SDK rather than
26
+ # hardcoding a number this file would have to chase.
27
+ _CHECKER = Path("packages/flutter_tools/gradle/src/main/kotlin/DependencyVersionChecker.kt")
28
+ _ERROR_VERSION = re.compile(r"errorGradleVersion\s*:\s*Version\s*=\s*Version\((\d+),\s*(\d+),\s*(\d+)\)")
29
+ _DISTRIBUTION = re.compile(r"^(distributionUrl=.*gradle-)([0-9]+(?:\.[0-9]+)*)(-(?:all|bin)\.zip)$", re.M)
30
+
31
+ Version = tuple[int, ...]
32
+
33
+
34
+ def parse_version(text: str) -> Version | None:
35
+ if not re.fullmatch(r"[0-9]+(\.[0-9]+)*", text or ""):
36
+ return None
37
+ return tuple(int(part) for part in text.split("."))
38
+
39
+
40
+ def _render(version: Version) -> str:
41
+ return ".".join(str(part) for part in version)
42
+
43
+
44
+ def _stripped(version: Version) -> str:
45
+ parts = list(version)
46
+ while len(parts) > 2 and parts[-1] == 0:
47
+ parts.pop()
48
+ return _render(tuple(parts))
49
+
50
+
51
+ def candidates(version: Version) -> list[str]:
52
+ """Distribution names to try, best guess first.
53
+
54
+ Gradle's naming is not consistent across majors: 8.x drops a trailing zero
55
+ patch (`gradle-8.14-all.zip`; `gradle-8.14.0-all.zip` is a 404) while 9.x
56
+ keeps it (`gradle-9.0.0-all.zip`; `gradle-9.0-all.zip` is a 404). Getting
57
+ this wrong swaps the error being fixed for a download failure that does not
58
+ look like our doing, so order by the observed rule and keep the other form
59
+ as a fallback.
60
+ """
61
+ stripped, full = _stripped(version), _render(version)
62
+ order = [full, stripped] if version and version[0] >= 9 else [stripped, full]
63
+ return list(dict.fromkeys(order))
64
+
65
+
66
+ def _exists(name: str) -> bool | None:
67
+ """True/False if the distribution could be checked, None if we could not."""
68
+ import urllib.error
69
+ import urllib.request
70
+
71
+ url = f"https://services.gradle.org/distributions/gradle-{name}-all.zip"
72
+ request = urllib.request.Request(url, method="HEAD")
73
+ try:
74
+ with urllib.request.urlopen(request, timeout=15) as response:
75
+ return response.status == 200
76
+ except urllib.error.HTTPError as exc:
77
+ return exc.code == 200
78
+ except OSError:
79
+ return None
80
+
81
+
82
+ def normalize(version: Version, probe=_exists) -> str:
83
+ """The distribution name to write into distributionUrl.
84
+
85
+ Probes services.gradle.org so a future naming change corrects itself; falls
86
+ back to the ordering in `candidates` when the network is unavailable, which
87
+ is no worse than not probing at all.
88
+ """
89
+ options = candidates(version)
90
+ for name in options:
91
+ if probe(name) is True:
92
+ return name
93
+ return options[0]
94
+
95
+
96
+ def flutter_minimum_gradle(flutter_root: Path) -> Version | None:
97
+ """The oldest Gradle this Flutter SDK will apply its plugin against."""
98
+ checker = flutter_root / _CHECKER
99
+ try:
100
+ match = _ERROR_VERSION.search(checker.read_text(encoding="utf-8"))
101
+ except OSError:
102
+ return None
103
+ if not match:
104
+ return None
105
+ return tuple(int(group) for group in match.groups())
106
+
107
+
108
+ def wrapper_properties(workspace: Path, gradle_root: Path | None = None) -> Path:
109
+ root = gradle_root or (workspace / "android")
110
+ return root / "gradle" / "wrapper" / "gradle-wrapper.properties"
111
+
112
+
113
+ def read_wrapper_version(properties: Path) -> Version | None:
114
+ try:
115
+ match = _DISTRIBUTION.search(properties.read_text(encoding="utf-8"))
116
+ except OSError:
117
+ return None
118
+ return parse_version(match.group(2)) if match else None
119
+
120
+
121
+ def set_wrapper_version(properties: Path, version: Version) -> bool:
122
+ try:
123
+ text = properties.read_text(encoding="utf-8")
124
+ except OSError:
125
+ return False
126
+ replaced, count = _DISTRIBUTION.subn(
127
+ lambda m: f"{m.group(1)}{normalize(version)}{m.group(3)}", text
128
+ )
129
+ if not count:
130
+ return False
131
+ properties.write_text(replaced, encoding="utf-8")
132
+ return True
133
+
134
+
135
+ def ensure_minimum(workspace: Path, flutter_root: Path, gradle_root: Path | None = None) -> str:
136
+ """Raise the wrapper to Flutter's floor. Returns a line for the build log."""
137
+ properties = wrapper_properties(workspace, gradle_root)
138
+ if not properties.is_file():
139
+ return ""
140
+ minimum = flutter_minimum_gradle(flutter_root)
141
+ if minimum is None:
142
+ return (
143
+ "::warning::Could not read Flutter's minimum Gradle version from "
144
+ f"{flutter_root}; leaving the wrapper alone"
145
+ )
146
+ current = read_wrapper_version(properties)
147
+ if current is None:
148
+ return f"::warning::No Gradle distributionUrl found in {properties}; leaving it alone"
149
+ if current >= minimum:
150
+ return f"Gradle wrapper {normalize(current)} meets Flutter's minimum {normalize(minimum)}"
151
+ if not set_wrapper_version(properties, minimum):
152
+ return f"::warning::Failed to rewrite the Gradle distributionUrl in {properties}"
153
+ return (
154
+ f"::warning::Gradle wrapper {normalize(current)} is below Flutter's minimum "
155
+ f"{normalize(minimum)}; raised it to {normalize(minimum)} for this build only. "
156
+ f"Commit the bump in {properties.name} to make it permanent."
157
+ )
@@ -4,9 +4,11 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  import os
7
+ import shutil
7
8
  import sys
8
9
  from pathlib import Path
9
10
 
11
+ import gradle_wrapper
10
12
  from android_config import (
11
13
  ConfigError,
12
14
  detect_package_name,
@@ -126,6 +128,22 @@ def apply_gradle_version(project, build_number: int, build_name: str) -> None:
126
128
  )
127
129
 
128
130
 
131
+ def flutter_root() -> Path | None:
132
+ """Where the runner's Flutter SDK lives.
133
+
134
+ flutter-action exports FLUTTER_ROOT; a self-hosted runner with Flutter
135
+ merely on PATH does not, so fall back to walking up from the binary
136
+ (<root>/bin/flutter).
137
+ """
138
+ declared = os.environ.get("FLUTTER_ROOT")
139
+ if declared:
140
+ return Path(declared)
141
+ binary = shutil.which("flutter")
142
+ if not binary:
143
+ return None
144
+ return Path(binary).resolve().parent.parent
145
+
146
+
129
147
  def main() -> None:
130
148
  workspace = Path(os.environ.get("GITHUB_WORKSPACE", ".")).resolve()
131
149
  env_path = Path(os.environ["GITHUB_ENV"])
@@ -151,6 +169,18 @@ def main() -> None:
151
169
  apply_gradle_version(
152
170
  project, build_number, os.environ.get("INPUT_BUILD_NAME") or ""
153
171
  )
172
+ else:
173
+ # Flutter refuses to apply its Gradle plugin to a wrapper older than
174
+ # the SDK's floor, and CI tracks `stable`, so that floor rises
175
+ # without the app changing. Raise it in the checkout rather than
176
+ # letting every app in the fleet break on Flutter's release day.
177
+ root = flutter_root()
178
+ if root is None:
179
+ print("::warning::Flutter SDK not found; skipping the Gradle wrapper check")
180
+ else:
181
+ message = gradle_wrapper.ensure_minimum(workspace, root)
182
+ if message:
183
+ print(message)
154
184
  except (ConfigError, KeyError, OSError) as exc:
155
185
  print(f"::error::{exc}")
156
186
  raise SystemExit(1) from exc
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env python3
2
+ """Tests for raising a Flutter app's Gradle wrapper to the SDK's floor."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import tempfile
7
+ import unittest
8
+ from pathlib import Path
9
+
10
+ import gradle_wrapper as gw
11
+
12
+ CHECKER_SOURCE = """
13
+ package com.flutter.gradle
14
+ object DependencyVersionChecker {
15
+ internal val warnGradleVersion: Version = Version(8, 7, 0)
16
+ internal val errorGradleVersion: Version = Version(8, 14, 0)
17
+ }
18
+ """
19
+
20
+ WRAPPER = (
21
+ "distributionBase=GRADLE_USER_HOME\n"
22
+ "distributionPath=wrapper/dists\n"
23
+ "distributionUrl=https\\://services.gradle.org/distributions/gradle-8.11.1-all.zip\n"
24
+ )
25
+
26
+
27
+ def never(_name: str) -> bool:
28
+ """Probe stub for tests: the network is never consulted."""
29
+ return False
30
+
31
+
32
+ class RenderTest(unittest.TestCase):
33
+ def test_eight_x_drops_a_trailing_zero_patch(self):
34
+ self.assertEqual(gw.candidates((8, 14, 0))[0], "8.14")
35
+
36
+ def test_nine_x_keeps_a_trailing_zero_patch(self):
37
+ # gradle-9.0-all.zip is a 404; gradle-9.0.0-all.zip is the real name.
38
+ self.assertEqual(gw.candidates((9, 0, 0))[0], "9.0.0")
39
+
40
+ def test_a_real_patch_is_never_stripped(self):
41
+ self.assertEqual(gw.candidates((8, 14, 3)), ["8.14.3"])
42
+
43
+ def test_the_other_spelling_stays_available_as_a_fallback(self):
44
+ self.assertIn("8.14.0", gw.candidates((8, 14, 0)))
45
+
46
+ def test_falls_back_to_the_first_candidate_without_network(self):
47
+ self.assertEqual(gw.normalize((8, 14, 0), probe=never), "8.14")
48
+
49
+ def test_a_successful_probe_wins_over_the_ordering(self):
50
+ self.assertEqual(
51
+ gw.normalize((8, 14, 0), probe=lambda name: name == "8.14.0"), "8.14.0"
52
+ )
53
+
54
+
55
+ class WrapperFileTest(unittest.TestCase):
56
+ def setUp(self):
57
+ self.tmp = tempfile.TemporaryDirectory()
58
+ self.workspace = Path(self.tmp.name)
59
+ self.properties = gw.wrapper_properties(self.workspace)
60
+ self.properties.parent.mkdir(parents=True)
61
+ self.properties.write_text(WRAPPER, encoding="utf-8")
62
+ self.flutter = self.workspace / "flutter"
63
+ checker = self.flutter / gw._CHECKER
64
+ checker.parent.mkdir(parents=True)
65
+ checker.write_text(CHECKER_SOURCE, encoding="utf-8")
66
+ self.addCleanup(self.tmp.cleanup)
67
+
68
+ def test_reads_the_declared_version(self):
69
+ self.assertEqual(gw.read_wrapper_version(self.properties), (8, 11, 1))
70
+
71
+ def test_reads_the_sdk_floor(self):
72
+ self.assertEqual(gw.flutter_minimum_gradle(self.flutter), (8, 14, 0))
73
+
74
+ def test_raises_a_wrapper_below_the_floor(self):
75
+ gw.set_wrapper_version(self.properties, (8, 14, 0))
76
+ self.assertEqual(gw.read_wrapper_version(self.properties), (8, 14,))
77
+ self.assertIn("gradle-8.14-all.zip", self.properties.read_text())
78
+
79
+ def test_preserves_a_bin_distribution(self):
80
+ self.properties.write_text(
81
+ WRAPPER.replace("-all.zip", "-bin.zip"), encoding="utf-8"
82
+ )
83
+ gw.set_wrapper_version(self.properties, (8, 14, 0))
84
+ self.assertIn("gradle-8.14-bin.zip", self.properties.read_text())
85
+
86
+ def test_leaves_a_wrapper_already_at_the_floor_alone(self):
87
+ self.properties.write_text(
88
+ WRAPPER.replace("8.11.1", "8.14.3"), encoding="utf-8"
89
+ )
90
+ message = gw.ensure_minimum(self.workspace, self.flutter)
91
+ self.assertIn("meets Flutter's minimum", message)
92
+ self.assertIn("gradle-8.14.3-all.zip", self.properties.read_text())
93
+
94
+ def test_warns_and_raises_when_below_the_floor(self):
95
+ message = gw.ensure_minimum(self.workspace, self.flutter)
96
+ self.assertTrue(message.startswith("::warning::"))
97
+ self.assertIn("8.11.1", message)
98
+ self.assertIn("gradle-8.14", self.properties.read_text())
99
+
100
+ def test_no_wrapper_is_not_an_error(self):
101
+ self.properties.unlink()
102
+ self.assertEqual(gw.ensure_minimum(self.workspace, self.flutter), "")
103
+
104
+ def test_unreadable_sdk_leaves_the_wrapper_untouched(self):
105
+ message = gw.ensure_minimum(self.workspace, self.workspace / "nope")
106
+ self.assertTrue(message.startswith("::warning::"))
107
+ self.assertIn("gradle-8.11.1-all.zip", self.properties.read_text())
108
+
109
+ def test_a_wrapper_without_a_distribution_url_is_left_alone(self):
110
+ self.properties.write_text("distributionBase=GRADLE_USER_HOME\n", encoding="utf-8")
111
+ message = gw.ensure_minimum(self.workspace, self.flutter)
112
+ self.assertIn("No Gradle distributionUrl", message)
113
+
114
+ def test_honours_an_explicit_gradle_root(self):
115
+ root = self.workspace / "nested"
116
+ properties = gw.wrapper_properties(self.workspace, root)
117
+ properties.parent.mkdir(parents=True)
118
+ properties.write_text(WRAPPER, encoding="utf-8")
119
+ gw.ensure_minimum(self.workspace, self.flutter, gradle_root=root)
120
+ self.assertIn("gradle-8.14", properties.read_text())
121
+
122
+
123
+ if __name__ == "__main__":
124
+ unittest.main()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gowalk-cicd",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Zero-config GitHub Actions delivery for iOS TestFlight and Android Google Play.",
5
5
  "type": "module",
6
6
  "bin": {