Skip to content

Commit 8fd585d

Browse files
committed
Add aliyun cli tool downloader
0 parents  commit 8fd585d

File tree

7 files changed

+199
-0
lines changed

7 files changed

+199
-0
lines changed

.github/workflows/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Main
2+
on:
3+
- push
4+
jobs:
5+
Test:
6+
name: Testing
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v1
11+
12+
- name: Setup Aliyun CLI
13+
uses: ./
14+
with:
15+
aliyun-cli-version: '3.0.29'
16+
mode: AK
17+
access-key-id: ${{ secrets.ALIYUN_ACCESS_KEY_ID }}
18+
access-key-secret: ${{ secrets.ALIYUN_ACCESS_KEY_SECRET }}
19+
region: ${{ secrets.ALIYUN_REGION }}

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (http://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+
node_modules

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Setup Aliyun CLI Action

action.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Setup Aliyun CLI'
2+
description: 'Setup Aliyun commandline tool, add it to the PATH and configure authentication'
3+
inputs:
4+
aliyun-cli-version:
5+
description: 'Version of aliyun cli'
6+
required: true
7+
mode:
8+
description: 'Authentication mode'
9+
region:
10+
description: 'Region name of your service, for example: cn-shanghai'
11+
access-key-id:
12+
description: 'Access key ID of your account, required in AK/StsToken/RamRoleArn mode'
13+
access-key-secret:
14+
description: 'Secret of the access key'
15+
sts-token:
16+
description: 'StsToken, required in StsToken mode'
17+
ram-role-name:
18+
description: 'RAM role name, required in RamRoleArn mode'
19+
ram-role-arn:
20+
description: 'RAM role arn'
21+
role-session-name:
22+
description: 'Role session name'
23+
runs:
24+
using: 'node12'
25+
main: 'index.js'
26+
27+

index.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const tc = require('@actions/tool-cache');
2+
const core = require('@actions/core');
3+
const exec = require('@actions/exec');
4+
const os = require('os');
5+
6+
const name = 'aliyun';
7+
const platform = os.platform();
8+
const version = core.getInput('aliyun-cli-version', { required: true });
9+
10+
const configs = [
11+
{ input: 'mode', flag: '--mode' },
12+
{ input: 'region', flag: '--region' },
13+
{ input: 'access-key-id', flag: '--access-key-id' },
14+
{ input: 'access-key-secret', flag: '--access-key-secret' },
15+
{ input: 'sts-token', flag: '--sts-token' },
16+
{ input: 'ram-role-name', flag: '--ram-role-name' },
17+
{ input: 'ram-role-arn', flag: '--ram-role-arn' },
18+
{ input: 'role-session-name', flag: '--role-session-name' },
19+
];
20+
for (const config of configs) {
21+
config.value = core.getInput(config.input);
22+
}
23+
24+
async function run() {
25+
const [system, ext, extractFunc, executable] = (function() { switch(platform) {
26+
case 'linux':
27+
return ['linux', 'tgz', 'extractTar', name];
28+
case 'darwin':
29+
return ['macosx', 'tgz', 'extractTar', name];
30+
case 'win32':
31+
return ['windows', 'zip', 'extractZip', `${name}.exe`];
32+
default:
33+
throw new Error(`Unexpected OS ${platform}`);
34+
}})();
35+
36+
const url = `https://github.com/aliyun/aliyun-cli/releases/download/v${version}/aliyun-cli-${system}-${version}-amd64.${ext}`;
37+
const downloadedPath = await tc.downloadTool(url);
38+
const extractedPath = await tc[extractFunc](downloadedPath);
39+
const cachedPath = await tc.cacheDir(extractedPath, name, version);
40+
core.addPath(cachedPath);
41+
42+
const args = ['configure', 'set'];
43+
for (const config of configs) {
44+
if (config.value.length > 0) {
45+
args.push(config.flag, config.value);
46+
}
47+
}
48+
49+
await exec.exec(executable, args);
50+
}
51+
52+
run().catch(function(e) {
53+
core.setFailed(`Action failed with error: ${e}`);
54+
});

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "setup-aliyun-cli-action",
3+
"version": "1.0.0",
4+
"description": "GitHub Action used to setup Aliyun CLI",
5+
"main": "index.js",
6+
"author": "jerray <jerrayfu@gmail.com>",
7+
"license": "MIT",
8+
"dependencies": {
9+
"@actions/core": "^1.2.0",
10+
"@actions/exec": "^1.0.1",
11+
"@actions/tool-cache": "^1.1.2"
12+
}
13+
}

yarn.lock

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@actions/core@^1.1.0", "@actions/core@^1.2.0":
6+
version "1.2.0"
7+
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.0.tgz#aa5f52b26c362c821d41557e599371a42f6c0b3d"
8+
integrity sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw==
9+
10+
"@actions/exec@^1.0.1":
11+
version "1.0.1"
12+
resolved "https://registry.yarnpkg.com/@actions/exec/-/exec-1.0.1.tgz#1624b541165697e7008d7c87bc1f69f191263c6c"
13+
integrity sha512-nvFkxwiicvpzNiCBF4wFBDfnBvi7xp/as7LE1hBxBxKG2L29+gkIPBiLKMVORL+Hg3JNf07AKRfl0V5djoypjQ==
14+
15+
"@actions/io@^1.0.1":
16+
version "1.0.1"
17+
resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.0.1.tgz#81a9418fe2bbdef2d2717a8e9f85188b9c565aca"
18+
integrity sha512-rhq+tfZukbtaus7xyUtwKfuiCRXd1hWSfmJNEpFgBQJ4woqPEpsBw04awicjwz9tyG2/MVhAEMfVn664Cri5zA==
19+
20+
"@actions/tool-cache@^1.1.2":
21+
version "1.1.2"
22+
resolved "https://registry.yarnpkg.com/@actions/tool-cache/-/tool-cache-1.1.2.tgz#304d44cecb9547324731e03ca004a3905e6530d2"
23+
integrity sha512-IJczPaZr02ECa3Lgws/TJEVco9tjOujiQSZbO3dHuXXjhd5vrUtfOgGwhmz3/f97L910OraPZ8SknofUk6RvOQ==
24+
dependencies:
25+
"@actions/core" "^1.1.0"
26+
"@actions/exec" "^1.0.1"
27+
"@actions/io" "^1.0.1"
28+
semver "^6.1.0"
29+
typed-rest-client "^1.4.0"
30+
uuid "^3.3.2"
31+
32+
semver@^6.1.0:
33+
version "6.3.0"
34+
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
35+
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
36+
37+
tunnel@0.0.4:
38+
version "0.0.4"
39+
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.4.tgz#2d3785a158c174c9a16dc2c046ec5fc5f1742213"
40+
integrity sha1-LTeFoVjBdMmhbcLARuxfxfF0IhM=
41+
42+
typed-rest-client@^1.4.0:
43+
version "1.5.0"
44+
resolved "https://registry.yarnpkg.com/typed-rest-client/-/typed-rest-client-1.5.0.tgz#c0dda6e775b942fd46a2d99f2160a94953206fc2"
45+
integrity sha512-DVZRlmsfnTjp6ZJaatcdyvvwYwbWvR4YDNFDqb+qdTxpvaVP99YCpBkA8rxsLtAPjBVoDe4fNsnMIdZTiPuKWg==
46+
dependencies:
47+
tunnel "0.0.4"
48+
underscore "1.8.3"
49+
50+
underscore@1.8.3:
51+
version "1.8.3"
52+
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022"
53+
integrity sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=
54+
55+
uuid@^3.3.2:
56+
version "3.3.3"
57+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.3.tgz#4568f0216e78760ee1dbf3a4d2cf53e224112866"
58+
integrity sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==

0 commit comments

Comments
 (0)