From aeabef547a26b5c2cdd9d636b5251beb599f079c Mon Sep 17 00:00:00 2001 From: WGB5445 <919603023@qq.com> Date: Fri, 4 Jul 2025 12:49:21 +0800 Subject: [PATCH 1/7] Refactor caching mechanism for Aptos and movefmt CLI installations in action.yml - Updated cache keys to include 'aptos-setup' and 'movefmt-version' for better cache management. - Removed the previous cache step for movefmt and integrated its logic into the Aptos caching process. - Adjusted conditional checks to ensure proper installation flow based on cache hits. --- action.yml | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/action.yml b/action.yml index 46d55e2..76f669f 100644 --- a/action.yml +++ b/action.yml @@ -72,11 +72,12 @@ runs: uses: actions/cache@v4 with: path: ${{ inputs.install-dir }}/bin - key: aptos-cli-${{ steps.get_version.outputs.version }}-${{ runner.os }}-${{ runner.arch }} + key: aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ runner.os }}-${{ runner.arch }} restore-keys: | - aptos-cli-${{ steps.get_version.outputs.version }}-${{ runner.os }}- - aptos-cli-${{ steps.get_version.outputs.version }}- - aptos-cli- + aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ runner.os }}- + aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}- + aptos-setup-${{ steps.get_version.outputs.version }}- + aptos-setup- - name: Build download URL id: dl @@ -182,19 +183,8 @@ runs: echo "Installed Aptos CLI version:" aptos --version - - name: Cache movefmt CLI - id: cache-movefmt - uses: actions/cache@v4 - with: - path: ${{ inputs.install-dir }}/bin/movefmt* - key: movefmt-${{ inputs.movefmt-version }}-${{ runner.os }}-${{ runner.arch }} - restore-keys: | - movefmt-${{ inputs.movefmt-version }}-${{ runner.os }}- - movefmt-${{ inputs.movefmt-version }}- - movefmt- - - name: Install movefmt CLI - if: steps.cache-movefmt.outputs.cache-hit != 'true' + if: steps.cache-aptos.outputs.cache-hit != 'true' shell: bash run: | # Detect OS and arch for movefmt asset naming @@ -274,4 +264,15 @@ runs: shell: bash run: | echo "Installed movefmt version:" - movefmt --version \ No newline at end of file + movefmt --version + + - name: Save installation cache + uses: actions/cache@v4 + with: + path: ${{ inputs.install-dir }}/bin + key: aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ runner.os }}-${{ runner.arch }} + restore-keys: | + aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ runner.os }}- + aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}- + aptos-setup-${{ steps.get_version.outputs.version }}- + aptos-setup- \ No newline at end of file From 35e9387287107b423e0e3338f72f6f397fcc99a9 Mon Sep 17 00:00:00 2001 From: WGB5445 <919603023@qq.com> Date: Fri, 4 Jul 2025 13:10:04 +0800 Subject: [PATCH 2/7] Update default install directory for Aptos CLI in action.yml - Changed the default installation directory from $HOME/.aptoscli to ~/.aptoscli for consistency and clarity. --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 76f669f..7e40c4a 100644 --- a/action.yml +++ b/action.yml @@ -11,7 +11,7 @@ inputs: install-dir: description: "Install directory for Aptos CLI (will install to /bin)" required: false - default: $HOME/.aptoscli + default: ~/.aptoscli movefmt-username: description: "GitHub username for movefmt repository" required: false From 98a83fec1fea27115e56892045af676bae277a88 Mon Sep 17 00:00:00 2001 From: WGB5445 <919603023@qq.com> Date: Fri, 4 Jul 2025 13:14:53 +0800 Subject: [PATCH 3/7] Update default install directory for Aptos CLI in action.yml to use environment variables for better compatibility across systems --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7e40c4a..bc6c65e 100644 --- a/action.yml +++ b/action.yml @@ -11,7 +11,7 @@ inputs: install-dir: description: "Install directory for Aptos CLI (will install to /bin)" required: false - default: ~/.aptoscli + default: ${{ env.HOME || env.USERPROFILE }}/.aptoscli movefmt-username: description: "GitHub username for movefmt repository" required: false From 4a1353cbeb1fa6e3c2cd3d499922534612dbeeb5 Mon Sep 17 00:00:00 2001 From: WGB5445 <919603023@qq.com> Date: Fri, 4 Jul 2025 13:18:28 +0800 Subject: [PATCH 4/7] Refactor installation steps in action.yml to standardize handling of install directory - Updated installation scripts for both Aptos and movefmt CLIs to consistently handle the install directory, replacing instances of `${{ inputs.install-dir }}` with a variable that resolves to the user's home directory when necessary. - Improved clarity and maintainability of the code by using a single variable for the install directory across different OS checks. --- action.yml | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/action.yml b/action.yml index bc6c65e..4b978b6 100644 --- a/action.yml +++ b/action.yml @@ -11,7 +11,7 @@ inputs: install-dir: description: "Install directory for Aptos CLI (will install to /bin)" required: false - default: ${{ env.HOME || env.USERPROFILE }}/.aptoscli + default: ~/.aptoscli movefmt-username: description: "GitHub username for movefmt repository" required: false @@ -84,6 +84,8 @@ runs: if: steps.cache-aptos.outputs.cache-hit != 'true' shell: bash run: | + INSTALL_DIR="${{ inputs.install-dir }}" + INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" # Detect OS and arch for asset naming case "${RUNNER_OS}" in Linux) @@ -144,18 +146,24 @@ runs: if: runner.os != 'Windows' && steps.cache-aptos.outputs.cache-hit != 'true' shell: bash run: | + INSTALL_DIR="${{ inputs.install-dir }}" + INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" unzip aptos.zip -d aptos - mkdir -p "${{ inputs.install-dir }}/bin" - mv aptos/aptos "${{ inputs.install-dir }}/bin/" + mkdir -p "$INSTALL_DIR/bin" + mv aptos/aptos "$INSTALL_DIR/bin/" # Add to PATH for subsequent steps - echo "${{ inputs.install-dir }}/bin" >> $GITHUB_PATH + echo "$INSTALL_DIR/bin" >> $GITHUB_PATH - name: Unpack & install (Windows) if: runner.os == 'Windows' && steps.cache-aptos.outputs.cache-hit != 'true' shell: pwsh run: | + $INSTALL_DIR = '${{ inputs.install-dir }}' + if ($INSTALL_DIR.StartsWith('~')) { + $INSTALL_DIR = $INSTALL_DIR -replace '^~', $env:USERPROFILE + } Expand-Archive aptos.zip -DestinationPath aptos - $dest="${{ inputs.install-dir }}\bin" + $dest = "$INSTALL_DIR\bin" New-Item -ItemType Directory -Force -Path $dest | Out-Null Move-Item aptos\aptos.exe $dest # Add to PATH for subsequent steps @@ -165,28 +173,38 @@ runs: if: steps.cache-aptos.outputs.cache-hit == 'true' && runner.os != 'Windows' shell: bash run: | + INSTALL_DIR="${{ inputs.install-dir }}" + INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" echo "Using cached Aptos CLI installation" # Add to PATH for subsequent steps - echo "${{ inputs.install-dir }}/bin" >> $GITHUB_PATH + echo "$INSTALL_DIR/bin" >> $GITHUB_PATH - name: Add to PATH (cache hit - Windows) if: steps.cache-aptos.outputs.cache-hit == 'true' && runner.os == 'Windows' shell: pwsh run: | + $INSTALL_DIR = '${{ inputs.install-dir }}' + if ($INSTALL_DIR.StartsWith('~')) { + $INSTALL_DIR = $INSTALL_DIR -replace '^~', $env:USERPROFILE + } Write-Host "Using cached Aptos CLI installation" # Add to PATH for subsequent steps - Add-Content -Path $Env:GITHUB_PATH -Value "${{ inputs.install-dir }}\bin" + Add-Content -Path $Env:GITHUB_PATH -Value "$INSTALL_DIR\bin" - name: Verify installation shell: bash run: | + INSTALL_DIR="${{ inputs.install-dir }}" + INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" echo "Installed Aptos CLI version:" - aptos --version + "$INSTALL_DIR/bin/aptos" --version - name: Install movefmt CLI if: steps.cache-aptos.outputs.cache-hit != 'true' shell: bash run: | + INSTALL_DIR="${{ inputs.install-dir }}" + INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" # Detect OS and arch for movefmt asset naming case "${RUNNER_OS}" in Linux) @@ -240,8 +258,8 @@ runs: exit 1 fi # Install on Windows - mkdir -p "${{ inputs.install-dir }}/bin" - mv movefmt.exe "${{ inputs.install-dir }}/bin/" + mkdir -p "$INSTALL_DIR/bin" + mv movefmt.exe "$INSTALL_DIR/bin/" else # Require token for download if [ -z "${{ inputs.github-token }}" ]; then @@ -255,7 +273,7 @@ runs: fi # Install on Linux/macOS chmod +x movefmt - mv movefmt "${{ inputs.install-dir }}/bin/" + mv movefmt "$INSTALL_DIR/bin/" fi echo "movefmt installed successfully" @@ -263,8 +281,10 @@ runs: - name: Verify movefmt installation shell: bash run: | + INSTALL_DIR="${{ inputs.install-dir }}" + INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" echo "Installed movefmt version:" - movefmt --version + "$INSTALL_DIR/bin/movefmt" --version - name: Save installation cache uses: actions/cache@v4 From 69b4d2ebbf039edae88c957655ec025cebdbc92b Mon Sep 17 00:00:00 2001 From: WGB5445 <919603023@qq.com> Date: Fri, 4 Jul 2025 13:28:48 +0800 Subject: [PATCH 5/7] Update action.yml and test.yml for improved installation and testing configurations - Changed the default install directory for Aptos CLI from ~/.aptoscli to .aptoscli for better compatibility. - Refined cache key generation in action.yml to utilize architecture name for enhanced cache management. - Added macOS x64 to the testing matrix in test.yml to expand testing coverage across platforms. --- .github/workflows/test.yml | 2 ++ action.yml | 23 ++++------------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 469c241..4eb74d5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,6 +28,8 @@ jobs: # Windows ARM64 runners are not widely available yet - os: windows-latest arch: arm64 + - os: macos-latest + arch: x64 include: # Test specific version - os: ubuntu-latest diff --git a/action.yml b/action.yml index 4b978b6..a7a8928 100644 --- a/action.yml +++ b/action.yml @@ -11,7 +11,7 @@ inputs: install-dir: description: "Install directory for Aptos CLI (will install to /bin)" required: false - default: ~/.aptoscli + default: .aptoscli movefmt-username: description: "GitHub username for movefmt repository" required: false @@ -72,12 +72,7 @@ runs: uses: actions/cache@v4 with: path: ${{ inputs.install-dir }}/bin - key: aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ runner.os }}-${{ runner.arch }} - restore-keys: | - aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ runner.os }}- - aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}- - aptos-setup-${{ steps.get_version.outputs.version }}- - aptos-setup- + key: aptos-setup-${{ steps.dl.outputs.arch_name }}-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ runner.os }} - name: Build download URL id: dl @@ -126,6 +121,7 @@ runs: asset_name="aptos-cli-${{ steps.get_version.outputs.version }}-${os_name}-${arch_name}.zip" url="https://github.com/aptos-labs/aptos-core/releases/download/aptos-cli-v${{ steps.get_version.outputs.version }}/$asset_name" echo "url=$url" >> $GITHUB_OUTPUT + echo "arch_name=$arch_name" >> $GITHUB_OUTPUT - name: Download ZIP archive if: steps.cache-aptos.outputs.cache-hit != 'true' @@ -284,15 +280,4 @@ runs: INSTALL_DIR="${{ inputs.install-dir }}" INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" echo "Installed movefmt version:" - "$INSTALL_DIR/bin/movefmt" --version - - - name: Save installation cache - uses: actions/cache@v4 - with: - path: ${{ inputs.install-dir }}/bin - key: aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ runner.os }}-${{ runner.arch }} - restore-keys: | - aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ runner.os }}- - aptos-setup-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}- - aptos-setup-${{ steps.get_version.outputs.version }}- - aptos-setup- \ No newline at end of file + "$INSTALL_DIR/bin/movefmt" --version \ No newline at end of file From 154aa1da72e1ad2407f9783600c8a908f66e7ebc Mon Sep 17 00:00:00 2001 From: WGB5445 <919603023@qq.com> Date: Fri, 4 Jul 2025 13:32:07 +0800 Subject: [PATCH 6/7] Refine cache key generation in action.yml for Aptos CLI installation - Updated the cache key format to include additional parameters such as install directory, username, and repository for improved cache management and specificity. - This change enhances the caching mechanism by ensuring unique keys based on user-specific configurations. --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a7a8928..ef9b4aa 100644 --- a/action.yml +++ b/action.yml @@ -72,7 +72,7 @@ runs: uses: actions/cache@v4 with: path: ${{ inputs.install-dir }}/bin - key: aptos-setup-${{ steps.dl.outputs.arch_name }}-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ runner.os }} + key: aptos-cli-${{ runner.os }}-${{ steps.dl.outputs.arch_name }}-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ inputs.install-dir }}-${{ inputs.movefmt-username }}-${{ inputs.movefmt-repo }} - name: Build download URL id: dl From d3070fb06f4df5f2c322ff7d7b7ad46df6489962 Mon Sep 17 00:00:00 2001 From: WGB5445 <919603023@qq.com> Date: Fri, 4 Jul 2025 13:37:46 +0800 Subject: [PATCH 7/7] Refactor Aptos CLI installation directory handling in action.yml and README - Removed the `install-dir` input from action.yml, standardizing the installation path to `$HOME/.aptoscli` for all platforms. - Updated caching logic to reflect the new installation directory, ensuring consistent behavior across different operating systems. - Revised README to document the changes in the installation path and clarify the default behavior. --- README.md | 9 ++++----- action.yml | 37 +++++++++++-------------------------- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index c544bc3..19102b9 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,6 @@ 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 /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` | @@ -90,7 +89,7 @@ jobs: ## Outputs This action doesn't produce any outputs, but it: -- Installs the Aptos CLI to `$HOME/.aptos/bin` (Linux/macOS) or `%USERPROFILE%\.aptos\bin` (Windows) +- Installs the Aptos CLI to `$HOME/.aptoscli/bin` (Linux/macOS) or `%USERPROFILE%\.aptoscli\bin` (Windows) - Adds the installation directory to `PATH` for subsequent steps - Verifies the installation by running `aptos --version` @@ -131,9 +130,9 @@ curl -s https://api.github.com/repos/aptos-labs/aptos-core/releases/latest | gre # Download and install manually curl -L "https://github.com/aptos-labs/aptos-core/releases/download/aptos-cli-v7.5.0/aptos-cli-7.5.0-darwin-x86_64.zip" -o aptos.zip unzip aptos.zip -d aptos -mkdir -p "$HOME/.aptos/bin" -mv aptos/aptos "$HOME/.aptos/bin/" -export PATH="$HOME/.aptos/bin:$PATH" +mkdir -p "$HOME/.aptoscli/bin" +mv aptos/aptos "$HOME/.aptoscli/bin/" +export PATH="$HOME/.aptoscli/bin:$PATH" aptos --version ``` diff --git a/action.yml b/action.yml index ef9b4aa..7f314bb 100644 --- a/action.yml +++ b/action.yml @@ -8,10 +8,7 @@ inputs: description: "Aptos CLI version (tag). Use 'latest' to automatically fetch the latest release" required: false default: "latest" - install-dir: - description: "Install directory for Aptos CLI (will install to /bin)" - required: false - default: .aptoscli + movefmt-username: description: "GitHub username for movefmt repository" required: false @@ -71,16 +68,15 @@ runs: id: cache-aptos uses: actions/cache@v4 with: - path: ${{ inputs.install-dir }}/bin - key: aptos-cli-${{ runner.os }}-${{ steps.dl.outputs.arch_name }}-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ inputs.install-dir }}-${{ inputs.movefmt-username }}-${{ inputs.movefmt-repo }} + path: ~/.aptoscli/bin + key: aptos-cli-${{ runner.os }}-${{ runner.arch }}-${{ steps.get_version.outputs.version }}-${{ inputs.movefmt-version }}-${{ inputs.movefmt-username }}-${{ inputs.movefmt-repo }} - name: Build download URL id: dl if: steps.cache-aptos.outputs.cache-hit != 'true' shell: bash run: | - INSTALL_DIR="${{ inputs.install-dir }}" - INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" + INSTALL_DIR="$HOME/.aptoscli" # Detect OS and arch for asset naming case "${RUNNER_OS}" in Linux) @@ -142,8 +138,7 @@ runs: if: runner.os != 'Windows' && steps.cache-aptos.outputs.cache-hit != 'true' shell: bash run: | - INSTALL_DIR="${{ inputs.install-dir }}" - INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" + INSTALL_DIR="$HOME/.aptoscli" unzip aptos.zip -d aptos mkdir -p "$INSTALL_DIR/bin" mv aptos/aptos "$INSTALL_DIR/bin/" @@ -154,10 +149,7 @@ runs: if: runner.os == 'Windows' && steps.cache-aptos.outputs.cache-hit != 'true' shell: pwsh run: | - $INSTALL_DIR = '${{ inputs.install-dir }}' - if ($INSTALL_DIR.StartsWith('~')) { - $INSTALL_DIR = $INSTALL_DIR -replace '^~', $env:USERPROFILE - } + $INSTALL_DIR = "$env:USERPROFILE\.aptoscli" Expand-Archive aptos.zip -DestinationPath aptos $dest = "$INSTALL_DIR\bin" New-Item -ItemType Directory -Force -Path $dest | Out-Null @@ -169,8 +161,7 @@ runs: if: steps.cache-aptos.outputs.cache-hit == 'true' && runner.os != 'Windows' shell: bash run: | - INSTALL_DIR="${{ inputs.install-dir }}" - INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" + INSTALL_DIR="$HOME/.aptoscli" echo "Using cached Aptos CLI installation" # Add to PATH for subsequent steps echo "$INSTALL_DIR/bin" >> $GITHUB_PATH @@ -179,10 +170,7 @@ runs: if: steps.cache-aptos.outputs.cache-hit == 'true' && runner.os == 'Windows' shell: pwsh run: | - $INSTALL_DIR = '${{ inputs.install-dir }}' - if ($INSTALL_DIR.StartsWith('~')) { - $INSTALL_DIR = $INSTALL_DIR -replace '^~', $env:USERPROFILE - } + $INSTALL_DIR = "$env:USERPROFILE\.aptoscli" Write-Host "Using cached Aptos CLI installation" # Add to PATH for subsequent steps Add-Content -Path $Env:GITHUB_PATH -Value "$INSTALL_DIR\bin" @@ -190,8 +178,7 @@ runs: - name: Verify installation shell: bash run: | - INSTALL_DIR="${{ inputs.install-dir }}" - INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" + INSTALL_DIR="$HOME/.aptoscli" echo "Installed Aptos CLI version:" "$INSTALL_DIR/bin/aptos" --version @@ -199,8 +186,7 @@ runs: if: steps.cache-aptos.outputs.cache-hit != 'true' shell: bash run: | - INSTALL_DIR="${{ inputs.install-dir }}" - INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" + INSTALL_DIR="$HOME/.aptoscli" # Detect OS and arch for movefmt asset naming case "${RUNNER_OS}" in Linux) @@ -277,7 +263,6 @@ runs: - name: Verify movefmt installation shell: bash run: | - INSTALL_DIR="${{ inputs.install-dir }}" - INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}" + INSTALL_DIR="$HOME/.aptoscli" echo "Installed movefmt version:" "$INSTALL_DIR/bin/movefmt" --version \ No newline at end of file