Skip to content

Commit

Permalink
Use tool-cache to cache tool downloads
Browse files Browse the repository at this point in the history
Change-type: patch
Signed-off-by: Kyle Harding <[email protected]>
  • Loading branch information
klutchell committed Apr 22, 2024
1 parent b9dee62 commit 34c028c
Showing 1 changed file with 71 additions and 33 deletions.
104 changes: 71 additions & 33 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,104 @@ inputs:
runs:
using: "composite"
steps:
- name: Check runner OS
id: check_os
- name: Restore balena CLI cache
id: cache
uses: actions/cache/restore@v4
with:
path: ${{ runner.tool_cache }}/balena-cli
key: balena-cli-${{ runner.os }}-${{ runner.arch }}

- name: Get latest release
if: ${{ inputs.cli-version }} != 'latest' || ${{ inputs.cli-version }} != ''
id: latest
shell: bash
working-directory: ${{ runner.temp }}
run: |
case ${{ runner.os }} in
Linux) echo "slug=linux" >> "${GITHUB_OUTPUT}" ;;
Windows) echo "slug=windows" >> "${GITHUB_OUTPUT}" ;;
macOS) echo "slug=macOS" >> "${GITHUB_OUTPUT}" ;;
*) echo "Unsupported OS: ${{ runner.os }}" ; exit 1 ;;
esac
release="$(curl -s https://api.github.com/repos/balena-io/balena-cli/releases/latest | jq -r '.tag_name')"
echo "release=${release}" >> "${GITHUB_OUTPUT}"
- name: Check runner Arch
id: check_arch
- name: Download balena CLI (Linux X64)
if: runner.os == 'Linux' && runner.arch == 'x64' && ! steps.cache.outputs.cache-hit
working-directory: ${{ runner.temp }}
shell: bash
env:
REPO: https://github.com/balena-io/balena-cli
VERSION: ${{ steps.latest.outputs.release || inputs.cli-version }}
run: |
case ${{ runner.arch }} in
X64) echo "slug=x64" >> "${GITHUB_OUTPUT}" ;;
ARM64) echo "slug=arm64" >> "${GITHUB_OUTPUT}" ;;
*) echo "Unsupported Arch: ${{ runner.arch }}" ; exit 1 ;;
esac
set -x
curl -fsSL "${REPO}/releases/download/${VERSION}/balena-cli-${VERSION}-linux-x64-standalone.zip" -o balena-cli.zip
unzip balena-cli.zip -d balena-cli
- name: Check CLI version
id: check_version
- name: Download balena CLI (Linux ARM64)
if: runner.os == 'Linux' && runner.arch == 'ARM64' && ! steps.cache.outputs.cache-hit
working-directory: ${{ runner.temp }}
shell: bash
env:
INPUT: ${{ inputs.cli-version }}
REPO: https://github.com/balena-io/balena-cli
VERSION: ${{ steps.latest.outputs.release || inputs.cli-version }}
run: |
latest="$(curl -s https://api.github.com/repos/balena-io/balena-cli/releases/latest | jq -r '.tag_name')"
set -x
curl -fsSL "${REPO}/releases/download/${VERSION}/balena-cli-${VERSION}-linux-arm64-standalone.zip" -o balena-cli.zip
unzip balena-cli.zip -d balena-cli
case ${INPUT} in
latest|"") echo "slug=${latest}" >> "${GITHUB_OUTPUT}" ;;
*) echo "slug=v${INPUT/v/}" >> "${GITHUB_OUTPUT}" ;;
esac
- name: Download balena CLI (Windows X64)
if: runner.os == 'Windows' && runner.arch == 'x64' && ! steps.cache.outputs.cache-hit
working-directory: ${{ runner.temp }}
shell: bash
env:
REPO: https://github.com/balena-io/balena-cli
VERSION: ${{ steps.latest.outputs.release || inputs.cli-version }}
run: |
set -x
curl -fsSL "${REPO}/releases/download/${VERSION}/balena-cli-${VERSION}-windows-x64-standalone.zip" -o balena-cli.zip
unzip balena-cli.zip -d balena-cli
# e.g. https://github.com/balena-io/balena-cli/releases/download/v18.1.9/balena-cli-v18.1.9-linux-arm64-standalone.zip
- name: Download balena CLI
- name: Download balena CLI (macOS X64)
if: runner.os == 'macOS' && runner.arch == 'x64' && ! steps.cache.outputs.cache-hit
working-directory: ${{ runner.temp }}
shell: bash
env:
OS: ${{ steps.check_os.outputs.slug }}
ARCH: ${{ steps.check_arch.outputs.slug }}
VERSION: ${{ steps.check_version.outputs.slug }}
REPO: https://github.com/balena-io/balena-cli
VERSION: ${{ steps.latest.outputs.release || inputs.cli-version }}
run: |
set -x
curl -fsSL "https://github.com/balena-io/balena-cli/releases/download/${VERSION}/balena-cli-${VERSION}-${OS}-${ARCH}-standalone.zip" -o "${{ runner.temp }}/balena-cli.zip"
curl -fsSL "${REPO}/releases/download/${VERSION}/balena-cli-${VERSION}-macOS-x64-standalone.zip" -o balena-cli.zip
unzip balena-cli.zip -d balena-cli
- name: Unpack balena CLI
- name: Download balena CLI (macOS ARM64)
if: runner.os == 'macOS' && runner.arch == 'ARM64' && ! steps.cache.outputs.cache-hit
working-directory: ${{ runner.temp }}
shell: bash
env:
GITHUB_ACTION_PATH: ${{ github.action_path }}
REPO: https://github.com/balena-io/balena-cli
VERSION: ${{ steps.latest.outputs.release || inputs.cli-version }}
run: |
unzip "${{ runner.temp }}/balena-cli.zip" -d "${GITHUB_ACTION_PATH}"
echo "${GITHUB_ACTION_PATH}/balena-cli" >> "${GITHUB_PATH}"
set -x
curl -fsSL "${REPO}/releases/download/${VERSION}/balena-cli-${VERSION}-macOS-arm64-standalone.zip" -o balena-cli.zip
unzip balena-cli.zip -d balena-cli
- name: Install balena CLI to tool cache
uses: AnimMouse/tool-cache@v1
with:
folder_name: balena-cli
cache_hit: ${{ steps.cache.outputs.cache-hit }}

- name: Save balena CLI cache
if: '! steps.cache.outputs.cache-hit'
uses: actions/cache/save@v4
with:
path: ${{ runner.tool_cache }}/balena-cli
key: balena-cli-${{ runner.os }}-${{ runner.arch}}

- name: Print balena CLI version
shell: bash
working-directory: ${{ runner.temp }}
run: balena version

- name: Login to balenaCloud
if: inputs.balena-token != ''
shell: bash
working-directory: ${{ runner.temp }}
run: |
balena login --token "${{ inputs.balena-token }}"
balena whoami

0 comments on commit 34c028c

Please sign in to comment.