-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathaction.yml
More file actions
235 lines (222 loc) · 8.19 KB
/
action.yml
File metadata and controls
235 lines (222 loc) · 8.19 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: "Dagger for GitHub"
description: "Run dagger commands in Github Actions"
inputs:
version:
description: "Dagger Version. Use semver vX.Y.Z or 'latest'"
required: false
default: "latest"
commit:
description: "Dagger Dev Commit"
required: false
default: ""
dagger-flags:
description: "Dagger CLI Flags"
required: false
default: "--progress plain"
verb:
description: "CLI verb (check, call, run, download, up, functions, shell, query)"
required: false
default: "call"
workdir:
description: "The working directory in which to run the Dagger CLI"
required: false
default: "."
cloud-token:
description: "Dagger Cloud Token"
required: false
default: ""
module:
description: "Dagger module to call. Local or Git"
required: false
default: ""
args:
description: "Arguments to pass to CLI"
required: false
default: ""
engine-stop:
description: "Deprecated"
deprecationMessage: "engine-stop is now a no-op and will be removed in a future release"
required: false
call:
description: "Function and arguments for dagger call"
required: false
default: ""
shell:
description: "Function and arguments for dagger shell"
required: false
default: ""
check:
description: "Function and arguments for dagger check"
required: false
default: ""
summary-path:
description: "File path to write the job summary"
required: false
default: ""
enable-github-summary:
description: "Whether to write summary to GITHUB_STEP_SUMMARY"
required: false
default: "false"
outputs:
output:
description: "Job output"
value: ${{ steps.exec.outputs.stdout }}
traceURL:
description: "Dagger Cloud trace URL"
value: ${{ steps.exec.outputs.traceURL }}
runs:
using: "composite"
steps:
- shell: bash
run: |
set -o pipefail
# Fallback to /usr/local for backwards compatability
prefix_dir="${RUNNER_TEMP:-/usr/local}"
# Ensure the dir is writable otherwise fallback to tmpdir
if [[ ! -d "$prefix_dir" ]] || [[ ! -w "$prefix_dir" ]]; then
prefix_dir="$(mktemp -d)"
fi
printf '%s/bin' "$prefix_dir" >> $GITHUB_PATH
# If the dagger version is 'latest', set the version back to an empty
# string. This allows the install script to detect and install the latest
# version itself
VERSION=${{ inputs.version }}
if [[ "$VERSION" == "latest" ]]; then
VERSION=
elif [[ -n "$VERSION" && "$VERSION" != v* ]]; then
# Add 'v' prefix if version doesn't start with 'v' and is not empty
VERSION="v$VERSION"
fi
latest=$(curl https://dl.dagger.io/dagger/versions/latest)
COMMIT=${{ inputs.commit }}
if [[ -x "$(command -v dagger)" ]]; then
echo "::group::Checking dagger"
version="$(dagger --silent version | cut --fields 2 --delimiter ' ')"
echo "Found existing dagger version: $version"
if [[ "$version" == "$VERSION" ]] || [[ "$version" == "$latest" ]]; then
echo "dagger ${version} is already installed, skipping installation"
exit 0
fi
echo "::endgroup::"
fi
echo "::group::Installing dagger"
curl -fsSL https://dl.dagger.io/dagger/install.sh | \
BIN_DIR=${prefix_dir}/bin DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
echo "::endgroup::"
- id: should-exec
shell: bash
env:
INPUT_CALL: ${{ inputs.call }}
INPUT_SHELL: ${{ inputs.shell }}
INPUT_ARGS: ${{ inputs.args }}
INPUT_CHECK: ${{ inputs.check }}
INPUT_VERB: ${{ inputs.verb }}
run: |
# Determine if the user wants to execute a dagger command or just install
if [[ -n "$INPUT_CALL" ]] || \
[[ -n "$INPUT_SHELL" ]] || \
[[ -n "$INPUT_ARGS" ]] || \
[[ -n "$INPUT_CHECK" ]] || \
[[ "$INPUT_VERB" != "call" ]]; then
echo "result=true" >> "$GITHUB_OUTPUT"
fi
- id: assemble
if: steps.should-exec.outputs.result == 'true'
shell: bash
env:
INPUT_MODULE: ${{ inputs.module }}
run: |
verb=${{ inputs.verb }}
shell=$(echo '${{ toJSON(inputs.shell) }}' | jq -rj .)
# Collapse backslash-continuations and newlines into spaces for CLI args
dagger_flags=$(echo '${{ toJSON(inputs.dagger-flags) }}' | jq -rj . | sed -z 's/\\\n/ /g; s/\n/ /g')
args=$(echo '${{ toJSON(inputs.args) }}' | jq -rj . | sed -z 's/\\\n/ /g; s/\n/ /g')
call=$(echo '${{ toJSON(inputs.call) }}' | jq -rj . | sed -z 's/\\\n/ /g; s/\n/ /g')
check=$(echo '${{ toJSON(inputs.check) }}' | jq -rj . | sed -z 's/\\\n/ /g; s/\n/ /g')
if [[ -n "${{ inputs.call }}" ]]; then
verb="call"
elif [[ -n "$check" ]]; then
verb="check"
# check input is used as a trigger; don't pass glob patterns as args
check=""
elif [[ "$shell" != "" ]]; then
verb=""
script=$(mktemp)
printf '%s' "$shell" > $script
fi
echo "script=$script" >> "$GITHUB_OUTPUT"
echo "verb=$verb" >> "$GITHUB_OUTPUT"
echo "dagger-flags=$dagger_flags" >> "$GITHUB_OUTPUT"
echo "args=$args" >> "$GITHUB_OUTPUT"
echo "call=$call" >> "$GITHUB_OUTPUT"
echo "check=$check" >> "$GITHUB_OUTPUT"
- id: exec
if: steps.should-exec.outputs.result == 'true'
shell: bash
env:
INPUT_MODULE: ${{ inputs.module }}
VERB: ${{ steps.assemble.outputs.verb }}
SCRIPT: ${{ steps.assemble.outputs.script }}
run: |
tmpout=$(mktemp)
tmperr=$(mktemp)
cd ${{ inputs.workdir }} && { \
DAGGER_CLOUD_TOKEN=${{ inputs.cloud-token }} \
dagger \
${{ steps.assemble.outputs.dagger-flags }} \
${VERB} \
${INPUT_MODULE:+-m $INPUT_MODULE} \
${{ steps.assemble.outputs.args || steps.assemble.outputs.call || steps.assemble.outputs.script || steps.assemble.outputs.check }}; } 1> >(tee "${tmpout}") 2> >(tee "${tmperr}" >&2)
{
# we need a delim that doesn't appear in the output - a hash of the
# file itself *probably* won't (if it does, we have larger
# cryptographic problems)
delim="$(sha256sum $tmpout | cut -d " " -f1)"
echo "stdout<<${delim}"
cat "${tmpout}"
echo
echo "${delim}"
} >> "$GITHUB_OUTPUT"
# Extract trace URL from stderr and set as traceURL output
trace_url=$((grep -Eo 'https://dagger.cloud(/[^ ]+/traces/[a-zA-Z0-9]+|/traces/setup)' "${tmperr}" || true) | head -n1)
if [[ -n "$trace_url" ]]; then
echo "traceURL=$trace_url" >> "$GITHUB_OUTPUT"
fi
# Generate job summary content
summary_content(){
echo -e "## Command\n"
echo '```bash'
cmd="dagger $VERB ${{ steps.assemble.outputs.args || steps.assemble.outputs.call || steps.assemble.outputs.script || steps.assemble.outputs.check }}"
if [[ -n "$INPUT_MODULE" ]]; then
echo -e -E "DAGGER_MODULE=\"$INPUT_MODULE\" $cmd"
else
echo -e -E "$cmd"
fi
echo '```'
if [[ -n "$SCRIPT" ]]; then
echo -e "### Script\n"
echo '```bash'
cat "$SCRIPT"
echo -e "\n"
echo '```'
fi
echo -e "## Dagger trace\n"
if [[ -n "$trace_url" ]]; then
echo "[$trace_url]($trace_url)"
else
echo "No trace available. To setup: [https://dagger.cloud/traces/setup](https://dagger.cloud/traces/setup)"
fi
echo -e "## Dagger version\n"
echo '```bash'
dagger version || true
echo '```'
echo -e "---\n"
}
# Write to custom summary path if specified
if [[ -n "${{ inputs.summary-path }}" ]]; then
summary_content > "${{ inputs.summary-path }}"
fi
# Write to GitHub step summary if enabled (default: true)
if [[ "${{ inputs.enable-github-summary }}" == "true" ]]; then
summary_content > "${GITHUB_STEP_SUMMARY}"
fi