From 10dadca91dd1da0252c377d4e5c024a96b28864d Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Wed, 3 Nov 2021 18:42:37 +0000 Subject: [PATCH] Update build scripts Former-commit-id: 3bb6a66bf4f5e624dc3fcf1c96c77f44a1e5842f [formerly 01c662d408455fc139a954c4fed8394f893cb0fd] [formerly b08926bd5c74057242c8ce131b454835d0f51705] [formerly e6e93cd679c794a271c22be07ef7d597415bff18 [formerly e273c12f37c948318957a581090a2a1c0edef5e2 [formerly 13e4f4ddd4b765b284ba7c37fca691b8fa345e9f]]] Former-commit-id: dab4e6ab06e941b36f8d4ec33e505ad69d1889d0 [formerly 208d30792569e484722985402726542afd7ee26e [formerly 65b52ddf576db8f9307f9f492468604bd5a70574]] Former-commit-id: 8df378564efe47b170de57d96f05ce01b76ad3f3 [formerly 6a9941ca496dbc5cccc17cd3f1b1517619da3fdd] Former-commit-id: 9ffe58aded8e0f7ef76a7e223f95b510c94e1af3 --- scripts/Build-DockerContainer.ps1 | 10 ++++----- scripts/Create-DraftRelease.ps1 | 34 +++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/scripts/Build-DockerContainer.ps1 b/scripts/Build-DockerContainer.ps1 index 3bca465d..c2e45ddb 100644 --- a/scripts/Build-DockerContainer.ps1 +++ b/scripts/Build-DockerContainer.ps1 @@ -20,22 +20,22 @@ if ($app_params -match 'params\[[''"]appVersion[''"]]\s*=\s*[''"]([^''"]+)') { $app_tag = $matches[1] $suggested_build = 'dev_' + $app_tag } else { - "*** WARNING: App version is incorrectly set in init.js.`nPlease correct before continuing.`n" + "`n*** WARNING: App version is incorrectly set in init.js.`nPlease correct before continuing.`n" exit } $sw_tag = '' if ($serviceworker -match 'appVersion\s*=\s*[''"]([^''"]+)') { $sw_tag = $matches[1] if ($sw_tag -ne $app_tag) { - "*** WARNING: The version in init.js [$app_tag] does not match the version in pwabuilder-sw.js [$sw_tag]! ***" + "`n*** WARNING: The version in init.js [$app_tag] does not match the version in pwabuilder-sw.js [$sw_tag]! ***" "Please correct before continuing.`n" exit } else { - "Version in init.js: $app_tag" - "Version in pwabuilder-sw.js: $sw_tag`n" + "`nVersion in init.js: $app_tag" + "Version in pwabuilder-sw.js: $sw_tag" } } else { - "*** WARNING: App version is incorrectly set in pwabuilder-sw.js.`nPlease correct before continuing.`n" + "`n*** WARNING: App version is incorrectly set in pwabuilder-sw.js.`nPlease correct before continuing.`n" exit } diff --git a/scripts/Create-DraftRelease.ps1 b/scripts/Create-DraftRelease.ps1 index 00ccfa4d..648581d4 100644 --- a/scripts/Create-DraftRelease.ps1 +++ b/scripts/Create-DraftRelease.ps1 @@ -17,9 +17,29 @@ $release_uri = 'https://api.github.com/repos/kiwix/kiwix-js-windows/releases' $github_token = Get-Content -Raw "$PSScriptRoot/github_token" $init_params = Get-Content -Raw "$PSScriptRoot\..\www\js\init.js" +$serviceworker = Select-String 'appVersion' "$PSScriptRoot\..\pwabuilder-sw.js" -List + $file_tag = '' -if ($init_params -match 'params\[[''"]version[''"]]\s*=\s*[''"]([^''"]+)') { +if ($init_params -match 'params\[[''"]appVersion[''"]]\s*=\s*[''"]([^''"]+)') { $file_tag = 'v' + $matches[1] +} else { + "*** WARNING: App version is incorrectly set in init.js.`nPlease correct before continuing.`n" + exit +} +$sw_tag = '' +if ($serviceworker -match 'appVersion\s*=\s*[''"]([^''"]+)') { + $sw_tag = 'v' + $matches[1] + if ($sw_tag -ne $file_tag) { + "*** WARNING: The version in init.js [$file_tag] does not match the version in pwabuilder-sw.js [$sw_tag]! ***" + "Please correct before continuing.`n" + exit + } else { + "`nVersion in init.js: $file_tag" + "Version in pwabuilder-sw.js: $sw_tag" + } +} else { + "*** WARNING: App version is incorrectly set in pwabuilder-sw.js.`nPlease correct before continuing.`n" + exit } if ($tag_name -eq "") { @@ -556,11 +576,13 @@ if ($dryrun -or $buildonly -or $release.assets_url -imatch '^https:') { if ($flavour -eq '_E') { $permalinkFile = $permalinkFile -replace 'uwp', 'electron' } "Looking for: $permalinkFile" foreach ($file in @($permalinkFile, $permalinkFile2)) { - $permalink = Get-Content -Raw $file - $permalink = $permalink -replace 'v[\d.EN]{5,}', "v$base_tag" - $permalink = $permalink -replace '\s*$', "`n" - if (-Not $dryrun) { Set-Content $file $permalink } - else { "`n[DRYRUN] would have written:`n$permalink`n" } + if ($file) { + $permalink = Get-Content -Raw $file + $permalink = $permalink -replace 'v[\d.EN]{5,}', "v$base_tag" + $permalink = $permalink -replace '\s*$', "`n" + if (-Not $dryrun) { Set-Content $file $permalink } + else { "`n[DRYRUN] would have written:`n$permalink`n" } + } } "Cleaning up..." if ((-Not ($dryrun -or $old_windows_support)) -and $compressed_archive ) { del $compressed_archive }