Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: install supported Terramate system/arch (excluding windows). #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,44 @@ defaults:
run:
shell: bash

permissions:
contents: read

jobs:
simple:
name: Terramate latest
runs-on: ubuntu-latest
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
Expand All @@ -44,6 +58,8 @@ jobs:

- name: Install asdf Terramate
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Validate execution
run: terramate version
Expand All @@ -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
Expand All @@ -72,6 +89,8 @@ jobs:
uses: ./
with:
version: ${{ matrix.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Validate execution - ${{ matrix.version }}
run: terramate version
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/home/runner/_work/_actions/terramate-io/terramate-action/i4k-fix-macos/install.sh: line 21: GITHUB_TOKEN: unbound variable I got this error when running this line @i4ki
20232

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, this needs a fallback to be unauthenticated if the env is not set.
But the install requires fetching the latest Terramate release from Github API, so if unauthenticated you can get some rate limiting errors in your pipeline. Quick fix now is just pass the GITHUB_TOKEN to the action.

tag_version=$(jq -r .tag_name <<<"${latest_json}")

if [ -z "${tag_version}" ] || [ "${tag_version}" == "null" ] ; then
Expand Down Expand Up @@ -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
Expand Down
Loading