From 217947b9064abb5347e40765ae5180196d0534aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Vay=C3=A1?= Date: Tue, 11 Feb 2020 11:06:43 +0100 Subject: [PATCH] [MM-19636] make file names consistent (#1186) * added jq * add verbose message * add another option for getting the path of npm * use package.json to get desktop version * add componentdownload property as dinamic * fix innertext * add namespace to element * remove v from version --- scripts/Makefile.ps1 | 46 ++++++++++++++++++--------------------- scripts/dependencies.ps1 | 10 +++++++++ scripts/msi_installer.wxs | 7 ++++-- scripts/tools.ps1 | 5 +++++ 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/scripts/Makefile.ps1 b/scripts/Makefile.ps1 index e5ba939b..2b2e0079 100644 --- a/scripts/Makefile.ps1 +++ b/scripts/Makefile.ps1 @@ -184,51 +184,47 @@ function Run-BuildId { # candle.exe : error CNDL0001 : Value was either too large or too small for an Int32. # Exception Type: System.OverflowException # Add the revision only if we are not building a tag - - Print-Info "Checking build id tag..." - if ($env:APPVEYOR_REPO_TAG -eq $true) { - $version = "$env:APPVEYOR_REPO_TAG_NAME" - } else { - $version = "$(git describe --tags $(git rev-list --tags --max-count=1))" - } + + $version = "$(jq -r '.version' package.json)" + $winVersion = "$($version -Replace '-','.' -Replace '[^0-9.]')" Print-Info "Checking build id tag validity... [$version]" [version]$appVersion = New-Object -TypeName System.Version - [void][version]::TryParse($($version -Replace '-','.' -Replace '[^0-9.]'), [ref]$appVersion) + [void][version]::TryParse($winVersion, [ref]$appVersion) if (!($appVersion)) { - Print-Error "Non parsable tag detected. Fallbacking to version 0.0.0." - $version = "0.0.0" + # if we couldn't parse, it might be a -develop or something similar, so we just add a + # number there that will change overtime. Most likely this is a PR to be tested + $revision = "$(git rev-list --all --count)" + $winVersion = "$($version -Replace '-.*').${revision}" + [void][version]::TryParse($winVersion, [ref]$appVersion) + if (!($appVersion)) { + Print-Error "Non parsable tag detected. Fallbacking to version 0.0.0." + $version = "0.0.0" + } } Print-Info -NoNewLine "Getting build id version..." - $env:COM_MATTERMOST_MAKEFILE_BUILD_ID = $version + $env:COM_MATTERMOST_MAKEFILE_BUILD_ID = "$version" Print " [$env:COM_MATTERMOST_MAKEFILE_BUILD_ID]" Print-Info -NoNewLine "Getting build id version for msi..." - $env:COM_MATTERMOST_MAKEFILE_BUILD_ID_MSI = ($version -Replace '-','.' -Replace '[^0-9.]').Split('.')[0..3] -Join '.' + $env:COM_MATTERMOST_MAKEFILE_BUILD_ID_MSI = $winVersion.Split('.')[0..3] -Join '.' Print " [$env:COM_MATTERMOST_MAKEFILE_BUILD_ID_MSI]" Print-Info -NoNewLine "Getting build id version for node/npm..." - $env:COM_MATTERMOST_MAKEFILE_BUILD_ID_NODE = ($version -Replace '^v').Split('.')[0..2] -Join '.' + $env:COM_MATTERMOST_MAKEFILE_BUILD_ID_NODE = $version Print " [$env:COM_MATTERMOST_MAKEFILE_BUILD_ID_NODE]" Print-Info "Patching version from msi xml descriptor..." $msiDescriptorFileName = "scripts\msi_installer.wxs" $msiDescriptor = [xml](Get-Content $msiDescriptorFileName) $msiDescriptor.Wix.Product.Version = [string]$env:COM_MATTERMOST_MAKEFILE_BUILD_ID_MSI + $ComponentDownload = $msiDescriptor.CreateElement("Property", "http://schemas.microsoft.com/wix/2006/wi") + $ComponentDownload.InnerText = "https://releases.mattermost.com/desktop/$version/mattermost-desktop-$version-`$(var.Platform).msi" + $ComponentDownload.SetAttribute("Id", "ComponentDownload") + $msiDescriptor.Wix.Product.AppendChild($ComponentDownload) $msiDescriptor.Save($msiDescriptorFileName) - - Print-Info "Patching version from electron package.json..." - $packageFileName = "package.json" - $package = Get-Content $packageFileName -Raw | ConvertFrom-Json - $package.version = [string]$env:COM_MATTERMOST_MAKEFILE_BUILD_ID_NODE - $package | ConvertTo-Json | Set-Content $packageFileName - - Print-Info "Patching version from electron src\package.json..." - $packageFileName = "src\package.json" - $package = Get-Content $packageFileName -Raw | ConvertFrom-Json - $package.version = [string]$env:COM_MATTERMOST_MAKEFILE_BUILD_ID_NODE - $package | ConvertTo-Json | Set-Content $packageFileName + Print-Info "Modified Wix XML" } function Run-BuildChangelog { diff --git a/scripts/dependencies.ps1 b/scripts/dependencies.ps1 index 1b60e661..2e51dedf 100644 --- a/scripts/dependencies.ps1 +++ b/scripts/dependencies.ps1 @@ -64,6 +64,11 @@ function Check-Deps { if ($verbose) { Print-Error "signtool dependency missing." } $missing += "signtool" } + if ($verbose) { Print-Info "Checking jq dependency..." } + if (!(Check-Command "jq")) { + if ($verbose) { Print-Error "jq dependency missing." } + $missing += "jq" + } if ($throwable -and $missing.Count -gt 0) { throw "com.mattermost.makefile.deps.missing" @@ -128,6 +133,11 @@ function Install-Deps { choco install nodejs-lts --yes break; } + "jq" { + Print-Info "Installing jq" + choco install jq --yes + break; + } } Print-Info "Refreshing PATH..." diff --git a/scripts/msi_installer.wxs b/scripts/msi_installer.wxs index 23bab276..90584c49 100644 --- a/scripts/msi_installer.wxs +++ b/scripts/msi_installer.wxs @@ -35,7 +35,7 @@ - there are any changes in the feature hierarchy (child feature moving out of a parent, or a parent feature getting a new child). --> - + true true diff --git a/scripts/tools.ps1 b/scripts/tools.ps1 index c0ba5f28..69e6379a 100644 --- a/scripts/tools.ps1 +++ b/scripts/tools.ps1 @@ -158,6 +158,11 @@ function Get-NpmDir { if ([System.IO.File]::Exists("$npmDir\npm.cmd")) { return $npmDir } + $progFile = ${env:ProgramW6432} + $npmDir = Join-Path -Path "$progFile" -ChildPath "nodejs" + if ([System.IO.File]::Exists("$npmDir\npm.cmd")) { + return $npmDir + } return $null }