diff --git a/.github/workflows/test-installer.yml b/.github/workflows/test-installer.yml new file mode 100644 index 000000000..03366dd9d --- /dev/null +++ b/.github/workflows/test-installer.yml @@ -0,0 +1,95 @@ +name: Test installer.sh + +on: + workflow_dispatch: + inputs: + version: + description: 'CLI version to install (leave empty for latest release)' + required: false + type: string + push: + branches: + - main + paths: + - installer.sh + pull_request: + paths: + - installer.sh + +permissions: + contents: read + +jobs: + linux: + runs-on: ubuntu-latest + container: ${{ matrix.image }} + + strategy: + fail-fast: false + matrix: + include: + - image: debian:bookworm + method: apt + - image: ubuntu:24.04 + method: apt + - image: fedora:41 + method: yum + - image: alpine:3.21 + method: apk + - image: debian:bookworm + method: raw + + steps: + - name: Install prerequisites + run: | + case "${{ matrix.method }}" in + apt) + apt-get update && apt-get install -y curl ca-certificates + ;; + yum) + yum install -y curl + ;; + apk) + apk add --no-cache curl ca-certificates + ;; + raw) + apt-get update && apt-get install -y curl ca-certificates gzip + ;; + esac + + - name: Check out repository + uses: actions/checkout@v4 + + - name: Run installer + env: + INSTALL_METHOD: ${{ matrix.method }} + GITHUB_TOKEN: ${{ github.token }} + VERSION: ${{ inputs.version }} + run: sh installer.sh + + - name: Verify installation + run: upsun --version + + macos: + runs-on: macos-latest + + strategy: + fail-fast: false + matrix: + method: + - homebrew + - raw + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Run installer + env: + INSTALL_METHOD: ${{ matrix.method }} + GITHUB_TOKEN: ${{ github.token }} + VERSION: ${{ inputs.version }} + run: sh installer.sh + + - name: Verify installation + run: upsun --version diff --git a/scripts/test/installer.sh b/scripts/test/installer.sh new file mode 100755 index 000000000..6d4e7801f --- /dev/null +++ b/scripts/test/installer.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# Test installer.sh across Linux distros using Docker. +# Requires Docker to be installed and running. +# macOS methods (homebrew, raw) are only tested in CI (GitHub Actions). + +set -eu + +cd "$(dirname "$0")/../.." + +: "${VERSION:=}" + +pass=0 +fail=0 +errors="" + +run_test() { + image="$1" + method="$2" + prereqs="$3" + + label="${image} (${method})" + echo "" + echo "=== ${label} ===" + + version_flag="" + if [ -n "$VERSION" ]; then + version_flag="-e VERSION=$VERSION" + fi + + if docker run --rm \ + -v "$(pwd)/installer.sh:/installer.sh:ro" \ + -e INSTALL_METHOD="$method" \ + $version_flag \ + "$image" \ + sh -c "${prereqs}sh /installer.sh && upsun --version"; then + echo "--- PASS: ${label} ---" + pass=$((pass + 1)) + else + echo "--- FAIL: ${label} ---" + fail=$((fail + 1)) + errors="${errors} ${label}\n" + fi +} + +echo "installer.sh test suite" +echo "=======================" + +run_test "debian:bookworm" "apt" \ + "apt-get update -qq && apt-get install -y -qq curl ca-certificates && " + +run_test "ubuntu:24.04" "apt" \ + "apt-get update -qq && apt-get install -y -qq curl ca-certificates && " + +run_test "fedora:41" "yum" \ + "yum install -y -q curl && " + +run_test "alpine:3.21" "apk" \ + "apk add -q --no-cache curl ca-certificates && " + +run_test "debian:bookworm" "raw" \ + "apt-get update -qq && apt-get install -y -qq curl ca-certificates gzip && " + +echo "" +echo "=======================" +echo "Results: ${pass} passed, ${fail} failed" + +if [ "$fail" -gt 0 ]; then + printf "\nFailed:\n%b" "$errors" + exit 1 +fi