From b733b79e37eda5caba8703a75b522e9053d0846e Mon Sep 17 00:00:00 2001 From: i4k Date: Thu, 4 Jul 2024 18:21:56 +0100 Subject: [PATCH] fix: install supported Terramate system/arch. Signed-off-by: i4k --- .github/workflows/tests.yml | 28 +++++++++++++++++++++++++--- README.md | 4 ++-- install.sh | 26 ++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f4b6203..d269799 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,6 +10,9 @@ defaults: run: shell: bash +permissions: + contents: read + jobs: simple: name: Terramate latest @@ -17,23 +20,34 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + + - if: runner.os == 'macOS' + name: "install jq on macos" + run: brew install jq - name: Install latest Terramate uses: ./ + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Validate execution run: terramate version asdf: name: Terramate asdf - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: + os: ["ubuntu-latest", "macos-latest"] version: [0.4.2, 0.4.3, skip] steps: - name: Checkout uses: actions/checkout@v4 + - if: runner.os == 'macOS' + name: "install jq on macos" + run: brew install jq + - name: Prepare asdf config if: ${{ matrix.version != 'skip' }} run: echo "terramate ${{ matrix.version}}" >.tool-versions @@ -44,6 +58,8 @@ jobs: - name: Install asdf Terramate uses: ./ + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Validate execution run: terramate version @@ -60,9 +76,10 @@ jobs: wrapper: name: Terramate with wrapper - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: + os: ["ubuntu-latest", "macos-latest"] version: [0.4.3, latest] steps: - name: Checkout @@ -72,6 +89,8 @@ jobs: uses: ./ with: version: ${{ matrix.version }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Validate execution - ${{ matrix.version }} run: terramate version @@ -87,9 +106,10 @@ jobs: no-wrapper: name: Terramate without wrapper - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: + os: ["ubuntu-latest", "macos-latest"] version: [0.4.3, latest] steps: - name: Checkout @@ -100,6 +120,8 @@ jobs: with: version: ${{ matrix.version }} use_wrapper: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Validate execution - ${{ matrix.version }} run: terramate version diff --git a/README.md b/README.md index 443301a..63dc6b4 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ The [`terramate-io/terramate-action`] is a GitHub composite action that sets up - It installs a wrapper script by default so that calls to `terramate` binary will expose GitHub Action outputs to access the `stderr`, `stderr`, and the `exitcode` of the `terramate` execution. - It allows you to configure a default [Terramate Cloud] organization to use Terramate Cloud Features like Drift Detection and Stack Health Information. -## Compatbility +## Compatibility -The action currently only supports `ubuntu` runners. +The action currently only supports `ubuntu` and `macos` runners. Please open an issue, if more runner support is required. ## Usage diff --git a/install.sh b/install.sh index 96a143b..01b3fd5 100755 --- a/install.sh +++ b/install.sh @@ -18,7 +18,7 @@ get_latest_version() { echo >&2 "latest version: Getting latest Terramate release information from GitHub Releases" latest_url="https://api.github.com/repos/terramate-io/terramate/releases/latest" - latest_json=$(curl -s "${latest_url}") + latest_json=$(curl -s -H "Authorization: Bearer ${GITHUB_TOKEN}" "${latest_url}") tag_version=$(jq -r .tag_name <<<"${latest_json}") if [ -z "${tag_version}" ] || [ "${tag_version}" == "null" ] ; then @@ -86,7 +86,29 @@ install() { tmpdir=$(mktemp -d) echo >&2 "install: Created tmp directory at ${tmpdir}" - url="https://github.com/terramate-io/terramate/releases/download/v${version}/terramate_${version}_linux_x86_64.tar.gz" + system=$(uname -s | tr '[:upper:]' '[:lower:]') + arch=$(uname -m) + + if ! [[ "${system}" =~ ^(linux|darwin)$ ]]; then + echo >&2 "install: Unsupported system ${system}." + exit 1 + fi + + case "${arch}" in + x86_64|x64) arch=x86_64 ;; + aarch64|arm64) arch=arm64 ;; + i386|i686) arch=i386 ;; + *) echo >&2 "install: Unsupported architecture ${arch}." && exit 1 ;; + esac + + if [ "${system}" == "darwin" ] && [ "${arch}" == "i386" ] ; then + echo >&2 "install: Unsupported architecture: darwin/i386" + exit 1 + fi + + echo >&2 "install: Downloading terramate binary for ${system}/${arch}" + + url="https://github.com/terramate-io/terramate/releases/download/v${version}/terramate_${version}_${system}_${arch}.tar.gz" status=$(curl -w "%{http_code}" -o "${tmpdir}/terramate.tar.gz" -L "${url}") if [ "${status}" != "200" ] ; then