kiwix-js-pwa/scripts/Build-DockerContainer.ps1
Jaifroid cd4bd67104 Update Build-DockerContainer.ps1
Former-commit-id: 15f3fcded51b3d144aad203afc65286283130acd [formerly 122b386115cd36e50417d9612b1b0482dc912ae5 [formerly 5b60c492ff2fc10e44728a7fa3e8dcae94f2cfe4]]
Former-commit-id: ce27f80e200b52b3155a4f2ea85a7d02241fbbc9
Former-commit-id: c3525c739a003f8e67762204a259efeb5f1b297c
2021-08-09 12:37:48 +03:00

66 lines
2.2 KiB
PowerShell

param (
[string]$tag_name = "",
[switch]$dryrun = $false
)
# DEV: To build the Docker container with a masnual dispatch (for testing only), provide an existing tag_name on master
# Provide parameters
$release_uri = 'https://api.github.com/repos/kiwix/kiwix-js-windows/actions/workflows/publish-docker.yaml/dispatches'
$github_token = Get-Content -Raw "$PSScriptRoot/github_token"
$init_params = Get-Content -Raw "$PSScriptRoot\..\www\js\init.js"
$suggested_build = ''
if ($init_params -match 'params\[[''"]version[''"]]\s*=\s*[''"]([^''"]+)') {
$suggested_build = 'v' + $matches[1]
}
if ($tag_name -eq "") {
$tag_name = Read-Host "`nGive the tag name to use for the docker build, or Enter to accept suggested tag, or add any suffix to suggested tag [$suggested_build]"
if ($tag_name -match '^[EN-]|^$') {
$split = $suggested_build -imatch '^([v\d.]+)(.*)$'
if ($split) {
$tag_name = $matches[1] + $tag_name + $matches[2]
# Clean up in case there was already a WikiMed or Wikivoyage suffix and we added one
$tag_name = $tag_name -replace '(\-[^\d.-]+)\-[^\d.]+$', '$1'
}
"Tag name set to: $tag_name"
}
if (-Not $dryrun) {
$dryrun_check = Read-Host "Is this a dry run? [Y/N]"
$dryrun = -Not ( $dryrun_check -imatch 'n' )
If ($dryrun) {
"Initiating dry run..."
}
}
}
if ($tag_name -NotMatch '^v\d+\.\d+\.\d+([EN-]|$)') {
"`nTag name must be in the format " + '"v0.0.0[E][N][-text]"!' + "`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' = "master"
'inputs' = @{ 'version' = $tag_name }
} | ConvertTo-Json
ContentType = "application/json"
}
# Post to the release server
if (-Not ($dryrun -or $buildonly -or $updatewinget)) {
$dispatch = Invoke-RestMethod @dispatch_params
} elseif (-Not $updatewinget) {
"[DRYRUN] Dispatch parameters:`n$dispatch_params`n$tag_name"
return
}
"`nServer returned: $dispatch"
"`nAn empty dispatch is normal, and indicates that the command was accepted.`n"