@aptos-labs/aptos-cli 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: Run bin script on Mac
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: macos-latest
|
|
12
|
+
concurrency: ci-${{ github.ref }}-${{ github.workflow }}
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout repository
|
|
15
|
+
uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: Run the bin script on Mac
|
|
18
|
+
run: node bin/aptos
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: Run bin script on Ubuntu
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
concurrency: ci-${{ github.ref }}-${{ github.workflow }}
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout repository
|
|
15
|
+
uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: Run the bin script on Ubuntu
|
|
18
|
+
run: node bin/aptos
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: Run bin script on Windows
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: windows-latest
|
|
12
|
+
concurrency: ci-${{ github.ref }}-${{ github.workflow }}
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout repository
|
|
15
|
+
uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: Run the bin script on Windows
|
|
18
|
+
run: node bin/aptos
|
|
19
|
+
shell: cmd
|
package/bin/aptos
CHANGED
|
@@ -14,6 +14,8 @@ const fs = require("fs");
|
|
|
14
14
|
const os = require("os");
|
|
15
15
|
|
|
16
16
|
const PNAME = "aptos-cli";
|
|
17
|
+
const GH_CLI_DOWNLOAD_URL =
|
|
18
|
+
"https://github.com/aptos-labs/aptos-core/releases/download";
|
|
17
19
|
|
|
18
20
|
// Wrapper around execSync that uses the shell.
|
|
19
21
|
const execSyncShell = (command, options) => {
|
|
@@ -72,6 +74,21 @@ const getLatestVersionBrew = () => {
|
|
|
72
74
|
return out[0].versions.stable;
|
|
73
75
|
};
|
|
74
76
|
|
|
77
|
+
// Determine the latest version of the CLI.
|
|
78
|
+
const getLatestVersion = async () => {
|
|
79
|
+
if (getOS() === "MacOS") {
|
|
80
|
+
return getLatestVersionBrew();
|
|
81
|
+
} else {
|
|
82
|
+
return getLatestVersionGh();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Determine the current SSL version
|
|
87
|
+
const getCurrentOpenSSLVersion = () => {
|
|
88
|
+
const out = execSyncShell("openssl version", { encoding: "utf8" });
|
|
89
|
+
return out.split(" ")[1].trim();
|
|
90
|
+
};
|
|
91
|
+
|
|
75
92
|
// Based on the installation path of the aptos formula, determine the path where the
|
|
76
93
|
// CLI should be installed.
|
|
77
94
|
const getCliPathBrew = () => {
|
|
@@ -81,6 +98,45 @@ const getCliPathBrew = () => {
|
|
|
81
98
|
return `${directory}/bin/aptos`;
|
|
82
99
|
};
|
|
83
100
|
|
|
101
|
+
// Install or update the CLI.
|
|
102
|
+
const installCli = (os, path, latestCLIVersion) => {
|
|
103
|
+
console.log(`Downloading aptos CLI version ${latestCLIVersion}`);
|
|
104
|
+
if (os === "Windows") {
|
|
105
|
+
const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${latestCLIVersion}/${PNAME}-${latestCLIVersion}-${os}-x86_64.zip`;
|
|
106
|
+
// Download the zip file, extract it, and move the binary to the correct location.
|
|
107
|
+
execSync(
|
|
108
|
+
`powershell -Command "if (!(Test-Path -Path 'C:\\tmp')) { New-Item -ItemType Directory -Path 'C:\\tmp' } ; Invoke-RestMethod -Uri ${url} -OutFile C:\\tmp\\aptos.zip; Expand-Archive -Path C:\\tmp\\aptos.zip -DestinationPath C:\\tmp -Force; Move-Item -Path C:\\tmp\\aptos.exe -Destination ${path}"`
|
|
109
|
+
);
|
|
110
|
+
} else if (os === "MacOS") {
|
|
111
|
+
// Install the CLI with brew.
|
|
112
|
+
execSyncShell("brew install aptos");
|
|
113
|
+
// Get the path of the CLI.
|
|
114
|
+
path = getCliPathBrew();
|
|
115
|
+
} else {
|
|
116
|
+
// On Linux, we check what version of OpenSSL we're working with to figure out
|
|
117
|
+
// which binary to download.
|
|
118
|
+
let osVersion = "x86_64";
|
|
119
|
+
let opensSslVersion = "1.0.0";
|
|
120
|
+
try {
|
|
121
|
+
opensSslVersion = getCurrentOpenSSLVersion();
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.log(
|
|
124
|
+
"Could not determine OpenSSL version, assuming older version (1.x.x)"
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (opensSslVersion.startsWith("3.")) {
|
|
129
|
+
osVersion = "22.04-x86_64";
|
|
130
|
+
}
|
|
131
|
+
console.log(`Downloading CLI binary ${os}-${osVersion}`);
|
|
132
|
+
const url = `${GH_CLI_DOWNLOAD_URL}/${PNAME}-v${latestCLIVersion}/${PNAME}-${latestCLIVersion}-${os}-${osVersion}.zip`;
|
|
133
|
+
// Download the zip file, extract it, and move the binary to the correct location.
|
|
134
|
+
execSync(
|
|
135
|
+
`curl -L -o /tmp/aptos.zip ${url}; unzip -o -q /tmp/aptos.zip -d /tmp; mv /tmp/aptos ${path};`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
84
140
|
const main = async () => {
|
|
85
141
|
const os = getOS();
|
|
86
142
|
|
|
@@ -102,34 +158,30 @@ const main = async () => {
|
|
|
102
158
|
path = `${__dirname}/${PNAME}`;
|
|
103
159
|
}
|
|
104
160
|
|
|
161
|
+
// Look up the latest version.
|
|
162
|
+
const latestVersion = await getLatestVersion();
|
|
163
|
+
|
|
105
164
|
// If binary does not exist, download it.
|
|
106
165
|
if (!fs.existsSync(path)) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
console.log(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
// Install the CLI with brew.
|
|
125
|
-
execSyncShell("brew install aptos");
|
|
126
|
-
// Get the path of the CLI.
|
|
127
|
-
path = getCliPathBrew();
|
|
166
|
+
console.log("CLI not installed");
|
|
167
|
+
// Install the latest version.
|
|
168
|
+
installCli(os, path, latestVersion);
|
|
169
|
+
} else {
|
|
170
|
+
// Get the current version of the CLI.
|
|
171
|
+
const currentVersion = execSyncShell(`${path} --version`, {
|
|
172
|
+
encoding: "utf8",
|
|
173
|
+
})
|
|
174
|
+
.trim()
|
|
175
|
+
.split(" ")[1];
|
|
176
|
+
console.log(
|
|
177
|
+
`Previously installed CLI version ${currentVersion}, checking for updates`
|
|
178
|
+
);
|
|
179
|
+
// Check if the installed version is the latest version.
|
|
180
|
+
if (currentVersion !== latestVersion) {
|
|
181
|
+
console.log(`A newer version of the CLI is available: ${latestVersion}`);
|
|
182
|
+
installCli(os, path, latestVersion);
|
|
128
183
|
} else {
|
|
129
|
-
|
|
130
|
-
execSync(
|
|
131
|
-
`curl -L -o /tmp/aptos.zip ${url}; unzip -o -q /tmp/aptos.zip -d /tmp; mv /tmp/aptos ${path};`
|
|
132
|
-
);
|
|
184
|
+
console.log(`CLI is up to date`);
|
|
133
185
|
}
|
|
134
186
|
}
|
|
135
187
|
|