-
Notifications
You must be signed in to change notification settings - Fork 25
/
action.yml
108 lines (102 loc) · 3.26 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
name: "Dagger for GitHub"
description: "Run dagger commands in Github Actions"
inputs:
version:
description: "Dagger Version"
required: false
default: "0.14.0"
commit:
description: "Dagger Dev Commit"
required: false
default: ""
dagger-flags:
description: "Dagger CLI Flags"
required: false
default: "--progress plain"
verb:
description: "CLI verb (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: "Whether to stop the Dagger Engine after this run"
required: false
default: "true"
call:
description: "Function and arguments for dagger call"
required: false
default: ""
outputs:
output:
description: "Job output"
value: ${{ steps.exec.outputs.stdout }}
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=
fi
COMMIT=${{ inputs.commit }}
# The install.sh script creates path ${prefix_dir}/bin
curl -fsS https://dl.dagger.io/dagger/install.sh \
| BIN_DIR=${prefix_dir}/bin DAGGER_VERSION="$VERSION" DAGGER_COMMIT="$COMMIT" sh
- id: exec
if: inputs.call != '' || inputs.args != ''
shell: bash
env:
INPUT_MODULE: ${{ inputs.module }}
run: |
tmpout=$(mktemp)
cd ${{ inputs.workdir }} && { \
DAGGER_CLOUD_TOKEN=${{ inputs.cloud-token }} \
dagger \
${{ inputs.dagger-flags }} \
${{ inputs.verb }} \
${INPUT_MODULE:+-m $INPUT_MODULE} \
${{ inputs.args || inputs.call }}; } | tee "${tmpout}"
{
# 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"
- if: (inputs.call != '' || inputs.args != '') && inputs.engine-stop == 'true'
shell: bash
run: |
mapfile -t containers < <(docker ps --filter name="dagger-engine-*" -q)
if [[ "${#containers[@]}" -gt 0 ]]; then
docker stop -t 300 "${containers[@]}";
fi