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
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# aptos-move-lint-github-action
Github action for running `aptos move lint`
# Aptos Move Lint — GitHub Action

Composite action that runs `aptos move lint` using the npm‑delivered Aptos CLI (`npx @aptos-labs/aptos-cli`). Fast to adopt, no build step, and works across repos with one line in your workflow.

Supported runners: Ubuntu and macOS

## Usage

```yaml
- uses: aptos-labs/aptos-move-lint-action@v1
with:
version: "latest" # npm wrapper version (not the CLI binary)
path-glob: "**/Move.toml" # glob of Move package manifests
checks: "strict" # default|strict|experimental
named-addresses: "" # e.g. std=0x1,Admin=0xa11ce
args: "" # extra args passed to the linter
fail-on-warnings: "true" # fail if warnings are found
```

## Inputs

- `version` (default: `latest`) — npm version of `@aptos-labs/aptos-cli` to use with `npx`.
- `path-glob` (default: `**/Move.toml`) — glob pattern for Move package manifests.
- `named-addresses` (default: empty) — comma‑separated list, e.g. `std=0x1,Admin=0xa11ce`.
- `checks` (default: `default`) — one of `default|strict|experimental`.
- `args` (default: empty) — extra args passed through to `aptos move lint`.
- `fail-on-warnings` (default: `true`) — when `true`, warnings cause the job to fail.

## How it works

- Sets up Node 20 and uses `npx -p @aptos-labs/aptos-cli@<version>` to invoke the CLI.
- Finds `Move.toml` files with portable `find -path` matching your `path-glob`,
deduplicates their directories, and lints each package.
- Captures lint output and optionally treats warnings as failures.

## Examples

This repo includes runnable GitHub Actions examples:

- `examples/github-actions/lint-basic.yml` — single Ubuntu job, warnings fail.
- `examples/github-actions/lint-strict-matrix.yml` — matrix across Ubuntu/macOS and checks (default/strict).
- `examples/github-actions/lint-nonfatal.yml` — warnings allowed (do not fail the job).

There is also a minimal Move package used by the examples at `examples/basic-move/` that intentionally triggers a linter warning (an unused variable) so you can see failure/behavior differences when `fail-on-warnings` is toggled.

Tip: In your own repo, set `path-glob` to match your packages (e.g. `**/Move.toml`) and consider a matrix to validate both Ubuntu and macOS.
97 changes: 97 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: "Aptos Move Lint"
description: "Run `aptos move lint` via npm-delivered Aptos CLI (npx)"
author: "Aptos Labs"
branding:
icon: "check-circle"
color: "green"

inputs:
version:
description: "npm version of @aptos-labs/aptos-cli"
default: "latest"
path-glob:
description: "Glob for Move packages (Move.toml paths)"
default: "**/Move.toml"
named-addresses:
description: "e.g. std=0x1,Admin=0xa11ce"
default: ""
checks:
description: "default|strict|experimental"
default: "default"
args:
description: "extra args to pass to linter"
default: ""
fail-on-warnings:
description: "fail build if warnings"
default: "true"

runs:
using: "composite"
steps:
- uses: actions/setup-node@v4
with:
node-version: "20"

- name: Lint Move packages
shell: bash
run: |
set -euo pipefail

# Compile package list
patterns_raw=${{ inputs.path-glob }}

# Prevent pathname expansion while splitting patterns on whitespace
set -f
set -- $patterns_raw
set +f

# Find Move.toml files matching any provided pattern and dedupe their directories
pkg_dirs=$(
for p in "$@"; do
find . -type f -path "$p" -name 'Move.toml' -print 2>/dev/null || true
done |
while IFS= read -r f; do dirname "$f"; done |
sort -u
)

# Read into an array
pkgs=()
while IFS= read -r d; do
[[ -n "$d" && -d "$d" ]] && pkgs+=("$d")
done <<< "$pkg_dirs"

if [[ ${#pkgs[@]} -eq 0 ]]; then
echo "No Move packages found after filtering."
exit 0
fi

# Informational: print CLI version actually running
npx --yes -p @aptos-labs/aptos-cli@${{ inputs.version }} aptos --version || true

STATUS=0
for D in "${pkgs[@]}"; do
echo "::group::Lint $D"

CMD=(npx --yes -p @aptos-labs/aptos-cli@${{ inputs.version }} aptos move lint --package-dir "$D" --checks "${{ inputs.checks }}")
if [[ -n "${{ inputs.named-addresses }}" ]]; then
CMD+=(--named-addresses "${{ inputs.named-addresses }}")
fi

set +e
OUT=$("${CMD[@]}" ${{ inputs.args }} 2>&1)
RC=$?
set -e

echo "$OUT"
if [[ $RC -ne 0 ]]; then
STATUS=1
fi
if [[ "${{ inputs.fail-on-warnings }}" == "true" ]]; then
if echo "$OUT" | grep -iwq 'warning'; then
STATUS=1
fi
fi
echo "::endgroup::"
done

exit $STATUS
7 changes: 7 additions & 0 deletions examples/basic-move/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "lint_example"
version = "0.0.0"

[addresses]
Example = "0x1"

7 changes: 7 additions & 0 deletions examples/basic-move/sources/unused.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module example::unused {
/// trivial function with an intentionally unused variable to trigger a lint warning
public fun hello(): u64 {
let unused: u64 = 0u64; // expect: unused variable warning
42u64
}
}
17 changes: 17 additions & 0 deletions examples/github-actions/lint-basic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Move Lint (basic)

on:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lint Move packages
uses: aptos-labs/aptos-move-lint-action@v1
with:
version: latest
path-glob: ./examples/basic-move/Move.toml
checks: default
fail-on-warnings: "true"
17 changes: 17 additions & 0 deletions examples/github-actions/lint-nonfatal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Move Lint (non-fatal warnings)

on:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lint Move packages (allow warnings)
uses: aptos-labs/aptos-move-lint-action@v1
with:
version: latest
path-glob: ./examples/basic-move/Move.toml
checks: default
fail-on-warnings: "false"
22 changes: 22 additions & 0 deletions examples/github-actions/lint-strict-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Move Lint (strict, matrix)

on:
workflow_dispatch:

jobs:
lint:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
checks: [default, strict]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Lint Move packages (matrix)
uses: aptos-labs/aptos-move-lint-action@v1
with:
version: latest
path-glob: ./examples/basic-move/Move.toml
checks: ${{ matrix.checks }}
fail-on-warnings: "true"