diff --git a/action.yml b/action.yml index e197118..f1c331e 100644 --- a/action.yml +++ b/action.yml @@ -28,11 +28,16 @@ inputs: outputs: dispatch-sent: description: "A value indicating whether a repository dispatch was sent" - value: ${{ steps.report-status.outputs.dispatch-sent }} + value: ${{ steps.check-image.outputs.SEND_DISPATCH }} + dispatch-payload: + description: "The payload data that was sent with the dispatch" + value: ${{ steps.check-image.outputs.OUTPUT_DISPATCH_PAYLOAD }} + runs: using: "composite" steps: - name: Check Image + id: check-image shell: pwsh run: | $ErrorActionPreference = 'Stop' @@ -46,16 +51,16 @@ runs: throw "'dockerfile' input not provided. This is required when 'base-image-name' is not provided." } - $dockerBumpCheckerVersion = "0.2.0" + $dockerBumpCheckerVersion = "dev" $containerName = "docker-bump-checker" $containerSrcPath = "/src" # The repo directory will be volume-mounted into the container so the Dockerfile path needs to be modified accordingly - $dockerfile = "$containerSrcPath/$dockerfile" $result = docker run ` --name $containerName ` -v ${env:GITHUB_WORKSPACE}:$containerSrcPath ` + -w $containerSrcPath ` ghcr.io/mthalman/docker-bump-checker:$dockerBumpCheckerVersion ` -BaseImage `"$baseImage`" ` -TargetImage `"$targetImage`" ` @@ -79,23 +84,36 @@ runs: if ($LASTEXITCODE -ne 0) { throw "command failed" } + + $result = $result | ConvertFrom-Json + + $actionPayload = "{}" + $outputPayload = "" + if ($result.sendDispatch -eq "true") { + $payloadObj = @{ + updates = $result.updates + } + + $actionPayload = ,$payloadObj | ConvertTo-Json -Compress + $outputPayload = $actionPayload + } - echo "SEND_DISPATCH=$result" >> "$env:GITHUB_ENV" + echo "SEND_DISPATCH=$($result.sendDispatch)" >> $env:GITHUB_OUTPUT + echo "ACTION_DISPATCH_PAYLOAD=$actionPayload" >> $env:GITHUB_OUTPUT + echo "OUTPUT_DISPATCH_PAYLOAD=$outputPayload" >> $env:GITHUB_OUTPUT - name: Repository Dispatch - if: env.SEND_DISPATCH == 'true' + if: ${{ steps.check-image.outputs.SEND_DISPATCH }} == 'true' uses: peter-evans/repository-dispatch@v3 with: token: ${{ inputs.token }} repository: ${{ inputs.repository }} event-type: ${{ inputs.event-type }} + client-payload: ${{ steps.check-image.outputs.DISPATCH_PAYLOAD }} - name: Report Status - id: report-status shell: pwsh run: | - if ($env:SEND_DISPATCH -eq "true") { + if ("${{ steps.check-image.outputs.SEND_DISPATCH }}" -eq "true") { echo "A repository dispatch was sent to '${{ inputs.repository }}' with event type '${{ inputs.event-type }}'." } else { echo "No repository dispatch was sent." } - - echo "dispatch-sent=$env:TRIGGER_WORKFLOW" >> "$env:GITHUB_OUTPUT" diff --git a/container/Dockerfile b/container/Dockerfile index 063b318..dd94bad 100644 --- a/container/Dockerfile +++ b/container/Dockerfile @@ -15,6 +15,7 @@ COPY --from=installer /usr/share/powershell /usr/share/powershell COPY --from=installer /root/.dotnet/tools /home/app/.dotnet/tools COPY --from=installer ["/symlinks", "/usr/bin"] COPY *.ps1 /scripts/ +COPY *.psm1 /scripts/ # Returns 'true' in the output if the image is out-of-date in relation to its base image; otherwise, 'false'. ENTRYPOINT ["pwsh", "-c", "/scripts/entrypoint.ps1"] diff --git a/container/check-image.ps1 b/container/check-image.ps1 index ed35fea..da9f046 100644 --- a/container/check-image.ps1 +++ b/container/check-image.ps1 @@ -7,23 +7,49 @@ param( [string]$BaseImage, [Parameter(Mandatory = $True)] - [string]$Architecture + [string]$Architecture, + + [string]$DockerfilePath ) $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' Set-StrictMode -Version 2.0 -Import-Module $PSScriptRoot/common.psm1 +function GetDigest($imageName) { + $digestCmd = "dredge manifest resolve $imageName --os linux --arch $Architecture" + $digest = $(InvokeTool $digestCmd "dredge manifest resolve failed") + return $digest +} -$cmd = "dredge image compare layers --output json $BaseImage $TargetImage --os linux --arch $Architecture" -$layerComparisonStr = $(InvokeTool $cmd "dredge image compare failed") +Import-Module $PSScriptRoot/common.psm1 +$compareCmd = "dredge image compare layers --output json $BaseImage $TargetImage --os linux --arch $Architecture" +$layerComparisonStr = $(InvokeTool $compareCmd "dredge image compare failed") $layerComparison = $layerComparisonStr | ConvertFrom-Json $imageUpToDate = [bool]$($layerComparison.summary.targetIncludesAllBaseLayers) $sendDispatch = ([string](-not $imageUpToDate)).ToLower() +$targetDigest = $(GetDigest $TargetImage) +$baseDigest = $(GetDigest $BaseImage) + LogMessage "Send dispatch: $sendDispatch" -return $sendDispatch +$updates = @() +if (-not $imageUpToDate) { + $updates += @{ + targetImageName = $TargetImage + targetImageDigest = $targetDigest + dockerfile = $DockerfilePath + baseImageName = $BaseImage + baseImageDigest = $baseDigest + } +} + +$result = @{ + sendDispatch = $sendDispatch + updates = $updates +} | ConvertTo-Json + +return $result diff --git a/container/entrypoint.ps1 b/container/entrypoint.ps1 index 258b482..cd3668e 100644 --- a/container/entrypoint.ps1 +++ b/container/entrypoint.ps1 @@ -21,6 +21,6 @@ if (-not $BaseImage) { $BaseImage = $(& $PSScriptRoot/get-base-image.ps1 -DockerfilePath $DockerfilePath -BaseStageName $BaseStageName) } -$result = $(& $PSScriptRoot/check-image.ps1 -TargetImage $targetImage -BaseImage $BaseImage -Architecture $Architecture) +$result = $(& $PSScriptRoot/check-image.ps1 -TargetImage $targetImage -BaseImage $BaseImage -Architecture $Architecture -DockerfilePath $DockerfilePath) return $result