From 91ecd4a97bc9ed58ae337b9704de9e0fb3d78d07 Mon Sep 17 00:00:00 2001 From: Ken Muse Date: Tue, 27 Aug 2024 14:03:17 -0400 Subject: [PATCH] Organization support in scripts --- .github/workflows/docker-image.yml | 16 +++++++++++++++- Dockerfile | 28 ++++++++++++++-------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 75ac965..f7c2330 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -51,7 +51,21 @@ jobs: # The org variable should be non-empty and match the owner name if this is an organization. $packageUrl = ($repoOwner -eq $orgName) ? "https://api.github.com/orgs/$repoOwner/packages/container/$repoName/versions" : "https://api.github.com/users/$repoOwner/packages/container/$repoName/versions" - $publishedImageVersions = $((Invoke-WebRequest -Headers @{ "Authorization"=$env:AUTH } -Uri $packageUrl).Content | ConvertFrom-Json) | %{ [PSCustomObject]@{ Id=$_.id; Url=$_.url;Tags=$_.metadata.container.tags } } | %{ $_.tags } + # PowerShell 7 syntax to avoid raising an exception. + $apiResults = Invoke-WebRequest -Headers @{ "Authorization"=$env:AUTH } -Uri $packageUrl -SkipHttpErrorCheck + if ($apiResults.StatusCode -eq 200) { + $content = $apiResults.Content | ConvertFrom-Json + } + elseif ($apiResults.StatusCode -eq 404) { + $content = @() + } + else { + Write-Host "Status Code: ${apiResults.StatusCode}" + Write-Host "Error: ${apiResults.Content}" + exit $apiResults.StatusCode + } + + $publishedImageVersions = $($apiResults.Content | ConvertFrom-Json) | %{ [PSCustomObject]@{ Id=$_.id; Url=$_.url;Tags=$_.metadata.container.tags } } | %{ $_.tags } $currentRunnerVersion = ((Invoke-WebRequest -Uri https://api.github.com/repos/actions/runner/releases/latest).Content | ConvertFrom-Json).tag_name -replace 'v','' $currentHooksVersion = ((Invoke-WebRequest -Uri https://api.github.com/repos/actions/runner-container-hooks/releases/latest).Content | ConvertFrom-Json).tag_name -replace 'v','' diff --git a/Dockerfile b/Dockerfile index 0b757d8..e853cfa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPrefe WORKDIR /home/runner -RUN ` +RUN <