Skip to content

Commit bbd98c5

Browse files
committed
perf: enable go caching and install task from prebuilt binary
Every job that uses this action paid several minutes of avoidable setup. actions/setup-go was invoked with `cache: false`, so each job re-downloaded the whole module graph and recompiled every dependency from scratch. On mcvs-scanner this accounted for roughly 190-300s per job before the first test line was even printed. The version guard around the Task install had also been silently broken since Task 3.44: it matched `Task version: v<x>`, but Task now reports a bare `<x>`. The guard therefore never matched and every job unconditionally recompiled Task from source, costing ~90s each. The guard now matches the bare version, which covers both the old and new output formats, and the prebuilt binary is installed instead of compiling from source, mirroring how golangci-lint is already installed in build/task.yml. Coverage results are unaffected: the coverage task already passes -count=1 (#344), so a warm build cache cannot cause cached test results to be reported as coverage.
1 parent 293da57 commit bbd98c5

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

action.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ runs:
104104
inputs.testing-type == 'unit'
105105
with:
106106
go-version-file: ${{ inputs.go-version-file }}
107-
cache: false
107+
cache: true
108108
- name: install task
109109
if: |
110110
inputs.release-dir != '' ||
@@ -121,9 +121,23 @@ runs:
121121
inputs.testing-type == 'unit'
122122
shell: bash
123123
run: |
124-
if ! task --version | grep -q "Task version: v${{ inputs.task-version }}"; then
125-
major_version=$(echo "${{ inputs.task-version }}" | sed -E 's/^([0-9]+).*/\1/')
126-
go install github.com/go-task/task/v${major_version}/cmd/task@v${{ inputs.task-version }}
124+
# Task <= 3.38 reported 'Task version: v3.38.0 (h1:...)', whereas newer
125+
# releases report a bare '3.51.1'. Matching the bare version covers
126+
# both, so that an already installed Task is actually detected.
127+
if ! task --version 2>/dev/null | grep -qF "${{ inputs.task-version }}"; then
128+
# The prebuilt binary is used rather than 'go install', which compiles
129+
# Task from source and costs roughly 90s in every job. This mirrors
130+
# how golangci-lint is installed in build/task.yml.
131+
#
132+
# The destination mirrors what 'go install' would have used, so that
133+
# Task still lands on a directory that is already on the PATH.
134+
bindir="$(go env GOBIN)"
135+
if [ -z "${bindir}" ]; then
136+
bindir="$(go env GOPATH)/bin"
137+
fi
138+
curl \
139+
-sSfL https://raw.githubusercontent.com/go-task/task/main/install-task.sh |\
140+
sh -s -- -b "${bindir}" v${{ inputs.task-version }}
127141
fi
128142
129143
echo "verifying that task can be found and run..."

0 commit comments

Comments
 (0)