Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Windows version variable when building #83

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ jobs:
$VER = yq e .version pubspec.yaml
echo "VERSION=$VER" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append

# Needed until Flutter progates this from pubspec automatically like
# it already does on other platforms.
- name: Update version variable on Windows
if: matrix.target == 'Windows'
run: |
$PUBSPEC = (Get-ChildItem -Path .\pubspec.yaml | Select-Object -Property FullName | Format-Wide | Out-String).trim()
$RUNNERRC = (Get-ChildItem -Path .\windows\runner\Runner.rc | Select-Object -Property FullName | Format-Wide | Out-String).trim()
dart run packaging/win32/update_windows_version_info/bin/update_windows_version_info.dart $PUBSPEC $RUNNERRC

- name: Verify pubspec version has been updated to match tag for release
if: |
github.event_name != 'pull_request' &&
Expand Down
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug win32 version updater",
"type": "dart",
"request": "launch",
"program": "packaging/win32/update_windows_version_info/bin/update_windows_version_info.dart",
"args": [
"/home/merritt/Development/nyrna/pubspec.yaml",
"/home/merritt/Development/nyrna/windows/runner/Runner.rc"
]
},
// Test current file
{
"name": "Test current file",
Expand Down
6 changes: 6 additions & 0 deletions packaging/win32/update_windows_version_info/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build output.
build/
3 changes: 3 additions & 0 deletions packaging/win32/update_windows_version_info/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial version.
2 changes: 2 additions & 0 deletions packaging/win32/update_windows_version_info/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A sample command-line application with an entrypoint in `bin/`, library code
in `lib/`, and example unit test in `test/`.
30 changes: 30 additions & 0 deletions packaging/win32/update_windows_version_info/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'dart:io';

import 'package:pub_semver/pub_semver.dart';
import 'package:yaml/yaml.dart';

/// Updates the `Runner.rc` file for the Windows build so it has the correct
/// version information. (windows/runner/Runner.rc)
///
/// Expects 2 arguments, the full paths for the pubspec & the Runner.rc
Future<void> main(List<String> args) async {
final pubspecPath = args[0];
final pubspecFile = File(pubspecPath);
final YamlMap pubspecYaml = loadYaml(await pubspecFile.readAsString());
final String version = pubspecYaml['version'];
final semVer = Version.parse(version);

final runnerRcPath = args[1];
final runnerRcFile = File(runnerRcPath);
String runnerRc = await runnerRcFile.readAsString();
runnerRc = runnerRc
.replaceAll(
RegExp(r'(?<=#define VERSION_AS_NUMBER )\d.*'),
'${semVer.major},${semVer.minor},${semVer.patch}',
)
.replaceAll(
RegExp(r'(?<=#define VERSION_AS_STRING ")\d.*(?=")'),
version,
);

await runnerRcFile.writeAsString(runnerRc);
}