|
| 1 | +# Copyright AGNTCY Contributors (https://github.com/agntcy) |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +--- |
| 5 | + |
| 6 | +name: Setup Task with Cache |
| 7 | +description: Setup Task (go-task/task) with GitHub Actions caching to prevent rate limiting |
| 8 | +inputs: |
| 9 | + version: |
| 10 | + description: 'Task version to install (e.g., "3.39.2", "latest")' |
| 11 | + required: false |
| 12 | + default: 'latest' |
| 13 | + cache-enabled: |
| 14 | + description: 'Enable caching of the Task binary' |
| 15 | + required: false |
| 16 | + default: 'true' |
| 17 | + github-token: |
| 18 | + description: 'GitHub token for API requests' |
| 19 | + required: false |
| 20 | + default: ${{ github.token }} |
| 21 | + |
| 22 | +outputs: |
| 23 | + cache-hit: |
| 24 | + description: 'Whether the Task binary was retrieved from cache' |
| 25 | + value: ${{ steps.cache.outputs.cache-hit }} |
| 26 | + version: |
| 27 | + description: 'The actual version of Task that was installed' |
| 28 | + value: ${{ steps.get-version.outputs.version }} |
| 29 | + |
| 30 | +runs: |
| 31 | + using: "composite" |
| 32 | + steps: |
| 33 | + - name: Determine Task version |
| 34 | + id: get-version |
| 35 | + shell: bash |
| 36 | + run: | |
| 37 | + if [ "${{ inputs.version }}" == "latest" ]; then |
| 38 | + echo "Fetching latest Task version (authenticated request)..." |
| 39 | + VERSION=$(curl -s -H "Authorization: Bearer ${{ inputs.github-token }}" -H "Accept: application/vnd.github+json" https://api.github.com/repos/go-task/task/releases/latest | grep '"tag_name"' | cut -d'"' -f4) |
| 40 | + if [[ -z "$VERSION" ]]; then |
| 41 | + echo "Failed to fetch latest version via authenticated request, using fallback" |
| 42 | + VERSION="v3.39.2" |
| 43 | + fi |
| 44 | + else |
| 45 | + VERSION="${{ inputs.version }}" |
| 46 | + # Ensure version starts with 'v' |
| 47 | + if [[ ! "$VERSION" =~ ^v ]]; then |
| 48 | + VERSION="v$VERSION" |
| 49 | + fi |
| 50 | + fi |
| 51 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 52 | + echo "Using Task version: $VERSION" |
| 53 | +
|
| 54 | + - name: Determine platform |
| 55 | + id: platform |
| 56 | + shell: bash |
| 57 | + run: | |
| 58 | + OS=$(uname -s | tr '[:upper:]' '[:lower:]') |
| 59 | + ARCH=$(uname -m) |
| 60 | +
|
| 61 | + # Normalize architecture names to match Task releases |
| 62 | + case $ARCH in |
| 63 | + x86_64) |
| 64 | + ARCH="amd64" |
| 65 | + ;; |
| 66 | + aarch64|arm64) |
| 67 | + ARCH="arm64" |
| 68 | + ;; |
| 69 | + armv7l) |
| 70 | + ARCH="arm" |
| 71 | + ;; |
| 72 | + esac |
| 73 | +
|
| 74 | + # Normalize OS names |
| 75 | + case $OS in |
| 76 | + darwin) |
| 77 | + OS="darwin" |
| 78 | + ;; |
| 79 | + linux) |
| 80 | + OS="linux" |
| 81 | + ;; |
| 82 | + mingw*|msys*|cygwin*) |
| 83 | + OS="windows" |
| 84 | + ;; |
| 85 | + esac |
| 86 | +
|
| 87 | + # Determine Windows architecture naming |
| 88 | + [[ $OS == "windows" ]] && BINARY_NAME="task.exe" || BINARY_NAME="task" |
| 89 | +
|
| 90 | + echo "os=$OS" >> $GITHUB_OUTPUT |
| 91 | + echo "arch=$ARCH" >> $GITHUB_OUTPUT |
| 92 | + echo "binary_name=$BINARY_NAME" >> $GITHUB_OUTPUT |
| 93 | + echo "Platform: $OS-$ARCH" |
| 94 | +
|
| 95 | + - name: Setup GitHub PATH |
| 96 | + shell: bash |
| 97 | + run: | |
| 98 | + echo "Adding ~/.local/bin to PATH" |
| 99 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 100 | +
|
| 101 | + - name: Setup cache for Task binary |
| 102 | + id: cache |
| 103 | + if: inputs.cache-enabled == 'true' |
| 104 | + uses: actions/cache@v4 |
| 105 | + with: |
| 106 | + # If windows, we need to cache task.exe |
| 107 | + path: ~/.local/bin/${{ steps.platform.outputs.binary_name }} |
| 108 | + key: task-${{ steps.get-version.outputs.version }}-${{ steps.platform.outputs.os }}-${{ steps.platform.outputs.arch }} |
| 109 | + |
| 110 | + - name: Download and install Task |
| 111 | + if: steps.cache.outputs.cache-hit != 'true' |
| 112 | + shell: bash |
| 113 | + env: |
| 114 | + VERSION: ${{ steps.get-version.outputs.version }} |
| 115 | + OS: ${{ steps.platform.outputs.os }} |
| 116 | + ARCH: ${{ steps.platform.outputs.arch }} |
| 117 | + GITHUB_TOKEN: ${{ inputs.github-token }} |
| 118 | + run: | |
| 119 | + echo "Task not found in cache, downloading..." |
| 120 | + sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -b ~/.local/bin -d ${{ steps.get-version.outputs.version }} |
| 121 | +
|
| 122 | + - name: Verify installation |
| 123 | + shell: bash |
| 124 | + run: | |
| 125 | + # Verify installation |
| 126 | + if task --version; then |
| 127 | + echo "Task installation verified" |
| 128 | + else |
| 129 | + echo "Task installation verification failed" |
| 130 | + exit 1 |
| 131 | + fi |
| 132 | +
|
| 133 | + - name: Cache status |
| 134 | + shell: bash |
| 135 | + run: | |
| 136 | + if [[ "${{ steps.cache.outputs.cache-hit }}" == "true" ]]; then |
| 137 | + echo "✓ Task binary retrieved from cache" |
| 138 | + else |
| 139 | + echo "✓ Task binary downloaded and cached for future runs" |
| 140 | + fi |
0 commit comments