Skip to content
Merged
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
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A GitHub Action to download and install the Aptos CLI on CI environments (Linux/
- ✅ **Flexible versioning**: Use latest release or specify a specific version
- ✅ **Automatic PATH setup**: CLI is automatically added to PATH for subsequent steps
- ✅ **Installation verification**: Verifies the installation by checking the CLI version
- ✅ **GitHub token required**: Uses GitHub token for API access and movefmt download

## Usage

Expand All @@ -17,6 +18,8 @@ A GitHub Action to download and install the Aptos CLI on CI environments (Linux/
```yaml
- name: Setup Aptos CLI
uses: WGB5445/aptos-cli-setup@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
```

### Specify a Version
Expand All @@ -25,9 +28,22 @@ A GitHub Action to download and install the Aptos CLI on CI environments (Linux/
- name: Setup Aptos CLI
uses: WGB5445/aptos-cli-setup@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version: "7.5.0"
```

### GitHub Token Required

A GitHub token is required for downloading movefmt:

```yaml
- name: Setup Aptos CLI
uses: WGB5445/aptos-cli-setup@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version: "latest"
```

### Complete Workflow Example

```yaml
Expand Down Expand Up @@ -56,6 +72,8 @@ jobs:

- name: Setup Aptos CLI
uses: WGB5445/aptos-cli-setup@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Test Aptos CLI
run: |
Expand All @@ -68,6 +86,11 @@ jobs:
| Input | Description | Required | Default |
|-------|-------------|----------|---------|
| `version` | Aptos CLI version (tag). Use 'latest' to automatically fetch the latest release | No | `latest` |
| `install-dir` | Install directory for Aptos CLI (will install to <dir>/bin) | No | `$HOME/.aptoscli` |
| `movefmt-username` | GitHub username for movefmt repository | No | `movebit` |
| `movefmt-repo` | GitHub repository name for movefmt | No | `movefmt` |
| `movefmt-version` | movefmt version to install | No | `1.2.3` |
| `github-token` | GitHub token for API access (required for downloading movefmt) | Yes | - |

## Outputs

Expand Down Expand Up @@ -130,6 +153,26 @@ The repository includes a test workflow (`.github/workflows/test.yml`) that test
1. **Download fails**: Check if the version exists in the [Aptos releases](https://github.com/aptos-labs/aptos-core/releases)
2. **Unsupported OS/Arch**: The action will fail with a clear error message for unsupported combinations
3. **PATH not set**: The action automatically adds the CLI to PATH, but you can manually add it if needed
4. **GitHub API errors**: The action includes retry logic and better error handling for API rate limits

### GitHub API Issues

If you encounter GitHub API errors, the action now includes:

- **Better error messages**: Clear guidance on what went wrong and how to fix it
- **GitHub token required**: Uses `${{ github.token }}` for API access and movefmt download

**Common causes of API errors:**
- **Missing token**: GitHub token is required for downloading movefmt
- **Rate limiting**: GitHub limits API requests
- **Network issues**: Temporary connectivity problems
- **Repository access**: The repositories might be temporarily unavailable

**Solutions:**
1. **Provide GitHub token**: Always include `github-token: ${{ secrets.GITHUB_TOKEN }}`
2. **Use a specific version**: Instead of `latest`, specify a version like `7.5.0`
3. **Check network**: Ensure your runner has internet access
4. **Check token permissions**: Ensure the token has appropriate permissions

### Debug Mode

Expand Down
103 changes: 100 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ inputs:
description: "Install directory for Aptos CLI (will install to <dir>/bin)"
required: false
default: $HOME/.aptoscli
movefmt-username:
description: "GitHub username for movefmt repository"
required: false
default: "movebit"
movefmt-repo:
description: "GitHub repository name for movefmt"
required: false
default: "movefmt"
movefmt-version:
description: "movefmt version to install"
required: false
default: "1.2.3"
github-token:
description: "GitHub token for API access (for higher rate limits and private repos)"
required: false
default: ${{ github.token }}
runs:
using: "composite"
steps:
Expand All @@ -21,7 +37,12 @@ runs:
run: |
if [ "${{ inputs.version }}" = "latest" ]; then
# Get all releases and find the latest CLI release
TAG=$(curl -s https://api.github.com/repos/aptos-labs/aptos-core/releases \
# Require token for API access
if [ -z "${{ inputs.github-token }}" ]; then
echo "Error: github-token is required for fetching latest version from GitHub API"
exit 1
fi
TAG=$(curl -H "Authorization: token ${{ inputs.github-token }}" -s https://api.github.com/repos/aptos-labs/aptos-core/releases \
| grep '"tag_name":' | grep 'aptos-cli-v' | head -1 | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$TAG" ]; then
echo "Error: Failed to fetch latest CLI version from GitHub API"
Expand Down Expand Up @@ -94,7 +115,12 @@ runs:
- name: Download ZIP archive
shell: bash
run: |
curl -L "${{ steps.dl.outputs.url }}" -o aptos.zip
# Require token for download
if [ -z "${{ inputs.github-token }}" ]; then
echo "Error: github-token is required for downloading Aptos CLI"
exit 1
fi
curl -H "Authorization: token ${{ inputs.github-token }}" -L "${{ steps.dl.outputs.url }}" -o aptos.zip
if [ ! -f aptos.zip ]; then
echo "Error: Failed to download Aptos CLI from ${{ steps.dl.outputs.url }}"
exit 1
Expand Down Expand Up @@ -130,4 +156,75 @@ runs:
- name: Install movefmt CLI
shell: bash
run: |
aptos update movefmt --assume-yes --install-dir "${{ inputs.install-dir }}/bin"
# Detect OS and arch for movefmt asset naming
case "${RUNNER_OS}" in
Linux)
os_name="unknown-linux-gnu"
;;
macOS)
os_name="apple-darwin"
;;
Windows)
os_name="windows"
;;
*)
echo "Unsupported OS: $RUNNER_OS" && exit 1
;;
esac

# Detect architecture for movefmt asset naming
arch_lc=$(echo "${RUNNER_ARCH}" | tr '[:upper:]' '[:lower:]')
case "$arch_lc" in
x86|x64|x86_64)
arch_name="x86_64"
;;
arm|arm64|aarch64)
arch_name="aarch64"
;;
*)
echo "Unsupported architecture: $arch_lc" && exit 1
;;
esac

# Build movefmt download URL based on actual release naming
if [ "$RUNNER_OS" = "Windows" ]; then
movefmt_asset="movefmt.v${{ inputs.movefmt-version }}-${arch_name}-${os_name}.exe"
else
movefmt_asset="movefmt.v${{ inputs.movefmt-version }}-${arch_name}-${os_name}"
fi
movefmt_url="https://github.com/${{ inputs.movefmt-username }}/${{ inputs.movefmt-repo }}/releases/download/v${{ inputs.movefmt-version }}/${movefmt_asset}"

echo "Downloading movefmt from: $movefmt_url"

# Download movefmt
if [ "$RUNNER_OS" = "Windows" ]; then
# Require token for download
if [ -z "${{ inputs.github-token }}" ]; then
echo "Error: github-token is required for downloading movefmt"
exit 1
fi
curl -H "Authorization: token ${{ inputs.github-token }}" -L "$movefmt_url" -o movefmt.exe
if [ ! -f movefmt.exe ]; then
echo "Error: Failed to download movefmt from $movefmt_url"
exit 1
fi
# Install on Windows
mkdir -p "${{ inputs.install-dir }}/bin"
mv movefmt.exe "${{ inputs.install-dir }}/bin/"
else
# Require token for download
if [ -z "${{ inputs.github-token }}" ]; then
echo "Error: github-token is required for downloading movefmt"
exit 1
fi
curl -H "Authorization: token ${{ inputs.github-token }}" -L "$movefmt_url" -o movefmt
if [ ! -f movefmt ]; then
echo "Error: Failed to download movefmt from $movefmt_url"
exit 1
fi
# Install on Linux/macOS
chmod +x movefmt
mv movefmt "${{ inputs.install-dir }}/bin/"
fi

echo "movefmt installed successfully"
Loading