Skip to content
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
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,40 @@ jobs:
uses: ./
with:
version: 'v0.4.0'

- name: Verify Installation
run: sqruff --version

test-with-token:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Test Install with GitHub Token
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Verify Installation
run: |
sqruff --version
sqruff --help

test-specific-version-with-token:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Test Install Specific Version with Token
uses: ./
with:
version: 'v0.28.0'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Verify Specific Version
run: |
# Verify sqruff runs successfully
sqruff --version
sqruff --help
88 changes: 87 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,89 @@
# install-sqruff-cli-action

GitHub Action to install sqruff
GitHub Action to install [sqruff](https://github.com/quarylabs/sqruff), a fast SQL linter and formatter written in Rust.

## Features

- Automatically detects and installs the latest version of sqruff
- Supports specifying a specific version
- Handles GitHub API rate limiting with optional token
- Architecture detection (supports x86_64 and ARM64)
- Comprehensive error handling and debugging output
- Verifies installation before completing

## Usage

### Basic usage (installs latest version)

```yaml
- uses: quarylabs/install-sqruff-cli-action@main
```

### With GitHub token (recommended to avoid rate limiting)

```yaml
- uses: quarylabs/install-sqruff-cli-action@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
```

### Install specific version

```yaml
- uses: quarylabs/install-sqruff-cli-action@main
with:
version: v0.28.0
github-token: ${{ secrets.GITHUB_TOKEN }}
```

## Inputs

| Input | Description | Required | Default |
|-------|-------------|----------|---------|
| `version` | Version of Sqruff CLI to install (e.g., `v0.28.0`) | No | `latest` |
| `github-token` | GitHub token for API requests (helps avoid rate limiting) | No | - |

## Example workflow

```yaml
name: Lint SQL

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install sqruff
uses: quarylabs/install-sqruff-cli-action@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Lint SQL files
run: sqruff lint --dialect postgres .
```

## Troubleshooting

### API Rate Limit Exceeded

If you see an error about GitHub API rate limits, make sure to provide the `github-token` input:

```yaml
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
```

### Architecture Not Supported

This action currently supports:
- Linux x86_64 (amd64)
- Linux ARM64 (aarch64)

Other architectures are not supported at this time.

## License

This project is licensed under the MIT License.
89 changes: 82 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,97 @@ inputs:
description: 'Version of Sqruff CLI to install'
required: false
default: 'latest'
github-token:
description: 'GitHub token for API requests (helps avoid rate limiting)'
required: false
default: ''
runs:
using: 'composite'
steps:
- run: |
set -e # Exit on error

# Function to make GitHub API calls with optional token
github_api_call() {
local url=$1
if [ -n "${{ inputs.github-token }}" ]; then
curl -s -H "Authorization: token ${{ inputs.github-token }}" "$url"
else
curl -s "$url"
fi
}

# Determine version to install
if [ "${{ inputs.version }}" = "latest" ]; then
# Fetch the latest release tag from GitHub API without authentication
LATEST_VERSION=$(curl -s https://api.github.com/repos/quarylabs/sqruff/releases/latest | grep 'tag_name' | cut -d '"' -f 4)
echo "Fetching latest Sqruff release..."
API_RESPONSE=$(github_api_call "https://api.github.com/repos/quarylabs/sqruff/releases/latest")

# Check if API call was successful
if echo "$API_RESPONSE" | grep -q "API rate limit exceeded"; then
echo "::error::GitHub API rate limit exceeded. Please provide a github-token input."
exit 1
fi

LATEST_VERSION=$(echo "$API_RESPONSE" | grep '"tag_name"' | cut -d '"' -f 4)

if [ -z "$LATEST_VERSION" ]; then
echo "::error::Failed to fetch latest version from GitHub API"
echo "API Response: $API_RESPONSE"
exit 1
fi

echo "Latest version is $LATEST_VERSION"
VERSION=$LATEST_VERSION
else
VERSION=${{ inputs.version }}
fi

echo "Installing Sqruff CLI version $VERSION"
wget https://github.com/quarylabs/sqruff/releases/download/$VERSION/sqruff-linux-x86_64-musl.tar.gz -O sqruff-cli.tar.gz
tar -xzf sqruff-cli.tar.gz
sudo mv sqruff /usr/local/bin/sqruff
sqruff --version
# Detect architecture
ARCH=$(uname -m)
case $ARCH in
x86_64)
BINARY_NAME="sqruff-linux-x86_64-musl"
;;
aarch64|arm64)
BINARY_NAME="sqruff-linux-aarch64-musl"
;;
*)
echo "::error::Unsupported architecture: $ARCH"
exit 1
;;
esac

# Download and install
echo "Installing Sqruff CLI version $VERSION for architecture $ARCH"
DOWNLOAD_URL="https://github.com/quarylabs/sqruff/releases/download/$VERSION/${BINARY_NAME}.tar.gz"

echo "Downloading from: $DOWNLOAD_URL"
if ! wget -q --show-progress "$DOWNLOAD_URL" -O sqruff-cli.tar.gz; then
echo "::error::Failed to download Sqruff CLI from $DOWNLOAD_URL"
exit 1
fi

echo "Extracting archive..."
if ! tar -xzf sqruff-cli.tar.gz; then
echo "::error::Failed to extract tarball"
exit 1
fi

echo "Installing binary..."
if ! sudo mv sqruff /usr/local/bin/sqruff; then
echo "::error::Failed to install sqruff binary"
exit 1
fi

# Make sure it's executable
sudo chmod +x /usr/local/bin/sqruff

# Verify installation
echo "Verifying installation..."
if sqruff --version; then
echo "✅ Sqruff CLI installed successfully!"
else
echo "::error::Failed to verify Sqruff CLI installation"
exit 1
fi
shell: bash