fix(ci): 'should use swiftlint version from env not inputs' (#1025)

* fix(ci): 'should use swiftlint version from env not inputs'

* fix(ci): remove `-it`

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Muhammad Nur Faiz <229660710+Meiw0@users.noreply.github.com>
This commit is contained in:
LemonNeko
2026-02-06 22:55:48 +08:00
co-authored by autofix-ci[bot] Muhammad Nur Faiz
parent 9cc2a9a206
commit 9e5034fffc
5 changed files with 9 additions and 213 deletions
-72
View File
@@ -1,72 +0,0 @@
# Setup SwiftLint Action
A reusable GitHub Action that downloads and installs SwiftLint binary from [SwiftLint releases](https://github.com/realm/SwiftLint/releases/) to `/usr/bin`.
## Usage
### Basic usage
```yaml
- uses: ./.github/actions/setup-swiftlint
```
This will install the latest version of SwiftLint.
### Specify version
```yaml
- uses: ./.github/actions/setup-swiftlint
with:
version: '0.58.2'
```
Or use version with `v` prefix:
```yaml
- uses: ./.github/actions/setup-swiftlint
with:
version: 'v0.58.2'
```
## Inputs
| Input | Description | Required | Default |
|-------|-------------|----------|---------|
| `version` | SwiftLint version (e.g., `0.58.2`). If not specified, the latest version will be used | No | `latest` |
## Example workflow
```yaml
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install SwiftLint
uses: ./.github/actions/setup-swiftlint
with:
version: '0.58.2'
- name: Run SwiftLint
run: swiftlint
```
## Supported operating systems
- macOS
- Linux
## Notes
- This action requires `sudo` permissions to install the binary to `/usr/bin`
- After installation, the `swiftlint` command will be globally available in PATH
- If the specified version does not exist, the action will fail with an error message
-134
View File
@@ -1,134 +0,0 @@
name: 'Setup SwiftLint'
description: 'Download and install SwiftLint binary to /usr/bin'
branding:
icon: 'code'
color: 'blue'
inputs:
version:
description: 'SwiftLint version (e.g., 0.58.2). If not specified, the latest version will be used'
required: false
default: 'latest'
runs:
using: 'composite'
steps:
- name: Detect OS and architecture
id: os
shell: bash
run: |
ARCH=$(uname -m)
if [[ "$ARCH" == "x86_64" ]]; then
ARCH_SUFFIX="amd64"
elif [[ "$ARCH" == "aarch64" ]] || [[ "$ARCH" == "arm64" ]]; then
ARCH_SUFFIX="arm64"
else
echo "Error: Unsupported architecture $ARCH"
exit 1
fi
if [[ "$RUNNER_OS" == "macOS" ]]; then
echo "platform=macos" >> $GITHUB_OUTPUT
echo "archive_name=portable_swiftlint.zip" >> $GITHUB_OUTPUT
elif [[ "$RUNNER_OS" == "Linux" ]]; then
echo "platform=linux" >> $GITHUB_OUTPUT
echo "archive_name=swiftlint_linux.zip" >> $GITHUB_OUTPUT
else
echo "Error: Unsupported OS $RUNNER_OS"
exit 1
fi
echo "arch=$ARCH_SUFFIX" >> $GITHUB_OUTPUT
- name: Resolve version
id: version
shell: bash
run: |
if [[ "${{ inputs.version }}" == "latest" ]]; then
# Fetch the latest release tag using a more robust method
CURL_ARGS=(-s)
if [[ -n "${{ github.token }}" ]]; then
CURL_ARGS+=(-H "Authorization: Bearer ${{ github.token }}")
fi
CURL_ARGS+=(-H "Accept: application/vnd.github+json")
CURL_ARGS+=(-H "X-GitHub-Api-Version: 2022-11-28")
CURL_ARGS+=("https://api.github.com/repos/realm/SwiftLint/releases/latest")
API_RESPONSE=$(curl "${CURL_ARGS[@]}")
# Try using jq if available (most GitHub Actions runners have it)
if command -v jq >/dev/null 2>&1; then
VERSION=$(echo "$API_RESPONSE" | jq -r '.tag_name // empty')
else
# Fallback: parse JSON manually with sed, being very specific about the tag_name field
VERSION=$(echo "$API_RESPONSE" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -1)
fi
# Validate the version looks correct (should contain version numbers)
if [[ -z "$VERSION" ]] || [[ "$VERSION" == "null" ]] || [[ ! "$VERSION" =~ ^[0-9] ]]; then
echo "Error: Failed to get latest version or got invalid version: '$VERSION'"
echo "API Response (first 50 lines):"
echo "$API_RESPONSE" | head -50
exit 1
fi
echo "Latest version: $VERSION"
else
VERSION="${{ inputs.version }}"
# Remove 'v' prefix if user provided it, since SwiftLint tags don't use it
VERSION="${VERSION#v}"
echo "Using specified version: $VERSION"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Download and install SwiftLint
shell: bash
run: |
set -e
PLATFORM="${{ steps.os.outputs.platform }}"
VERSION="${{ steps.version.outputs.version }}"
ARCH="${{ steps.os.outputs.arch }}"
ARCHIVE_NAME="${{ steps.os.outputs.archive_name }}"
if [[ "$PLATFORM" == "linux" ]]; then
ARCHIVE_NAME="${ARCHIVE_NAME%.zip}_${ARCH}.zip"
fi
DOWNLOAD_URL="https://github.com/realm/SwiftLint/releases/download/${VERSION}/${ARCHIVE_NAME}"
echo "Downloading SwiftLint from $DOWNLOAD_URL..."
if ! curl -L -f -o swiftlint.zip "$DOWNLOAD_URL"; then
ARCHIVE_NAME_FALLBACK="${ARCHIVE_NAME%.zip}.zip"
DOWNLOAD_URL="https://github.com/realm/SwiftLint/releases/download/${VERSION}/${ARCHIVE_NAME_FALLBACK}"
echo "Trying fallback URL: $DOWNLOAD_URL"
if ! curl -L -f -o swiftlint.zip "$DOWNLOAD_URL"; then
echo "Error: Download failed, please check if the version is correct"
exit 1
fi
fi
echo "Extracting..."
EXTRACT_DIR=$(mktemp -d)
unzip -q -o swiftlint.zip -d "$EXTRACT_DIR"
if [[ -f "$EXTRACT_DIR/swiftlint" ]]; then
BINARY_PATH="$EXTRACT_DIR/swiftlint"
elif [[ -f "$EXTRACT_DIR/swiftlint_linux/swiftlint" ]]; then
BINARY_PATH="$EXTRACT_DIR/swiftlint_linux/swiftlint"
elif [[ -f "$EXTRACT_DIR/portable_swiftlint/swiftlint" ]]; then
BINARY_PATH="$EXTRACT_DIR/portable_swiftlint/swiftlint"
else
echo "Error: Could not find swiftlint binary"
ls -la "$EXTRACT_DIR"
exit 1
fi
chmod +x "$BINARY_PATH"
sudo mv "$BINARY_PATH" /usr/bin/swiftlint
if ! swiftlint version; then
echo "Error: SwiftLint installation verification failed"
exit 1
fi
rm -rf swiftlint.zip "$EXTRACT_DIR" 2>/dev/null || true
+2 -2
View File
@@ -14,7 +14,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/setup-swiftlint
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v6
with:
@@ -24,7 +23,8 @@ jobs:
- run: pnpm install
- run: pnpm prune && pnpm dedupe
- run: pnpm run lint:fix
- run: pnpm run lint:swift --fix
- run: docker run -v `pwd`:`pwd` -w `pwd` ghcr.io/realm/swiftlint:latest --fix
working-directory: ./apps/stage-pocket
# - name: AutoCorrect
# uses: huacnlee/autocorrect-action@main
+2 -2
View File
@@ -15,7 +15,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/setup-swiftlint
- uses: pnpm/action-setup@v3
- uses: actions/setup-node@v5
with:
@@ -24,7 +23,8 @@ jobs:
- run: pnpm install --frozen-lockfile
- run: pnpm run lint
- run: pnpm run lint:swift
- run: docker run -v `pwd`:`pwd` -w `pwd` ghcr.io/realm/swiftlint:latest
working-directory: ./apps/stage-pocket
build-test:
name: Build Test (${{ matrix.app_name }})