Skip to content

Commit 1e0ebad

Browse files
committed
update
1 parent e517031 commit 1e0ebad

1 file changed

Lines changed: 31 additions & 48 deletions

File tree

actions/taskfile-runner/action.yml

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ inputs:
1717
description: 'Taskfile version'
1818
required: false
1919
default: '3.44.1'
20+
show_summary:
21+
description: 'Print summary with task output in job summary'
22+
required: false
23+
default: 'true'
24+
summary_limit:
25+
description: 'Max number of output lines to show in summary'
26+
required: false
27+
default: '250'
2028

2129
outputs:
2230
task_version:
@@ -37,84 +45,66 @@ runs:
3745
working-directory: ${{ inputs.dir }}
3846
run: |
3947
set -euo pipefail
40-
4148
if [[ ! -f "Taskfile.yml" && ! -f "Taskfile.yaml" ]]; then
4249
echo "❌ No Taskfile found in ${{ inputs.dir }}"
4350
echo "Expected: Taskfile.yml or Taskfile.yaml"
4451
exit 1
4552
fi
46-
4753
echo "✅ Taskfile found"
4854
4955
- name: Detect architecture
5056
id: arch
5157
shell: bash
5258
run: |
5359
set -euo pipefail
54-
5560
ARCH=$(uname -m)
5661
case "$ARCH" in
5762
x86_64) ARCH="amd64" ;;
5863
aarch64|arm64) ARCH="arm64" ;;
5964
*) echo "❌ Unsupported architecture: $ARCH" && exit 1 ;;
6065
esac
61-
62-
echo "arch=$ARCH" >> $GITHUB_OUTPUT
66+
echo "arch=$ARCH" >> "$GITHUB_OUTPUT"
67+
echo "Using arch: $ARCH"
6368
6469
- name: Cache Task binary
6570
id: cache
6671
uses: actions/cache@v4
6772
with:
68-
path: ${{ env.HOME }}/.cache/task/task-${{ inputs.version }}-${{ steps.arch.outputs.arch }}
73+
path: ~/.cache/task
6974
key: task-${{ inputs.version }}-${{ steps.arch.outputs.arch }}
75+
restore-keys: |
76+
task-${{ inputs.version }}-
77+
task-
7078
7179
- name: Download Task binary
7280
if: steps.cache.outputs.cache-hit != 'true'
7381
shell: bash
7482
run: |
7583
set -euo pipefail
76-
7784
VERSION="${{ inputs.version }}"
7885
ARCH="${{ steps.arch.outputs.arch }}"
7986
echo "⬇️ Downloading Task v$VERSION for $ARCH..."
8087
81-
TMPDIR="$(mktemp -d)"
82-
trap 'rm -rf "$TMPDIR"' EXIT
88+
TMPDIR="$(mktemp -d)"; trap 'rm -rf "$TMPDIR"' EXIT
89+
mkdir -p "$HOME/.cache/task"
8390
84-
mkdir -p ~/.cache/task
8591
curl -fsSLo "$TMPDIR/task.tgz" "https://github.com/go-task/task/releases/download/v${VERSION}/task_linux_${ARCH}.tar.gz"
8692
tar -xzf "$TMPDIR/task.tgz" -C "$TMPDIR"
8793
88-
TASK_BINARY=""
89-
for cand in \
90-
"$TMPDIR/task" \
91-
"$TMPDIR/bin/task" \
92-
"$TMPDIR/task_linux_${ARCH}/task"
93-
do
94-
if [[ -f "$cand" && -x "$cand" ]]; then
95-
TASK_BINARY="$cand"
96-
break
97-
fi
98-
done
99-
100-
if [[ -z "$TASK_BINARY" ]]; then
101-
TASK_BINARY="$(find "$TMPDIR" -maxdepth 3 -type f -name task -perm -111 -print -quit || true)"
102-
fi
103-
104-
if [[ -z "$TASK_BINARY" ]]; then
94+
TASK_BIN="$(find "$TMPDIR" -maxdepth 3 -type f -name task -perm -111 -print -quit || true)"
95+
if [[ -z "$TASK_BIN" ]]; then
10596
echo "❌ Task binary not found in archive"
10697
exit 1
10798
fi
10899
109-
mv "$TASK_BINARY" ~/.cache/task/task-$VERSION-$ARCH
110-
echo "✅ Downloaded to ~/.cache/task/task-$VERSION-$ARCH"
100+
install -m 0755 "$TASK_BIN" "$HOME/.cache/task/task-$VERSION-$ARCH"
101+
echo "✅ Downloaded to $HOME/.cache/task/task-$VERSION-$ARCH"
111102
112103
- name: Install Task binary
113104
id: install
114105
shell: bash
115106
run: |
116107
set -euo pipefail
117-
118108
VERSION="${{ inputs.version }}"
119109
ARCH="${{ steps.arch.outputs.arch }}"
120110
SRC="$HOME/.cache/task/task-$VERSION-$ARCH"
@@ -127,16 +117,13 @@ runs:
127117
128118
mkdir -p "$(dirname "$DEST")"
129119
install -m 0755 "$SRC" "$DEST"
130-
131120
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
132121
133122
VER_RAW="$("$DEST" --version 2>&1 | head -n1 | tr -d '\r')"
134123
VER="$(printf '%s\n' "$VER_RAW" | grep -Eo 'v?[0-9]+(\.[0-9]+)+' | head -n1 || true)"
135-
if [[ -z "$VER" ]]; then
136-
VER="$VER_RAW"
137-
fi
138-
124+
[[ -z "$VER" ]] && VER="$VER_RAW"
139125
[[ "$VER" != v* ]] && VER="v$VER"
126+
140127
echo "✅ Installed task $VER"
141128
echo "version=$VER" >> "$GITHUB_OUTPUT"
142129
@@ -145,13 +132,10 @@ runs:
145132
shell: bash
146133
run: |
147134
set -euo pipefail
148-
149-
echo "🌐 Exporting env vars:"
150135
IFS=',' read -ra VARS <<< "${{ inputs.vars }}"
151136
for var in "${VARS[@]}"; do
152137
pair="$(echo "$var" | xargs)"
153138
[[ -z "$pair" ]] && continue
154-
155139
key="${pair%%=*}"
156140
value="${pair#*=}"
157141
if [[ "$value" == "$key" ]]; then
@@ -162,7 +146,6 @@ runs:
162146
echo "❌ Invalid var (empty key): $pair"
163147
exit 1
164148
fi
165-
166149
delim="ENV_${key}_$RANDOM$RANDOM"
167150
{
168151
echo "$key<<$delim"
@@ -177,53 +160,53 @@ runs:
177160
working-directory: ${{ inputs.dir }}
178161
run: |
179162
set -euo pipefail
180-
181163
echo "🚀 Running task ${{ inputs.command }}"
182164
183165
set +e
184-
OUTPUT=$(task ${{ inputs.command }} 2>&1)
166+
OUTPUT="$(task ${{ inputs.command }} 2>&1)"
185167
EXIT_CODE=$?
186168
set -e
187169
188170
printf "%s\n" "$OUTPUT"
189-
171+
190172
DELIM="__TASK_OUTPUT_$(date +%s%N)__"
191173
{
192174
echo "output<<$DELIM"
193175
printf "%s\n" "$OUTPUT"
194176
echo "$DELIM"
195177
} >> "$GITHUB_OUTPUT"
178+
196179
if [[ $EXIT_CODE -ne 0 ]]; then
197180
echo "❌ Task failed with exit code $EXIT_CODE"
198181
exit $EXIT_CODE
199182
fi
200-
183+
201184
echo "✅ Task completed successfully"
202185
203186
- name: Task Runner Summary
187+
if: inputs.show_summary != 'false'
204188
shell: bash
205189
run: |
206190
set -euo pipefail
207-
208-
LIMIT=200
209191
OUT="${{ steps.run.outputs.output }}"
192+
LIMIT="${{ inputs.summary_limit }}"
193+
# sane fallback if user passed junk
194+
if ! [[ "$LIMIT" =~ ^[0-9]+$ ]]; then LIMIT=250; fi
210195
211196
{
212197
echo "## 🧰 Task Runner Summary"
213198
echo "- Command: \`${{ inputs.command }}\`"
214199
echo "- Directory: \`${{ inputs.dir }}\`"
215200
echo "- Task version: \`${{ steps.install.outputs.version }}\`"
216201
217-
if [ -n "${OUT}" ]; then
202+
if [ -n "$OUT" ]; then
218203
echo ""
219-
220204
TOTAL=$(printf "%s\n" "$OUT" | wc -l | awk '{print $1}')
221205
if [ "$TOTAL" -le "$LIMIT" ]; then
222206
echo "### 🧾 Task output"
223207
else
224208
echo "### 🧾 Task output (first ${LIMIT} lines of ${TOTAL})"
225209
fi
226-
227210
echo '```'
228211
printf "%s\n" "$OUT" | awk -v lim="$LIMIT" 'NR<=lim{print}'
229212
echo '```'

0 commit comments

Comments
 (0)