Skip to content

Commit c3305dd

Browse files
authored
Merge pull request #107 from skyeskie/auto_version
Automatically use Pubspec version number as basis for MSIX version
2 parents e18d433 + 0e87bd8 commit c3305dd

File tree

6 files changed

+91
-5
lines changed

6 files changed

+91
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 3.2.0
4+
5+
- Automatically use the Pubspec `version` tag by default. To use auto-versioning, remove any `msix_version` fields or command line options.
6+
37
## 3.1.6
48

59
### Breaking Changes

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ msix_config:
5151
logo_path: C:\path\to\logo.png
5252
capabilities: internetClient, location, microphone, webcam
5353
```
54+
See [Configurations Examples And Use Cases].
5455
5556
### Available Configurations
5657
@@ -126,7 +127,27 @@ msix_config:
126127

127128
</details>
128129

129-
See also [Configurations Examples And Use Cases].
130+
### Msix Version
131+
132+
The MSIX installer version number is used to determine updates to the app and consists of 4 numbers (`1.0.0.0`).
133+
134+
<details>
135+
136+
<summary>See more details on how to set the msix version (click to expand)</summary>
137+
138+
#### The version is determined by the first available option:
139+
140+
1. Command line `--version` flag
141+
2. In `pubspec.yaml`, under the `msix_config` node, the `msix_version` value
142+
3. Using the `version` field in `pubspec.yaml`.
143+
- The Pubspec version uses [semver], which is of the form `major.minor.patch-prerelease+build`
144+
- `msix` will use the `major.minor.patch` and append a `0` for the MSIX version
145+
- All prerelease and build info is discarded
146+
4. Fallback to `1.0.0.0`
147+
148+
By default, if you have a valid `version` in your `pubspec.yaml` file, that will form the basis for your MSIX installer version.
149+
150+
</details>
130151

131152
## :black_nib: Signing options
132153

@@ -227,4 +248,4 @@ Tags: `msi` `windows` `win10` `win11` `windows10` `windows11` `windows store` `w
227248
[disabled]: https://docs.microsoft.com/en-us/windows/msix/app-installer/installing-windows10-apps-web
228249
[self signed]: https://docs.microsoft.com/en-us/windows/msix/package/create-certificate-package-signing#create-a-self-signed-certificate
229250
[Configurations Examples And Use Cases]: https://pub.dev/packages/msix/example
230-
251+
[semver]: https://semver.org/

example/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ msix_config:
3434
###### For CI/CD:
3535
3636
```yaml
37+
name: flutter_app
38+
version: 1.3.2
39+
40+
# ...
41+
3742
msix_config:
3843
display_name: Flutter App
39-
msix_version: 1.0.1.0
4044
install_certificate: false
4145
```
46+
Note: The main app version will be used as a basis for the MSIX version (`1.3.2` to `1.3.2.0`)
4247

4348
###### With Metadata:
4449

lib/src/configuration.dart

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:args/args.dart' show ArgParser, ArgResults;
33
import 'package:cli_util/cli_logging.dart' show Logger;
44
import 'package:package_config/package_config.dart' show findPackageConfig;
55
import 'package:path/path.dart' show extension, basename;
6+
import 'package:pub_semver/pub_semver.dart';
67
import 'package:yaml/yaml.dart' show YamlMap, loadYaml;
78
import 'extensions.dart';
89

@@ -68,7 +69,8 @@ class Configuration {
6869
appName = pubspec['name'];
6970
appDescription = pubspec['description'];
7071
var yaml = pubspec['msix_config'] ?? YamlMap();
71-
msixVersion = _args['version'] ?? yaml['msix_version'];
72+
msixVersion =
73+
_args['version'] ?? yaml['msix_version'] ?? _getPubspecVersion(pubspec);
7274
certificatePath = _args['certificate-path'] ?? yaml['certificate_path'];
7375
certificatePassword = _args['certificate-password'] ??
7476
yaml['certificate_password']?.toString();
@@ -334,6 +336,25 @@ class Configuration {
334336
return pubspec;
335337
}
336338

339+
String? _getPubspecVersion(dynamic yaml) {
340+
// Existing behavior is to put null if no version, so matching
341+
if (yaml['version'] == null) return null;
342+
try {
343+
final pubspecVersion = Version.parse(yaml['version']);
344+
return [
345+
pubspecVersion.major,
346+
pubspecVersion.minor,
347+
pubspecVersion.patch,
348+
0
349+
].join('.');
350+
} on FormatException {
351+
_logger.stderr(
352+
'Warning: Could not parse Pubspec version. No version provided.',
353+
);
354+
return null;
355+
}
356+
}
357+
337358
/// Get the languages list
338359
Iterable<String>? _getLanguages(dynamic config) =>
339360
((_args['languages'] ?? config['languages']) as String?)

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: msix
22
description: A command-line tool that create Msix installer from your flutter windows-build files.
3-
version: 3.1.6
3+
version: 3.2.0
44
maintainer: Yehuda Kremer (yehudakremer@gmail.com)
55
homepage: https://github.com/YehudaKremer/msix
66

test/configuration_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,41 @@ msix_config:
123123
await customConfig.getConfigValues();
124124
expect(config.msixVersion, isNull);
125125
});
126+
127+
test('fallback to pubspec version', () async {
128+
await File(yamlTestPath).writeAsString(
129+
'name: testAppWithVersion\n'
130+
'version: 1.1.3',
131+
);
132+
await config.getConfigValues();
133+
expect(config.msixVersion, equals('1.1.3.0'));
134+
});
135+
136+
test('ignores extra semver info in pubspec version', () async {
137+
await File(yamlTestPath).writeAsString(
138+
'name: testAppWithVersion\n'
139+
'version: 0.8.13-alpha.1+2000-01-01',
140+
);
141+
await config.getConfigValues();
142+
expect(config.msixVersion, equals('0.8.13.0'));
143+
});
144+
145+
test('puts version null on invalid semver', () async {
146+
await File(yamlTestPath).writeAsString(
147+
'name: invalidSemverApp\n'
148+
'version: 0.8.13a',
149+
);
150+
await config.getConfigValues();
151+
expect(config.msixVersion, isNull);
152+
});
153+
154+
test('no version provided - null then maps to 1.0.0.0', () async {
155+
await File(yamlTestPath).writeAsString(yamlContent);
156+
await config.getConfigValues();
157+
expect(config.msixVersion, isNull);
158+
await config.validateConfigValues();
159+
expect(config.msixVersion, equals('1.0.0.0'));
160+
});
126161
});
127162

128163
group('certificate:', () {

0 commit comments

Comments
 (0)