Skip to content
Draft
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
66 changes: 58 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ inputs:
terminus-version:
description: |
The full version of Terminus to install. If omitted, the latest version is used.
For deterministic builds, specifying a version is recommended.
required: false
disable-cache:
description: Disable session cache and force a new session to be initiated.
required: false
default: false
default: "false"

runs:
using: composite
Expand All @@ -23,23 +24,72 @@ runs:
if: ${{ ! inputs.terminus-version }}
shell: bash
run: |
TERMINUS_RELEASE=$(
curl --silent \
echo "Attempting to find latest Terminus version..."
# Try to get the latest release from GitHub API with proper error handling
if ! TERMINUS_RELEASE=$(curl --silent --fail --max-time 10 \
--header 'authorization: Bearer ${{ github.token }}' \
"https://api.github.com/repos/pantheon-systems/terminus/releases/latest" \
| perl -nle'print $& while m#"tag_name": "\K[^"]*#g'
)
| perl -nle'print $& while m#"tag_name": "\K[^"]*#g'); then
echo "::error::Failed to connect to GitHub API to determine latest Terminus version."
echo "::error::Please specify a terminus-version input parameter for deterministic builds."
exit 1
fi

# Validate we got a proper version string (should be semver format)
if [[ -z "$TERMINUS_RELEASE" || ! "$TERMINUS_RELEASE" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Unable to determine a valid Terminus version from GitHub API."
echo "::error::Please specify a terminus-version input parameter for deterministic builds."
exit 1
fi

echo "Latest Terminus version detected: $TERMINUS_RELEASE"
echo "TERMINUS_RELEASE=$TERMINUS_RELEASE" >> $GITHUB_ENV

- name: Install Terminus
shell: bash
run: |
mkdir $HOME/terminus && cd $HOME/terminus
mkdir -p $HOME/terminus && cd $HOME/terminus
echo "Installing Terminus v$TERMINUS_RELEASE"
curl -L https://github.com/pantheon-systems/terminus/releases/download/$TERMINUS_RELEASE/terminus.phar --output terminus

# Download Terminus with validation
if ! curl --fail -L https://github.com/pantheon-systems/terminus/releases/download/$TERMINUS_RELEASE/terminus.phar --output terminus; then
echo "::error::Failed to download Terminus v$TERMINUS_RELEASE"
exit 1
fi

# Download checksum for verification
if curl --fail -L https://github.com/pantheon-systems/terminus/releases/download/$TERMINUS_RELEASE/terminus.phar.sha256 --output terminus.sha256; then
echo "Verifying download integrity..."
# Fix the checksum file format if needed (ensure it only contains hash and filename)
sed -i.bak 's/^.*\([0-9a-f]\{64\}\).*$/\1 terminus/g' terminus.sha256
if ! sha256sum -c terminus.sha256; then
echo "::error::Checksum verification failed! The downloaded file may be corrupted."
exit 1
fi
echo "Integrity verification passed."
else
echo "::warning::Could not download checksum file. Skipping integrity check."
fi

# Basic file type verification
file_info=$(file terminus)
if ! echo "$file_info" | grep -q -E 'PHP script|executable|.+ASCII.+PHP'; then
echo "::error::Downloaded file is not a PHP script or executable. Got: $file_info"
exit 1
fi

# Make executable and create symlink
chmod +x terminus
sudo ln -s $HOME/terminus/terminus /usr/local/bin/terminus
sudo ln -sf $HOME/terminus/terminus /usr/local/bin/terminus
mkdir -p $HOME/.terminus/{cache,plugins}

# Verify installation
echo "Verifying Terminus installation..."
if ! terminus --version; then
echo "::error::Terminus installation verification failed."
exit 1
fi
echo "Terminus installation successful."
env:
TERMINUS_RELEASE: ${{ inputs.terminus-version || env.TERMINUS_RELEASE }}

Expand Down
Loading