diff options
| -rw-r--r-- | .github/workflows/android-app.yml | 1 | ||||
| -rw-r--r-- | .github/workflows/daemon.yml | 1 | ||||
| -rw-r--r-- | .gitignore | 1 | ||||
| -rwxr-xr-x | build.sh | 14 | ||||
| -rw-r--r-- | dist-assets/windows/version.h | 4 | ||||
| -rw-r--r-- | mullvad-version/src/main.rs | 51 | ||||
| -rwxr-xr-x | prepare-release.sh | 16 | ||||
| -rwxr-xr-x | version-metadata.sh | 97 | ||||
| -rw-r--r-- | windows/winfw/src/winfw/winfw.rc | 2 | ||||
| -rw-r--r-- | windows/winfw/src/winfw/winfw.vcxproj | 12 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/winnet.rc | 2 | ||||
| -rw-r--r-- | windows/winnet/src/winnet/winnet.vcxproj | 18 |
12 files changed, 87 insertions, 132 deletions
diff --git a/.github/workflows/android-app.yml b/.github/workflows/android-app.yml index 193f8f075f..8f4740de71 100644 --- a/.github/workflows/android-app.yml +++ b/.github/workflows/android-app.yml @@ -20,7 +20,6 @@ on: - build-apk.sh - update-api-metadata.sh - update-version-metadata.sh - - version-metadata.sh # Build if requested manually from the Actions tab workflow_dispatch: jobs: diff --git a/.github/workflows/daemon.yml b/.github/workflows/daemon.yml index beae485ded..c6ef2f1fff 100644 --- a/.github/workflows/daemon.yml +++ b/.github/workflows/daemon.yml @@ -29,7 +29,6 @@ on: - integration-tests.sh - prepare-release.sh - rustfmt.toml - - version-metadata.sh # Build if requested manually from the Actions tab workflow_dispatch: jobs: diff --git a/.gitignore b/.gitignore index 170e4589b4..8fbeebe0f4 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ /dist-assets/shell-completions/ /dist-assets/aarch64-apple-darwin/ /dist-assets/x86_64-apple-darwin/ +/windows/version.h /windows/**/bin/ /windows/**/*.user /android/keystore.properties @@ -153,20 +153,6 @@ fi log_header "Building Mullvad VPN $PRODUCT_VERSION" -function restore_metadata_backups { - pushd "$SCRIPT_DIR" > /dev/null - log_info "Restoring version metadata files..." - ./version-metadata.sh restore-backup --desktop - mv Cargo.lock.bak Cargo.lock || true - popd > /dev/null -} -trap 'restore_metadata_backups' EXIT - -log_info "Updating version in metadata files..." -cp Cargo.lock Cargo.lock.bak -./version-metadata.sh inject "$PRODUCT_VERSION" --desktop - - # Sign all binaries passed as arguments to this function function sign_win { local NUM_RETRIES=3 diff --git a/dist-assets/windows/version.h b/dist-assets/windows/version.h deleted file mode 100644 index 241c67d853..0000000000 --- a/dist-assets/windows/version.h +++ /dev/null @@ -1,4 +0,0 @@ -#define MAJOR_VERSION 2022 -#define MINOR_VERSION 5 -#define PATCH_VERSION 0 -#define PRODUCT_VERSION "2022.5-beta2" diff --git a/mullvad-version/src/main.rs b/mullvad-version/src/main.rs index 09f37880bb..a54914e6c2 100644 --- a/mullvad-version/src/main.rs +++ b/mullvad-version/src/main.rs @@ -4,11 +4,14 @@ use std::{env, process::exit}; const ANDROID_VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/android-product-version.txt")); +const VERSION_REGEX: &str = r"^20([0-9]{2})\.([1-9][0-9]?)(-beta([1-9][0-9]?))?(-dev-[0-9a-f]+)?$"; + fn main() { let command = env::args().nth(1); match command.as_deref() { None => println!("{}", mullvad_version::VERSION), Some("semver") => println!("{}", to_semver(mullvad_version::VERSION)), + Some("version.h") => println!("{}", to_windows_h_format(mullvad_version::VERSION)), Some("versionName") => println!("{ANDROID_VERSION}"), Some("versionCode") => println!("{}", to_android_version_code(ANDROID_VERSION)), Some(command) => { @@ -45,14 +48,50 @@ fn to_semver(version: &str) -> String { /// Version: 2021.34-beta5 /// versionCode: 21340005 fn to_android_version_code(version: &str) -> String { - let re = - Regex::new(r"^20([0-9]{2})\.([1-9][0-9]?)(-beta([1-9][0-9]?))?(-dev-[0-9a-f]+)?$").unwrap(); + let version = parse_version(version); + format!( + "{}{:0>2}00{:0>2}", + version.year, + version.incremental, + version.beta.unwrap_or_default() + ) +} + +fn to_windows_h_format(version: &str) -> String { + let Version { + year, incremental, .. + } = parse_version(version); + + format!( + "#define MAJOR_VERSION 20{year} +#define MINOR_VERSION {incremental} +#define PATCH_VERSION 0 +#define PRODUCT_VERSION \"{version}\"" + ) +} + +struct Version { + year: String, + incremental: String, + beta: Option<String>, +} + +fn parse_version(version: &str) -> Version { + let re = Regex::new(VERSION_REGEX).unwrap(); let captures = re .captures(version) .expect("Version does not match expected format"); - let year = captures.get(1).expect("Missing year").as_str(); - let incremental = captures.get(2).expect("Missing incremental").as_str(); - let beta = captures.get(4).map(|m| m.as_str()).unwrap_or_default(); + let year = captures.get(1).expect("Missing year").as_str().to_owned(); + let incremental = captures + .get(2) + .expect("Missing incremental") + .as_str() + .to_owned(); + let beta = captures.get(4).map(|m| m.as_str().to_owned()); - format!("{year}{:0>2}00{:0>2}", incremental, beta) + Version { + year, + incremental, + beta, + } } diff --git a/prepare-release.sh b/prepare-release.sh index 888f21a686..d7de34199d 100755 --- a/prepare-release.sh +++ b/prepare-release.sh @@ -62,12 +62,16 @@ if [[ "$ANDROID" == "true" && $(grep "^## \\[android/$PRODUCT_VERSION\\] - " CHA exit 1 fi -echo "Updating version in metadata files..." -./version-metadata.sh inject $PRODUCT_VERSION $VERSION_METADATA_ARGS - if [[ "$DESKTOP" == "true" ]]; then - git commit -S -m "Update desktop app versions to $PRODUCT_VERSION" \ - dist-assets/windows/version.h + echo "$PRODUCT_VERSION" > dist-assets/desktop-product-version.txt + git commit -S -m "Update desktop app version to $PRODUCT_VERSION" \ + dist-assets/desktop-product-version.txt +fi + +if [[ "$ANDROID" == "true" ]]; then + echo "$PRODUCT_VERSION" > dist-assets/android-product-version.txt + git commit -S -m "Update android app version to $PRODUCT_VERSION" \ + dist-assets/android-product-version.txt fi NEW_TAGS="" @@ -85,8 +89,6 @@ if [[ "$DESKTOP" == "true" ]]; then NEW_TAGS+=" $PRODUCT_VERSION" fi -./version-metadata.sh delete-backup - echo "=================================================" echo "| DONE preparing for a release! |" echo "| Now push the tag created by this script |" diff --git a/version-metadata.sh b/version-metadata.sh deleted file mode 100755 index eb5f93a02d..0000000000 --- a/version-metadata.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env bash -# -# Can inject correctly formatted version strings/numbers in all the various -# project metadata files. Can also back them up and restore them. - -set -eu - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd "$SCRIPT_DIR" - -# Parse arguments -COMMAND="$1" -shift 1 - -PRODUCT_VERSION="" -DESKTOP="false" -for argument in "$@"; do - case "$argument" in - "--desktop") - DESKTOP="true" - ;; - -*) - echo >&2 "Unknown option \"$argument\"" - exit 1 - ;; - *) - PRODUCT_VERSION="$argument" - ;; - esac -done - -function inject_version { - # Regex that only matches valid Mullvad VPN versions. It also captures - # relevant values into capture groups, read out via BASH_REMATCH[x]. - local VERSION_REGEX="^20([0-9]{2})\.([1-9][0-9]?)(-beta([1-9][0-9]?))?(-dev-[0-9a-f]+)?$" - - if [[ ! $PRODUCT_VERSION =~ $VERSION_REGEX ]]; then - echo >&2 "Invalid version format. Please specify version as:" - echo >&2 "<YEAR>.<NUMBER>[-beta<NUMBER>]" - return 1 - fi - - local semver_version - semver_version=$(echo "$PRODUCT_VERSION" | sed -Ee 's/($|-.*)/.0\1/g') - local semver_major="20${BASH_REMATCH[1]}" - local semver_minor=${BASH_REMATCH[2]} - local semver_patch="0" - - if [[ "$DESKTOP" == "true" ]]; then - # Windows C++ - cp dist-assets/windows/version.h dist-assets/windows/version.h.bak - cat <<EOF > dist-assets/windows/version.h -#define MAJOR_VERSION $semver_major -#define MINOR_VERSION $semver_minor -#define PATCH_VERSION $semver_patch -#define PRODUCT_VERSION "$PRODUCT_VERSION" -EOF - fi -} - -function restore_backup { - set +e - - if [[ "$DESKTOP" == "true" ]]; then - # Windows C++ - mv dist-assets/windows/version.h.bak dist-assets/windows/version.h - - fi - set -e -} - -function delete_backup { - set +e - - if [[ "$DESKTOP" == "true" ]]; then - # Windows C++ - rm dist-assets/windows/version.h.bak - - fi - set -e -} - -case "$COMMAND" in - "inject") - inject_version - ;; - "restore-backup") - restore_backup - ;; - "delete-backup") - delete_backup - ;; - *) - echo >&2 "Invalid command" - exit 1 - ;; -esac diff --git a/windows/winfw/src/winfw/winfw.rc b/windows/winfw/src/winfw/winfw.rc index 1e70710b75..a101cebb61 100644 --- a/windows/winfw/src/winfw/winfw.rc +++ b/windows/winfw/src/winfw/winfw.rc @@ -1,4 +1,4 @@ -#include "../../../../dist-assets/windows/version.h" +#include "../../../version.h" 1 VERSIONINFO FILEVERSION MAJOR_VERSION,MINOR_VERSION,PATCH_VERSION,0 diff --git a/windows/winfw/src/winfw/winfw.vcxproj b/windows/winfw/src/winfw/winfw.vcxproj index afdb8daec1..f13b019889 100644 --- a/windows/winfw/src/winfw/winfw.vcxproj +++ b/windows/winfw/src/winfw/winfw.vcxproj @@ -181,6 +181,9 @@ <AdditionalLibraryDirectories>$(SolutionDir)/bin/$(Platform)-$(Configuration)</AdditionalLibraryDirectories> <ModuleDefinitionFile>winfw.def</ModuleDefinitionFile> </Link> + <PreBuildEvent> + <Command>cargo run -q --bin mullvad-version version.h > $(ProjectDir)..\..\..\version.h</Command> + </PreBuildEvent> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ClCompile> @@ -201,6 +204,9 @@ <AdditionalLibraryDirectories>$(SolutionDir)/bin/$(Platform)-$(Configuration)</AdditionalLibraryDirectories> <ModuleDefinitionFile>winfw.def</ModuleDefinitionFile> </Link> + <PreBuildEvent> + <Command>cargo run -q --bin mullvad-version version.h > $(ProjectDir)..\..\..\version.h</Command> + </PreBuildEvent> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ClCompile> @@ -225,6 +231,9 @@ <AdditionalLibraryDirectories>$(SolutionDir)/bin/$(Platform)-$(Configuration)</AdditionalLibraryDirectories> <ModuleDefinitionFile>winfw.def</ModuleDefinitionFile> </Link> + <PreBuildEvent> + <Command>cargo run -q --bin mullvad-version version.h > $(ProjectDir)..\..\..\version.h</Command> + </PreBuildEvent> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ClCompile> @@ -249,6 +258,9 @@ <AdditionalLibraryDirectories>$(SolutionDir)/bin/$(Platform)-$(Configuration)</AdditionalLibraryDirectories> <ModuleDefinitionFile>winfw.def</ModuleDefinitionFile> </Link> + <PreBuildEvent> + <Command>cargo run -q --bin mullvad-version version.h > $(ProjectDir)..\..\..\version.h</Command> + </PreBuildEvent> </ItemDefinitionGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/windows/winnet/src/winnet/winnet.rc b/windows/winnet/src/winnet/winnet.rc index 253d011bc1..0509b4a59e 100644 --- a/windows/winnet/src/winnet/winnet.rc +++ b/windows/winnet/src/winnet/winnet.rc @@ -1,4 +1,4 @@ -#include "../../../../dist-assets/windows/version.h" +#include "../../../version.h" 1 VERSIONINFO FILEVERSION MAJOR_VERSION,MINOR_VERSION,PATCH_VERSION,0 diff --git a/windows/winnet/src/winnet/winnet.vcxproj b/windows/winnet/src/winnet/winnet.vcxproj index c32fa0972a..e38fd0e4b1 100644 --- a/windows/winnet/src/winnet/winnet.vcxproj +++ b/windows/winnet/src/winnet/winnet.vcxproj @@ -173,6 +173,9 @@ <AdditionalLibraryDirectories>$(SolutionDir)/bin/$(Platform)-$(Configuration)</AdditionalLibraryDirectories> <AdditionalDependencies>libshared.lib;libcommon.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies> </Link> + <PreBuildEvent> + <Command>cargo run -q --bin mullvad-version version.h > $(ProjectDir)..\..\..\version.h</Command> + </PreBuildEvent> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|Win32'"> <ClCompile> @@ -197,6 +200,9 @@ <AdditionalLibraryDirectories>$(SolutionDir)/bin/$(Platform)-Debug</AdditionalLibraryDirectories> <AdditionalDependencies>libshared.lib;libcommon.lib;Iphlpapi.lib</AdditionalDependencies> </Lib> + <PreBuildEvent> + <Command>cargo run -q --bin mullvad-version version.h > $(ProjectDir)..\..\..\version.h</Command> + </PreBuildEvent> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ClCompile> @@ -217,6 +223,9 @@ <AdditionalLibraryDirectories>$(SolutionDir)/bin/$(Platform)-$(Configuration)</AdditionalLibraryDirectories> <ModuleDefinitionFile>winnet.def</ModuleDefinitionFile> </Link> + <PreBuildEvent> + <Command>cargo run -q --bin mullvad-version version.h > $(ProjectDir)..\..\..\version.h</Command> + </PreBuildEvent> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Static|x64'"> <ClCompile> @@ -241,6 +250,9 @@ <AdditionalDependencies>libshared.lib;libcommon.lib;Iphlpapi.lib</AdditionalDependencies> <AdditionalLibraryDirectories>$(SolutionDir)/bin/$(Platform)-Debug</AdditionalLibraryDirectories> </Lib> + <PreBuildEvent> + <Command>cargo run -q --bin mullvad-version version.h > $(ProjectDir)..\..\..\version.h</Command> + </PreBuildEvent> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ClCompile> @@ -265,6 +277,9 @@ <AdditionalLibraryDirectories>$(SolutionDir)/bin/$(Platform)-$(Configuration)</AdditionalLibraryDirectories> <AdditionalDependencies>libshared.lib;libcommon.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies> </Link> + <PreBuildEvent> + <Command>cargo run -q --bin mullvad-version version.h > $(ProjectDir)..\..\..\version.h</Command> + </PreBuildEvent> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ClCompile> @@ -289,6 +304,9 @@ <AdditionalLibraryDirectories>$(SolutionDir)/bin/$(Platform)-$(Configuration)</AdditionalLibraryDirectories> <AdditionalDependencies>libshared.lib;libcommon.lib;Iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies> </Link> + <PreBuildEvent> + <Command>cargo run -q --bin mullvad-version version.h > $(ProjectDir)..\..\..\version.h</Command> + </PreBuildEvent> </ItemDefinitionGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> |
