-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
125 lines (111 loc) · 4.78 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: 'Docker Bump'
description: 'Trigger a GitHub workflow whenever a target image is out-of-date with its dependent base image'
inputs:
target-image-name:
description: 'Name of the image to check'
required: true
base-image-name:
description: 'Name of the base image the target image is based on'
default: ''
dockerfile:
description: 'Path to the Dockerfile used to build the target image'
default: ''
base-stage-name:
description: 'Name of the stage in the Dockerfile associated with the base image'
default: ''
arch:
description: 'Default architecture of the image'
default: amd64
repository:
description: 'Name of GitHub repository containing the workflow to trigger'
default: ${{ github.repository }}
event-type:
description: 'Name of the event that will be sent for the repository dispatch'
default: 'base-image-update'
token:
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT) used to send the repository dispatch'
default: ${{ github.token }}
outputs:
dispatch-sent:
description: "A value indicating whether a repository dispatch was 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'
$targetImage = "${{ inputs.target-image-name }}"
$baseImage = "${{ inputs.base-image-name }}"
$dockerfile = "${{ inputs.dockerfile }}"
$baseStage = "${{ inputs.base-stage-name }}"
$arch = "${{ inputs.arch }}"
$dockerBumpCheckerVersion = "0.4.0"
$containerName = "docker-bump-checker"
$containerSrcPath = "/src"
if ($dockerfile.StartsWith(${env:GITHUB_WORKSPACE})) {
$dockerfile = $dockerfile.Substring(${env:GITHUB_WORKSPACE}.Length).TrimStart('/')
}
# The repo directory will be volume-mounted into the container so the Dockerfile path needs to be modified accordingly
$result = docker run `
--name $containerName `
-v ${env:GITHUB_WORKSPACE}:$containerSrcPath `
-w $containerSrcPath `
ghcr.io/mthalman/docker-bump-checker:$dockerBumpCheckerVersion `
-BaseImage `"$baseImage`" `
-TargetImage `"$targetImage`" `
-DockerfilePath `"$dockerfile`" `
-BaseStageName `"$baseStage`" `
-Architecture `"$arch`"
$dockerRunExitCode = $LASTEXITCODE
docker cp ${containerName}:/home/app/log.txt log.txt > $null 2>&1
if ($LASTEXITCODE -ne 0) {
throw "Unable to retrieve log"
}
Get-Content log.txt
if ($dockerRunExitCode -ne 0) {
throw "command failed"
}
docker rm $containerName
if ($LASTEXITCODE -ne 0) {
throw "command failed"
}
$result = $result | ConvertFrom-Json
# Need to track two different payloads. This is only to account for the scenario where no dispatch is sent.
# In that scenario, we don't send the dispatch but the repository-dispatch action will still validate its
# client-payload input which needs to be valid JSON. So that is defaulted here. The other payload is the
# output of this composite action. That needs to be empty when no dispatch is sent. In the scenario where
# a dispatch is sent, both these payload variables get set to the same value.
$actionPayload = "{}"
$outputPayload = ""
if ($result.sendDispatch -eq "true") {
$payloadObj = @{
updates = $result.updates
}
$actionPayload = ,$payloadObj | ConvertTo-Json -Compress
$outputPayload = $actionPayload
}
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: ${{ 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.ACTION_DISPATCH_PAYLOAD }}
- name: Report Status
shell: pwsh
run: |
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."
}