mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-11 21:34:43 -04:00

Former-commit-id: 00e3265a28c63058a0d8d979ab2d2ec64dcb2a7a [formerly ae6b5bfb933c334ec51a53b5a2ebc518feee3b28] [formerly ea922a640c8d31a176cb911dd26a6899a080ddd4] [formerly bb06a5e197c9f9534442f82bb00c7cd1edb53519 [formerly 364ec55298f2fdae1942fd1b569fca0a223b6241 [formerly ed2db480ded880f871fd9deaa33cd2b61c16095b]]] Former-commit-id: 09deadadd51162f6da234c1786abe5ae83938406 [formerly 14c9c7000b4bac877a5bec4ae5688ff126732176 [formerly 74f24d304d2318fcc350a74e6db1dd24dc44ad16]] Former-commit-id: 19b0d7b3533ea5707282ca40d7467953878656d3 [formerly 065ebc78986f1782c2adf77803022e5e6aa2511b] Former-commit-id: 81751c8eb8c550ca4da6173afac9ff8a1087a8ba
121 lines
4.8 KiB
PowerShell
121 lines
4.8 KiB
PowerShell
# This is a utility script which helps developers choose sensible values for updating the online Docker-based implementation
|
|
# of this app while testing and developing code in a specific branch. It checks app.js and service-worker.js for consistency,
|
|
# and checks that that the underlying branch of a PR has been checked out (rather than the PR itself). It then calls the
|
|
# GitHub REST API for dispatching the workflow using the provided values.
|
|
#
|
|
# IMPORTANT: Ensure that your personal github token is in your local copy of the '/scripts' directory, saved as 'github_token'
|
|
#
|
|
# You may run this script with commandline switches -machine_name (this could be 'dev'), the -branch_name, and -dryrun (this
|
|
# will show the changes that would be made if run without the -dryrun switch). Alternatively, if you do not provide these
|
|
# values, you will be prompted with sensible defaults.
|
|
|
|
# Prevents execution with unrecognized switches
|
|
[CmdletBinding()]
|
|
param (
|
|
[string]$machine_name = "",
|
|
[string]$branch_name = "",
|
|
[switch]$dryrun = $false
|
|
)
|
|
|
|
# Provide parameters
|
|
$release_uri = 'https://api.github.com/repos/kiwix/kiwix-js-windows/actions/workflows/publish-docker.yaml/dispatches'
|
|
|
|
$app_params = Select-String 'appVersion' "$PSScriptRoot\..\www\js\init.js" -List
|
|
$serviceworker = Select-String 'appVersion' "$PSScriptRoot\..\service-worker.js" -List
|
|
$suggested_build = ''
|
|
$app_tag = ''
|
|
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"
|
|
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 service-worker.js [$sw_tag]! ***"
|
|
"Please correct before continuing.`n"
|
|
exit
|
|
} else {
|
|
"`nVersion in init.js: $app_tag"
|
|
"Version in service-worker.js: $sw_tag`n"
|
|
}
|
|
} else {
|
|
"*** WARNING: App version is incorrectly set in service-worker.js.`nPlease correct before continuing.`n"
|
|
exit
|
|
}
|
|
|
|
if (Test-Path $PSScriptRoot/github_token -PathType Leaf) {
|
|
$github_token = Get-Content -Raw "$PSScriptRoot/github_token"
|
|
} else {
|
|
Write-Warning "Missing file github_token! Please add it to $PSScriptRoot to run this script.`n"
|
|
$github_token = $false
|
|
}
|
|
|
|
if ($machine_name -eq "") {
|
|
if (-Not $dryrun) {
|
|
$dryrun_check = Read-Host "Is this a dry run? [Y/N]"
|
|
$dryrun = -Not ( $dryrun_check -imatch 'n' )
|
|
If ($dryrun) {
|
|
"[DRYRUN]: Initiating dry run..."
|
|
}
|
|
}
|
|
$machine_name = Read-Host "`nGive the name to use for the docker build, or Enter to accept suggested name [$suggested_build]"
|
|
""
|
|
if (-Not $machine_name) {
|
|
$machine_name = $suggested_build
|
|
$warning_message = "Please note that ""$app_tag"" will be used as the appVersion. If you want to change that, press Ctrl-C and re-run this script entering a build number matching 9.9.9."
|
|
} elseif ($machine_name -match '^v?[\d.]+') {
|
|
$warning_message = "*** Please be aware that you have entered a release tag matching the format 9.9.9* [$machine_name], and so it will be used as the appVersion of the container " +
|
|
"and will be visible to users. If this is NOT want you want, press Ctrl-C to abort this script, and re-run with the suggested build number."
|
|
}
|
|
if ($warning_message) { Write-Warning $warning_message }
|
|
}
|
|
|
|
if ($branch_name -eq "") {
|
|
$suggested_branch = &{ git branch --show-current }
|
|
$branch_name = Read-Host "`nGive the branch name to use of the docker build, or Enter to accept [$suggested_branch]"
|
|
if (-Not $branch_name) { $branch_name = $suggested_branch }
|
|
if ($branch_name -imatch '^pr/\d+') {
|
|
"`nWARNING: You appear to have indicated a PR. Please check out the underlying branch to use this script,`nor else run it again and give the branch name at the prompt.`n"
|
|
return
|
|
}
|
|
|
|
}
|
|
|
|
"`nMachine name set to: $machine_name"
|
|
"Branch name set to: $branch_name"
|
|
|
|
if (-Not $dryrun -and -Not $github_token) {
|
|
"`nSupply token to continue.`n"
|
|
exit
|
|
}
|
|
|
|
# Set up dispatch_params object - for API see https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event
|
|
$dispatch_params = @{
|
|
Uri = $release_uri
|
|
Method = 'POST'
|
|
Headers = @{
|
|
'Authorization' = "token $github_token"
|
|
'Accept' = 'application/vnd.github.v3+json'
|
|
}
|
|
Body = @{
|
|
'ref' = $branch_name
|
|
'inputs' = @{ 'version' = $machine_name }
|
|
} | ConvertTo-Json
|
|
ContentType = "application/json"
|
|
}
|
|
|
|
$dispatch_f = ($dispatch_params | Format-List | Out-String);
|
|
"`nDispatch parameters:`n$dispatch_f"
|
|
|
|
# Post to the release server
|
|
if (-Not $dryrun) {
|
|
Invoke-RestMethod @dispatch_params
|
|
"`nCheck for any error message above. An empty dispatch is normal, and indicates that the command was accepted.`n"
|
|
} else {
|
|
"[DRYRUN]: Complete.`n"
|
|
}
|