diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7410252 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,40 @@ +name: Test Action + +on: + pull_request: + +jobs: + test: + name: Test on ${{ matrix.os }} ${{ matrix.arch }} + runs-on: ${{ matrix.runner }} + strategy: + matrix: + include: + - os: Linux + arch: x86_64 + runner: ubuntu-latest + - os: Linux + arch: arm64 + runner: ubuntu-24.04-arm + - os: macOS + arch: x86_64 + runner: macos-15-intel + - os: macOS + arch: arm64 + runner: macos-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Roc + uses: ./ + + - name: Check Roc version + run: roc version + + - name: Download HelloWorld example + run: curl -fsSL -o main.roc https://raw.githubusercontent.com/roc-lang/examples/main/examples/HelloWorld/main.roc + + - name: Run HelloWorld example + run: roc main.roc diff --git a/README.md b/README.md index ac53aab..3728d3d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Setup Roc -A GitHub Action to download and setup the Roc compiler for Linux x86_64. +A GitHub Action to download and setup the Roc compiler for Linux and macOS. ## Usage @@ -12,16 +12,22 @@ TODO ## Platform Support -This action currently supports: -- **OS**: Linux -- **Architecture**: x86_64 +This action supports the following platforms: + +| OS | Architecture | Status | +|----|--------------|--------| +| Linux | x86_64 | ✅ | +| Linux | arm64 | ✅ | +| macOS | x86_64 (Intel) | ✅ | +| macOS | arm64 (Apple Silicon) | ✅ | ## What it does -1. Downloads the Roc compiler (`roc-linux_x86_64-alpha4-rolling.tar.gz`) from the official releases -2. Verifies the SHA256 checksum to ensure file integrity -3. Extracts the compiler -4. Adds the Roc executable to the PATH +1. Detects your operating system and architecture +2. Downloads the appropriate Roc compiler release for your platform +3. Verifies the SHA256 checksum to ensure file integrity +4. Extracts the compiler +5. Adds the Roc executable to the PATH ## Security diff --git a/action.yml b/action.yml index 6081d27..1a6775e 100644 --- a/action.yml +++ b/action.yml @@ -12,25 +12,69 @@ runs: run: | set -euo pipefail - # Check if running on Linux x86_64 - if [[ "$OSTYPE" != "linux-gnu"* ]]; then - echo "Error: This action currently only supports Linux" - exit 1 - fi + # Detect OS and architecture + OS=$(uname -s) + ARCH=$(uname -m) - if [[ "$(uname -m)" != "x86_64" ]]; then - echo "Error: This action currently only supports x86_64 architecture" - exit 1 - fi + echo "Detected OS: $OS" + echo "Detected architecture: $ARCH" + + # Determine platform-specific values + case "$OS" in + Linux) + case "$ARCH" in + x86_64) + PLATFORM="linux_x86_64" + EXPECTED_SHA="96e8be05e6f7176433ada74532ff36a62b8dc44c5247a82cdf919f2dadc5178b" + DIR_PATTERN="roc_nightly-linux_x86_64-*" + SHA_CMD="sha256sum" + ;; + aarch64|arm64) + PLATFORM="linux_arm64" + EXPECTED_SHA="95558e2b5564b9f2b19fb29ad7df440d4ef7163dea571ffcd39409ef678ecccf" + DIR_PATTERN="roc_nightly-linux_arm64-*" + SHA_CMD="sha256sum" + ;; + *) + echo "Error: Unsupported Linux architecture: $ARCH" + exit 1 + ;; + esac + ;; + Darwin) + case "$ARCH" in + x86_64) + PLATFORM="macos_x86_64" + EXPECTED_SHA="e8378bdec9fbeaf8f7bae49159a7b43d42050b047375521799984311dcda7078" + DIR_PATTERN="roc_nightly-macos_x86_64-*" + SHA_CMD="shasum -a 256" + ;; + arm64) + PLATFORM="macos_apple_silicon" + EXPECTED_SHA="416fbd983280eda11ac87b0947e27bf0a86d186a94baebeb71e163942bb5bd84" + DIR_PATTERN="roc_nightly-macos_apple_silicon-*" + SHA_CMD="shasum -a 256" + ;; + *) + echo "Error: Unsupported macOS architecture: $ARCH" + exit 1 + ;; + esac + ;; + *) + echo "Error: Unsupported operating system: $OS" + exit 1 + ;; + esac # Download Roc - echo "Downloading Roc for Linux x86_64..." - curl -fsSL -o roc.tar.gz https://github.com/roc-lang/roc/releases/download/alpha4-rolling/roc-linux_x86_64-alpha4-rolling.tar.gz + DOWNLOAD_URL="https://github.com/roc-lang/roc/releases/download/alpha4-rolling/roc-${PLATFORM}-alpha4-rolling.tar.gz" + echo "Downloading Roc for $PLATFORM..." + curl -fsSL -o roc.tar.gz "$DOWNLOAD_URL" # Verify SHA256 checksum echo "Verifying SHA256 checksum..." - EXPECTED_SHA="96e8be05e6f7176433ada74532ff36a62b8dc44c5247a82cdf919f2dadc5178b" - ACTUAL_SHA=$(sha256sum roc.tar.gz | awk '{print $1}') + ACTUAL_SHA=$($SHA_CMD roc.tar.gz | awk '{print $1}') if [[ "$ACTUAL_SHA" != "$EXPECTED_SHA" ]]; then echo "Error: SHA256 checksum mismatch!" @@ -48,7 +92,7 @@ runs: rm roc.tar.gz # Find the extracted directory and add to PATH - ROC_DIR=$(find . -maxdepth 1 -type d -name "roc_nightly-linux_x86_64-*" | head -n 1) + ROC_DIR=$(find . -maxdepth 1 -type d -name "$DIR_PATTERN" | head -n 1) if [[ -z "$ROC_DIR" ]]; then echo "Error: Could not find extracted Roc directory" exit 1