mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-28 05:56:01 -04:00

Former-commit-id: b0949c8d8eaa55c73df0757b86fce288d11911b0 [formerly 16a4238ed1fb4c88be97f24926d61f5526e665f2] [formerly b25a43428a0ffc6341004a1bae1bbbf913fc943c] [formerly 8905110294c480812df0aa062455aff7e120162a [formerly e55efeb0ccf4018ed6dc88c4eead93a7bd70d8c4 [formerly 36b38db5d10a237534d1a1657b02196eed1acad1]]] Former-commit-id: 5f8dd8bf0eb1816bef8ffc76be73d5ad17c90776 [formerly 497a8314fab051c741d330b419c5b616babf8675 [formerly 014c372e24d8319f82ebbe77dbe220b74c2c18ad]] Former-commit-id: 3a1afc5e05afd4982d54725bdaed606b67be5e24 [formerly 5c5ac1fc484c2ce8b1786d0e66d8aa9d7e5daae9] Former-commit-id: 3b8870ea78a88e19e4cd0ec0e36d878d4c942d32
90 lines
3.0 KiB
PowerShell
90 lines
3.0 KiB
PowerShell
# Rewrites the draft release on the server to enable Electron cloud building
|
|
# Automatic if $INPUT_VERSION is provided, or else explicitly set $from and $to
|
|
|
|
[CmdletBinding()]
|
|
param (
|
|
[switch]$dryrun = $false,
|
|
[string]$from = '',
|
|
[string]$to = ''
|
|
)
|
|
if ($INPUT_TARGET -eq "nightly") {
|
|
$CRON_LAUNCHED = "1"
|
|
}
|
|
|
|
if ($INPUT_VERSION) {
|
|
$from = $INPUT_VERSION
|
|
if ($from -match '^v[0-9.]+(-WikiMed|-Wikivoyage)?$') {
|
|
$to = $from -replace '^(v[0-9.]+)(.*)$', '$1-E$2'
|
|
} elseif ($from -cmatch '^v[0-9.]+-E') {
|
|
$to = $from -creplace '-E', ''
|
|
}
|
|
}
|
|
|
|
if (-not $CRON_LAUNCHED) {
|
|
if (-not ($from -and $to)) {
|
|
"`nFrom and To inputs were not provided or could not be determeined automatically!"
|
|
exit 0
|
|
} else {
|
|
"Rewriting draft version from $from to $to..."
|
|
}
|
|
"`nChecking for a draft publishing target on GitHub..."
|
|
if (-not $GITHUB_TOKEN) {
|
|
$GITHUB_TOKEN = Get-Content -Raw "$PSScriptRoot/github_token"
|
|
}
|
|
$draft_release_params = @{
|
|
Uri = "https://api.github.com/repos/kiwix/kiwix-js-windows/releases"
|
|
Method = 'GET'
|
|
Headers = @{
|
|
'Authorization' = "token $GITHUB_TOKEN"
|
|
'Accept' = 'application/vnd.github.v3+json'
|
|
}
|
|
ContentType = "application/json"
|
|
}
|
|
$releases = Invoke-RestMethod @draft_release_params
|
|
$release_found = $false
|
|
$release = $null
|
|
$base_input = $INPUT_VERSION -replace '^(v[0-9.]+).*', '$1'
|
|
$releases | Where-Object { $release_found -eq $False } | % {
|
|
$release = $_
|
|
if (($release.draft -eq $true) -and ($release.tag_name -match $base_input)) {
|
|
$release_found = $true
|
|
}
|
|
}
|
|
if ($release_found) {
|
|
if ($dryrun) {
|
|
$release_json = $release | ConvertTo-Json
|
|
"[DRYRUN:] Draft release found: `n$release_json"
|
|
}
|
|
$release_body_json = @{
|
|
'tag_name' = "$to"
|
|
'draft' = $true
|
|
} | ConvertTo-Json
|
|
# Explicitly encode as UTF8 (or else it will fail with UTF8 characters)
|
|
# $release_body_json = ([System.Text.Encoding]::UTF8.GetBytes($release_body_json))
|
|
|
|
$release_params = @{
|
|
Uri = $release.url
|
|
Method = 'POST'
|
|
Headers = @{
|
|
'Authorization' = "token $GITHUB_TOKEN"
|
|
'Accept' = 'application/vnd.github.v3+json'
|
|
}
|
|
Body = $release_body_json
|
|
ContentType = "application/json"
|
|
}
|
|
# Post to the release server
|
|
if (-Not $dryrun) {
|
|
$release = Invoke-RestMethod @release_params
|
|
# Change the INPUT_VERSION
|
|
Set-Variable 'INPUT_VERSION' $to -Scope Global
|
|
"Posted rewrite request to server and setting INPUT_VERSION to $INPUT_VERSION...`n"
|
|
} else {
|
|
"[DRYRUN] Release Body:`n" + ($release_params | ConvertTo-Json)
|
|
}
|
|
|
|
} else {
|
|
"No draft release matching the tag $INPUT_VERSION was found."
|
|
}
|
|
}
|
|
|