From 763f78c5bb44a257f6cb28d8cac7f039bcd5ffc2 Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Sat, 12 Jun 2021 11:04:38 +0100 Subject: [PATCH] Create Build-DockerContainer.ps1 Former-commit-id: 032028954b2ca85f55406133ccce423c4492e6a4 [formerly 7d83b45873a8ec01a4cd4d89034e596a6f9cce65 [formerly 5a87b6b92964ecf0ee82bf8dae873dba1153175e]] Former-commit-id: 70bc2b91db25bd69040eed4c5664d8ea08455153 Former-commit-id: 2618a0398ed042780c31f56eb88ba524184690e0 --- scripts/Build-DockerContainer.ps1 | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 scripts/Build-DockerContainer.ps1 diff --git a/scripts/Build-DockerContainer.ps1 b/scripts/Build-DockerContainer.ps1 new file mode 100644 index 00000000..0d6a9a77 --- /dev/null +++ b/scripts/Build-DockerContainer.ps1 @@ -0,0 +1,49 @@ +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" + +if ($tag_name -eq "") { + $tag_name = Read-Host "`nEnter the existing tag name to use for the manual docker build (e.g. 'v1.4.0')" + 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:`n$dispatch"