Skip to content

Commit a7c5d83

Browse files
fankclaude
andcommitted
Fix GitHub Action failures and improve robustness
- Add GitHub token support to avoid API rate limiting - Add comprehensive error handling with set -e and error checks - Add architecture detection for x86_64 and ARM64 support - Add detailed debugging output and GitHub Actions error annotations - Create CI workflow to test the action - Update README with usage examples and troubleshooting guide 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7805329 commit a7c5d83

File tree

3 files changed

+230
-8
lines changed

3 files changed

+230
-8
lines changed

.github/workflows/test.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Test Action
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test-latest:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Test install latest version
16+
uses: ./
17+
with:
18+
github-token: ${{ secrets.GITHUB_TOKEN }}
19+
20+
- name: Verify installation
21+
run: |
22+
sqruff --version
23+
sqruff --help
24+
25+
test-specific-version:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Test install specific version
31+
uses: ./
32+
with:
33+
version: v0.28.0
34+
github-token: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Verify specific version
37+
run: |
38+
sqruff --version | grep "0.28.0"
39+
40+
test-without-token:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v4
44+
45+
- name: Test install without token
46+
uses: ./
47+
48+
- name: Verify installation
49+
run: |
50+
sqruff --version
51+
52+
test-arm64:
53+
runs-on: ubuntu-latest
54+
if: false # ARM runners not available in free tier
55+
steps:
56+
- uses: actions/checkout@v4
57+
58+
- name: Test install on ARM64
59+
uses: ./
60+
with:
61+
github-token: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,89 @@
11
# install-sqruff-cli-action
22

3-
GitHub Action to install sqruff
3+
GitHub Action to install [sqruff](https://github.com/quarylabs/sqruff), a fast SQL linter and formatter written in Rust.
4+
5+
## Features
6+
7+
- Automatically detects and installs the latest version of sqruff
8+
- Supports specifying a specific version
9+
- Handles GitHub API rate limiting with optional token
10+
- Architecture detection (supports x86_64 and ARM64)
11+
- Comprehensive error handling and debugging output
12+
- Verifies installation before completing
13+
14+
## Usage
15+
16+
### Basic usage (installs latest version)
17+
18+
```yaml
19+
- uses: quarylabs/install-sqruff-cli-action@main
20+
```
21+
22+
### With GitHub token (recommended to avoid rate limiting)
23+
24+
```yaml
25+
- uses: quarylabs/install-sqruff-cli-action@main
26+
with:
27+
github-token: ${{ secrets.GITHUB_TOKEN }}
28+
```
29+
30+
### Install specific version
31+
32+
```yaml
33+
- uses: quarylabs/install-sqruff-cli-action@main
34+
with:
35+
version: v0.28.0
36+
github-token: ${{ secrets.GITHUB_TOKEN }}
37+
```
38+
39+
## Inputs
40+
41+
| Input | Description | Required | Default |
42+
|-------|-------------|----------|---------|
43+
| `version` | Version of Sqruff CLI to install (e.g., `v0.28.0`) | No | `latest` |
44+
| `github-token` | GitHub token for API requests (helps avoid rate limiting) | No | - |
45+
46+
## Example workflow
47+
48+
```yaml
49+
name: Lint SQL
50+
51+
on: [push, pull_request]
52+
53+
jobs:
54+
lint:
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v4
58+
59+
- name: Install sqruff
60+
uses: quarylabs/install-sqruff-cli-action@main
61+
with:
62+
github-token: ${{ secrets.GITHUB_TOKEN }}
63+
64+
- name: Lint SQL files
65+
run: sqruff lint --dialect postgres .
66+
```
67+
68+
## Troubleshooting
69+
70+
### API Rate Limit Exceeded
71+
72+
If you see an error about GitHub API rate limits, make sure to provide the `github-token` input:
73+
74+
```yaml
75+
with:
76+
github-token: ${{ secrets.GITHUB_TOKEN }}
77+
```
78+
79+
### Architecture Not Supported
80+
81+
This action currently supports:
82+
- Linux x86_64 (amd64)
83+
- Linux ARM64 (aarch64)
84+
85+
Other architectures are not supported at this time.
86+
87+
## License
88+
89+
This project is licensed under the MIT License.

action.yml

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,97 @@ inputs:
88
description: 'Version of Sqruff CLI to install'
99
required: false
1010
default: 'latest'
11+
github-token:
12+
description: 'GitHub token for API requests (helps avoid rate limiting)'
13+
required: false
14+
default: ''
1115
runs:
1216
using: 'composite'
1317
steps:
1418
- run: |
19+
set -e # Exit on error
20+
21+
# Function to make GitHub API calls with optional token
22+
github_api_call() {
23+
local url=$1
24+
if [ -n "${{ inputs.github-token }}" ]; then
25+
curl -s -H "Authorization: token ${{ inputs.github-token }}" "$url"
26+
else
27+
curl -s "$url"
28+
fi
29+
}
30+
31+
# Determine version to install
1532
if [ "${{ inputs.version }}" = "latest" ]; then
16-
# Fetch the latest release tag from GitHub API without authentication
17-
LATEST_VERSION=$(curl -s https://api.github.com/repos/quarylabs/sqruff/releases/latest | grep 'tag_name' | cut -d '"' -f 4)
33+
echo "Fetching latest Sqruff release..."
34+
API_RESPONSE=$(github_api_call "https://api.github.com/repos/quarylabs/sqruff/releases/latest")
35+
36+
# Check if API call was successful
37+
if echo "$API_RESPONSE" | grep -q "API rate limit exceeded"; then
38+
echo "::error::GitHub API rate limit exceeded. Please provide a github-token input."
39+
exit 1
40+
fi
41+
42+
LATEST_VERSION=$(echo "$API_RESPONSE" | grep '"tag_name"' | cut -d '"' -f 4)
43+
44+
if [ -z "$LATEST_VERSION" ]; then
45+
echo "::error::Failed to fetch latest version from GitHub API"
46+
echo "API Response: $API_RESPONSE"
47+
exit 1
48+
fi
49+
1850
echo "Latest version is $LATEST_VERSION"
1951
VERSION=$LATEST_VERSION
2052
else
2153
VERSION=${{ inputs.version }}
2254
fi
2355
24-
echo "Installing Sqruff CLI version $VERSION"
25-
wget https://github.com/quarylabs/sqruff/releases/download/$VERSION/sqruff-linux-x86_64-musl.tar.gz -O sqruff-cli.tar.gz
26-
tar -xzf sqruff-cli.tar.gz
27-
sudo mv sqruff /usr/local/bin/sqruff
28-
sqruff --version
56+
# Detect architecture
57+
ARCH=$(uname -m)
58+
case $ARCH in
59+
x86_64)
60+
BINARY_NAME="sqruff-linux-x86_64-musl"
61+
;;
62+
aarch64|arm64)
63+
BINARY_NAME="sqruff-linux-aarch64-musl"
64+
;;
65+
*)
66+
echo "::error::Unsupported architecture: $ARCH"
67+
exit 1
68+
;;
69+
esac
70+
71+
# Download and install
72+
echo "Installing Sqruff CLI version $VERSION for architecture $ARCH"
73+
DOWNLOAD_URL="https://github.com/quarylabs/sqruff/releases/download/$VERSION/${BINARY_NAME}.tar.gz"
74+
75+
echo "Downloading from: $DOWNLOAD_URL"
76+
if ! wget -q --show-progress "$DOWNLOAD_URL" -O sqruff-cli.tar.gz; then
77+
echo "::error::Failed to download Sqruff CLI from $DOWNLOAD_URL"
78+
exit 1
79+
fi
80+
81+
echo "Extracting archive..."
82+
if ! tar -xzf sqruff-cli.tar.gz; then
83+
echo "::error::Failed to extract tarball"
84+
exit 1
85+
fi
86+
87+
echo "Installing binary..."
88+
if ! sudo mv sqruff /usr/local/bin/sqruff; then
89+
echo "::error::Failed to install sqruff binary"
90+
exit 1
91+
fi
92+
93+
# Make sure it's executable
94+
sudo chmod +x /usr/local/bin/sqruff
95+
96+
# Verify installation
97+
echo "Verifying installation..."
98+
if sqruff --version; then
99+
echo "✅ Sqruff CLI installed successfully!"
100+
else
101+
echo "::error::Failed to verify Sqruff CLI installation"
102+
exit 1
103+
fi
29104
shell: bash

0 commit comments

Comments
 (0)