|
| 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 | +}); |
0 commit comments