Skip to content

Commit 9a6e76f

Browse files
committed
ci: install aptos cli for cre aptos suite
1 parent 6321a3e commit 9a6e76f

4 files changed

Lines changed: 29 additions & 187 deletions

File tree

.github/workflows/cre-system-tests.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,35 @@ jobs:
213213
chmod +x bin/ctf
214214
echo "::endgroup::"
215215
216+
- name: Install Aptos CLI
217+
if: ${{ matrix.tests.test_name == 'Test_CRE_V2_Aptos_Suite' }}
218+
shell: bash
219+
env:
220+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
221+
APTOS_CLI_TAG: "aptos-cli-v7.8.0"
222+
run: |
223+
echo "::startgroup::Install Aptos CLI"
224+
bin_dir="$HOME/.local/bin"
225+
mkdir -p "$bin_dir"
226+
227+
gh release download "${APTOS_CLI_TAG}" \
228+
--pattern "aptos-cli-*-Ubuntu-24.04-x86_64.zip" \
229+
--clobber \
230+
--repo aptos-labs/aptos-core \
231+
-O aptos-cli.zip
232+
233+
unzip -o aptos-cli.zip -d aptos-cli-extract >/dev/null
234+
aptos_path="$(find aptos-cli-extract -type f -name aptos | head -n1)"
235+
if [[ -z "$aptos_path" ]]; then
236+
echo "failed to locate aptos binary in release archive"
237+
exit 1
238+
fi
239+
240+
install -m 0755 "$aptos_path" "$bin_dir/aptos"
241+
echo "$bin_dir" >> "$GITHUB_PATH"
242+
"$bin_dir/aptos" --version
243+
echo "::endgroup::"
244+
216245
- name: Start local CRE${{ matrix.tests.cre_version }}
217246
shell: bash
218247
id: start-local-cre

system-tests/lib/cre/features/aptos/aptos.go

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
stderrors "errors"
88
"fmt"
99
"net/url"
10-
"os"
11-
osexec "os/exec"
12-
"path/filepath"
1310
"strconv"
1411
"strings"
1512
"text/template"
@@ -72,9 +69,6 @@ const (
7269

7370
var forwarderContractVersion = semver.MustParse("1.0.0")
7471

75-
var aptosLookPath = osexec.LookPath
76-
var aptosContainerImage = aptosContainerImageFromDocker
77-
7872
type Aptos struct{}
7973

8074
type methodConfigSettings struct {
@@ -551,12 +545,6 @@ func ensureForwarder(
551545
Msg("Aptos deployer account not confirmed visible yet; proceeding with deploy retries")
552546
}
553547

554-
restoreAptosCLI, err := prepareAptosCLI(ctx, containerName)
555-
if err != nil {
556-
return "", fmt.Errorf("failed to prepare Aptos CLI for forwarder deploy on chain selector %d: %w", chain.ChainSelector(), err)
557-
}
558-
defer restoreAptosCLI()
559-
560548
var deployedAddress string
561549
var pendingTxHash string
562550
var lastDeployErr error
@@ -605,89 +593,6 @@ func ensureForwarder(
605593
return addr, nil
606594
}
607595

608-
// prepareAptosCLI makes the host aptos CLI available for Move package
609-
// compilation. Local CRE runners do not always have aptos installed, so fall
610-
// back to a thin wrapper that runs the CLI from the existing Aptos container
611-
// image with the current working directory bind-mounted.
612-
func prepareAptosCLI(ctx context.Context, containerName string) (func(), error) {
613-
if _, err := aptosLookPath("aptos"); err == nil {
614-
return func() {}, nil
615-
}
616-
617-
containerName = strings.TrimSpace(containerName)
618-
if containerName == "" {
619-
return nil, pkgerrors.New("aptos CLI not found on PATH and no Aptos container is available for fallback")
620-
}
621-
622-
image, err := aptosContainerImage(ctx, containerName)
623-
if err != nil {
624-
return nil, err
625-
}
626-
627-
wrapperDir, err := os.MkdirTemp("", "aptos-cli-wrapper-*")
628-
if err != nil {
629-
return nil, fmt.Errorf("create Aptos CLI wrapper directory: %w", err)
630-
}
631-
632-
wrapperPath := filepath.Join(wrapperDir, "aptos")
633-
script := fmt.Sprintf(`#!/bin/sh
634-
set -eu
635-
pwd_path="$(pwd -P)"
636-
exec docker run --rm \
637-
--user "$(id -u):$(id -g)" \
638-
-v "$pwd_path:$pwd_path" \
639-
-w "$pwd_path" \
640-
--entrypoint aptos \
641-
%q "$@"
642-
`, image)
643-
if err := os.WriteFile(wrapperPath, []byte(script), 0o600); err != nil {
644-
_ = os.RemoveAll(wrapperDir)
645-
return nil, fmt.Errorf("write Aptos CLI wrapper script: %w", err)
646-
}
647-
if err := os.Chmod(wrapperPath, 0o700); err != nil {
648-
_ = os.RemoveAll(wrapperDir)
649-
return nil, fmt.Errorf("mark Aptos CLI wrapper script executable: %w", err)
650-
}
651-
652-
oldPath := os.Getenv("PATH")
653-
if oldPath == "" {
654-
if err := os.Setenv("PATH", wrapperDir); err != nil {
655-
_ = os.RemoveAll(wrapperDir)
656-
return nil, fmt.Errorf("prepend Aptos CLI wrapper to PATH: %w", err)
657-
}
658-
} else {
659-
if err := os.Setenv("PATH", wrapperDir+string(os.PathListSeparator)+oldPath); err != nil {
660-
_ = os.RemoveAll(wrapperDir)
661-
return nil, fmt.Errorf("prepend Aptos CLI wrapper to PATH: %w", err)
662-
}
663-
}
664-
665-
return func() {
666-
_ = os.Setenv("PATH", oldPath)
667-
_ = os.RemoveAll(wrapperDir)
668-
}, nil
669-
}
670-
671-
// PrepareAptosCLI ensures the aptos CLI is available for local smoke tests and
672-
// setup phases that compile Move packages on the host.
673-
func PrepareAptosCLI(ctx context.Context, containerName string) (func(), error) {
674-
return prepareAptosCLI(ctx, containerName)
675-
}
676-
677-
func aptosContainerImageFromDocker(ctx context.Context, containerName string) (string, error) {
678-
out, err := osexec.CommandContext(ctx, "docker", "inspect", "--format", "{{.Config.Image}}", containerName).CombinedOutput()
679-
if err != nil {
680-
return "", fmt.Errorf("inspect Aptos container image for %q: %w (%s)", containerName, err, strings.TrimSpace(string(out)))
681-
}
682-
683-
image := strings.TrimSpace(string(out))
684-
if image == "" {
685-
return "", fmt.Errorf("inspect Aptos container image for %q: empty image reference", containerName)
686-
}
687-
688-
return image, nil
689-
}
690-
691596
// addForwarderToDataStore seals a new datastore snapshot with the Aptos
692597
// forwarder address so later setup phases can reuse it without redeploying.
693598
func addForwarderToDataStore(creEnv *cre.Environment, chainSelector uint64, address string) error {

system-tests/lib/cre/features/aptos/aptos_test.go

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package aptos
22

33
import (
4-
"context"
54
"encoding/hex"
65
"math/big"
7-
"os"
8-
"path/filepath"
9-
"strings"
106
"testing"
117
"time"
128

@@ -245,87 +241,3 @@ func TestResolveMethodConfigSettings_InvalidTransmissionSchedule(t *testing.T) {
245241
})
246242
require.Error(t, err)
247243
}
248-
249-
func TestPrepareAptosCLI_UsesHostBinaryWhenAvailable(t *testing.T) {
250-
t.Setenv("PATH", "/usr/bin")
251-
252-
originalLookPath := aptosLookPath
253-
originalContainerImage := aptosContainerImage
254-
aptosLookPath = func(file string) (string, error) {
255-
require.Equal(t, "aptos", file)
256-
return "/usr/bin/aptos", nil
257-
}
258-
aptosContainerImage = func(context.Context, string) (string, error) {
259-
t.Fatal("container fallback should not be used when host aptos exists")
260-
return "", nil
261-
}
262-
t.Cleanup(func() {
263-
aptosLookPath = originalLookPath
264-
aptosContainerImage = originalContainerImage
265-
})
266-
267-
restore, err := prepareAptosCLI(context.Background(), "aptos-node")
268-
require.NoError(t, err)
269-
require.Equal(t, "/usr/bin", os.Getenv("PATH"))
270-
271-
restore()
272-
require.Equal(t, "/usr/bin", os.Getenv("PATH"))
273-
}
274-
275-
func TestPrepareAptosCLI_BuildsContainerWrapperWhenHostBinaryMissing(t *testing.T) {
276-
t.Setenv("PATH", "/usr/bin")
277-
278-
originalLookPath := aptosLookPath
279-
originalContainerImage := aptosContainerImage
280-
aptosLookPath = func(file string) (string, error) {
281-
require.Equal(t, "aptos", file)
282-
return "", os.ErrNotExist
283-
}
284-
aptosContainerImage = func(ctx context.Context, containerName string) (string, error) {
285-
require.Equal(t, "aptos-node", containerName)
286-
return "ghcr.io/example/aptos:latest", nil
287-
}
288-
t.Cleanup(func() {
289-
aptosLookPath = originalLookPath
290-
aptosContainerImage = originalContainerImage
291-
})
292-
293-
restore, err := prepareAptosCLI(context.Background(), "aptos-node")
294-
require.NoError(t, err)
295-
t.Cleanup(restore)
296-
297-
pathParts := strings.Split(os.Getenv("PATH"), string(os.PathListSeparator))
298-
require.Len(t, pathParts, 2)
299-
require.Equal(t, "/usr/bin", pathParts[1])
300-
301-
wrapperPath := filepath.Join(pathParts[0], "aptos")
302-
content, err := os.ReadFile(wrapperPath)
303-
require.NoError(t, err)
304-
require.Contains(t, string(content), `--entrypoint aptos \`)
305-
require.Contains(t, string(content), `"ghcr.io/example/aptos:latest" "$@"`)
306-
307-
restore()
308-
require.Equal(t, "/usr/bin", os.Getenv("PATH"))
309-
_, err = os.Stat(wrapperPath)
310-
require.ErrorIs(t, err, os.ErrNotExist)
311-
}
312-
313-
func TestPrepareAptosCLI_RequiresContainerWhenHostBinaryMissing(t *testing.T) {
314-
originalLookPath := aptosLookPath
315-
originalContainerImage := aptosContainerImage
316-
aptosLookPath = func(string) (string, error) {
317-
return "", os.ErrNotExist
318-
}
319-
aptosContainerImage = func(context.Context, string) (string, error) {
320-
t.Fatal("container image lookup should not be used without a container name")
321-
return "", nil
322-
}
323-
t.Cleanup(func() {
324-
aptosLookPath = originalLookPath
325-
aptosContainerImage = originalContainerImage
326-
})
327-
328-
restore, err := prepareAptosCLI(context.Background(), "")
329-
require.Nil(t, restore)
330-
require.ErrorContains(t, err, "aptos CLI not found on PATH")
331-
}

system-tests/tests/smoke/cre/v2_aptos_capability_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,6 @@ func deployAptosDataFeedsReceiverForWrite(
578578
require.NoError(t, err, "failed to parse primary forwarder address")
579579

580580
owner := deployer.AccountAddress()
581-
restoreAptosCLI, err := aptosfeature.PrepareAptosCLI(t.Context(), containerName)
582-
require.NoError(t, err, "failed to prepare Aptos CLI for local package deploys")
583-
t.Cleanup(restoreAptosCLI)
584-
585581
secondaryAddress, secondaryTx, _, err := aptosplatformsecondary.DeployToObject(deployer, client, owner)
586582
require.NoError(t, err, "failed to deploy Aptos secondary platform package")
587583
require.NoError(t, aptosfeature.WaitForTransactionSuccess(client, secondaryTx.Hash, "platform_secondary deployment"))

0 commit comments

Comments
 (0)