|
| 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 | + 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) |
| 39 | + if [[ -z "$VERSION" ]]; then |
| 40 | + VERSION="v3.39.2" |
| 41 | + fi |
| 42 | + else |
| 43 | + VERSION="${{ inputs.version }}" |
| 44 | + if [[ ! "$VERSION" =~ ^v ]]; then |
| 45 | + VERSION="v$VERSION" |
| 46 | + fi |
| 47 | + fi |
| 48 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + - name: Determine platform |
| 51 | + id: platform |
| 52 | + shell: bash |
| 53 | + run: | |
| 54 | + OS=$(uname -s | tr '[:upper:]' '[:lower:]') |
| 55 | + ARCH=$(uname -m) |
| 56 | + case $ARCH in |
| 57 | + x86_64) ARCH="amd64" ;; |
| 58 | + aarch64|arm64) ARCH="arm64" ;; |
| 59 | + armv7l) ARCH="arm" ;; |
| 60 | + esac |
| 61 | + case $OS in |
| 62 | + darwin) OS="darwin" ;; |
| 63 | + linux) OS="linux" ;; |
| 64 | + mingw*|msys*|cygwin*) OS="windows" ;; |
| 65 | + esac |
| 66 | + [[ $OS == "windows" ]] && BINARY_NAME="task.exe" || BINARY_NAME="task" |
| 67 | + echo "os=$OS" >> $GITHUB_OUTPUT |
| 68 | + echo "arch=$ARCH" >> $GITHUB_OUTPUT |
| 69 | + echo "binary_name=$BINARY_NAME" >> $GITHUB_OUTPUT |
| 70 | +
|
| 71 | + - name: Setup GitHub PATH |
| 72 | + shell: bash |
| 73 | + run: echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 74 | + |
| 75 | + - name: Setup cache for Task binary |
| 76 | + id: cache |
| 77 | + if: inputs.cache-enabled == 'true' |
| 78 | + uses: actions/cache@v4 |
| 79 | + with: |
| 80 | + path: ~/.local/bin/${{ steps.platform.outputs.binary_name }} |
| 81 | + key: task-${{ steps.get-version.outputs.version }}-${{ steps.platform.outputs.os }}-${{ steps.platform.outputs.arch }} |
| 82 | + |
| 83 | + - name: Download and install Task |
| 84 | + if: steps.cache.outputs.cache-hit != 'true' |
| 85 | + shell: bash |
| 86 | + run: | |
| 87 | + sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -b ~/.local/bin -d ${{ steps.get-version.outputs.version }} |
| 88 | +
|
| 89 | + - name: Verify installation |
| 90 | + shell: bash |
| 91 | + run: task --version |
0 commit comments