Initial version of setup-ossutil
This commit is contained in:
17
.github/workflows/test.yml
vendored
17
.github/workflows/test.yml
vendored
@@ -11,13 +11,20 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- run: |
|
||||
npm install
|
||||
npm run all
|
||||
- run: npm ci
|
||||
- run: npm run all
|
||||
|
||||
test: # make sure the action works on a clean machine without building
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: ./
|
||||
with:
|
||||
milliseconds: 1000
|
||||
endpoint: ${{ secrets.OSS_ENDPOINT }}
|
||||
access-key-id: ${{ secrets.OSS_ACCESS_KEY_ID }}
|
||||
access-key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }}
|
||||
- run: ossutil -v
|
||||
- run: ossutil ls
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
||||
|
||||
47
__tests__/installer.test.ts
Normal file
47
__tests__/installer.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import * as path from 'path'
|
||||
|
||||
const TOOL_DIR = path.join(__dirname, 'runner', 'tools')
|
||||
const TEMP_DIR = path.join(__dirname, 'runner', 'temp')
|
||||
process.env['RUNNER_TOOL_CACHE'] = TOOL_DIR
|
||||
process.env['RUNNER_TEMP'] = TEMP_DIR
|
||||
|
||||
import * as core from '@actions/core'
|
||||
import * as io from '@actions/io'
|
||||
import * as fs from 'fs'
|
||||
import * as installer from '../src/installer'
|
||||
|
||||
const FILE_NAME = process.platform === 'win32' ? 'ossutil.exe' : 'ossutil'
|
||||
|
||||
describe('installer tests', () => {
|
||||
beforeAll(async () => {
|
||||
await io.rmRF(TOOL_DIR)
|
||||
await io.rmRF(TEMP_DIR)
|
||||
}, 60000)
|
||||
|
||||
afterAll(async () => {
|
||||
await io.rmRF(TOOL_DIR)
|
||||
await io.rmRF(TEMP_DIR)
|
||||
}, 60000)
|
||||
|
||||
it('install ossutil 1.6.10', async () => {
|
||||
const version = '1.6.10'
|
||||
await installer.getOssutil(version)
|
||||
|
||||
const ossutilDir = path.join(TOOL_DIR, 'ossutil', version, process.arch)
|
||||
expect(fs.existsSync(`${ossutilDir}.complete`)).toBe(true)
|
||||
|
||||
const exist = fs.existsSync(path.join(ossutilDir, FILE_NAME))
|
||||
expect(exist).toBe(true)
|
||||
}, 60000)
|
||||
|
||||
it('throw if wrong version', async () => {
|
||||
let thrown = false
|
||||
try {
|
||||
await installer.getOssutil('1000.0.0')
|
||||
} catch (error) {
|
||||
core.error(error)
|
||||
thrown = true
|
||||
}
|
||||
expect(thrown).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -1,27 +0,0 @@
|
||||
import {wait} from '../src/wait'
|
||||
import * as process from 'process'
|
||||
import * as cp from 'child_process'
|
||||
import * as path from 'path'
|
||||
|
||||
test('throws invalid number', async () => {
|
||||
const input = parseInt('foo', 10)
|
||||
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
|
||||
})
|
||||
|
||||
test('wait 500 ms', async () => {
|
||||
const start = new Date()
|
||||
await wait(500)
|
||||
const end = new Date()
|
||||
var delta = Math.abs(end.getTime() - start.getTime())
|
||||
expect(delta).toBeGreaterThan(450)
|
||||
})
|
||||
|
||||
// shows how the runner will run a javascript action with env / stdout protocol
|
||||
test('test runs', () => {
|
||||
process.env['INPUT_MILLISECONDS'] = '500'
|
||||
const ip = path.join(__dirname, '..', 'lib', 'main.js')
|
||||
const options: cp.ExecSyncOptions = {
|
||||
env: process.env
|
||||
}
|
||||
console.log(cp.execSync(`node ${ip}`, options).toString())
|
||||
})
|
||||
25
action.yml
25
action.yml
@@ -1,10 +1,23 @@
|
||||
name: 'Your name here'
|
||||
description: 'Provide a description here'
|
||||
author: 'Your name or organization here'
|
||||
name: 'Setup OSSUTIL'
|
||||
description: 'Download and config Alibaba Cloud OSSUTIL'
|
||||
author: 'Rimo'
|
||||
inputs:
|
||||
myInput: # change this
|
||||
description: 'input description here'
|
||||
default: 'default value if applicable'
|
||||
ossutil-version:
|
||||
description: 'The OSSUTIL version to download and use'
|
||||
required: false
|
||||
default: '1.6.10'
|
||||
endpoint:
|
||||
description: 'The endpoint of your bucket'
|
||||
required: true
|
||||
access-key-id:
|
||||
description: 'The AccessKeyID of the credentials'
|
||||
required: true
|
||||
access-key-secret:
|
||||
description: 'The AccessKeySecret of the credentials'
|
||||
required: true
|
||||
sts-token:
|
||||
description: 'The STS Token of the credentials'
|
||||
required: false
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
|
||||
4060
dist/index.js
vendored
4060
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
41
package-lock.json
generated
41
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "typescript-action",
|
||||
"version": "0.0.0",
|
||||
"name": "setup-ossutil",
|
||||
"version": "0.1.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -9,6 +9,37 @@
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz",
|
||||
"integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw=="
|
||||
},
|
||||
"@actions/exec": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.3.tgz",
|
||||
"integrity": "sha512-TogJGnueOmM7ntCi0ASTUj4LapRRtDfj57Ja4IhPmg2fls28uVOPbAn8N+JifaOumN2UG3oEO/Ixek2A4NcYSA==",
|
||||
"requires": {
|
||||
"@actions/io": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"@actions/http-client": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.1.tgz",
|
||||
"integrity": "sha512-vy5DhqTJ1gtEkpRrD/6BHhUlkeyccrOX0BT9KmtO5TWxe5KSSwVHFE+J15Z0dG+tJwZJ/nHC4slUIyqpkahoMg=="
|
||||
},
|
||||
"@actions/io": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.2.tgz",
|
||||
"integrity": "sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg=="
|
||||
},
|
||||
"@actions/tool-cache": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.3.0.tgz",
|
||||
"integrity": "sha512-pbv32I89niDShw1YTDo0OFQmWPkZPElE7e3So1jfEzjIyzGRfYIzshwOVhemJZLcDtzo3kxO3GFDAmuVvub/6w==",
|
||||
"requires": {
|
||||
"@actions/core": "^1.2.0",
|
||||
"@actions/exec": "^1.0.0",
|
||||
"@actions/http-client": "^1.0.1",
|
||||
"@actions/io": "^1.0.1",
|
||||
"semver": "^6.1.0",
|
||||
"uuid": "^3.3.2"
|
||||
}
|
||||
},
|
||||
"@babel/code-frame": {
|
||||
"version": "7.5.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz",
|
||||
@@ -5461,8 +5492,7 @@
|
||||
"semver": {
|
||||
"version": "6.3.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
||||
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
|
||||
"dev": true
|
||||
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw=="
|
||||
},
|
||||
"set-blocking": {
|
||||
"version": "2.0.0",
|
||||
@@ -6239,8 +6269,7 @@
|
||||
"uuid": {
|
||||
"version": "3.3.3",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz",
|
||||
"integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ=="
|
||||
},
|
||||
"validate-npm-package-license": {
|
||||
"version": "3.0.4",
|
||||
|
||||
17
package.json
17
package.json
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "typescript-action",
|
||||
"version": "0.0.0",
|
||||
"name": "setup-ossutil",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "TypeScript template action",
|
||||
"main": "lib/main.js",
|
||||
"description": "setup ossutil action",
|
||||
"main": "lib/setup-ossutil.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write **/*.ts",
|
||||
@@ -15,17 +15,18 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/actions/typescript-action.git"
|
||||
"url": "git+https://github.com/yizhoumo/setup-ossutil.git"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"node",
|
||||
"ossutil",
|
||||
"setup"
|
||||
],
|
||||
"author": "YourNameOrOrganization",
|
||||
"author": "Rimo",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.0"
|
||||
"@actions/core": "^1.2.0",
|
||||
"@actions/tool-cache": "^1.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.23",
|
||||
|
||||
78
src/installer.ts
Normal file
78
src/installer.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as tc from '@actions/tool-cache'
|
||||
import * as path from 'path'
|
||||
|
||||
const TOOL_NAME = 'ossutil'
|
||||
|
||||
/**
|
||||
* Get ossutil ready for use
|
||||
* @param version the version of ossutil
|
||||
*/
|
||||
export async function getOssutil(version: string): Promise<void> {
|
||||
let toolPath = tc.find(TOOL_NAME, version)
|
||||
if (!toolPath) {
|
||||
// download, extract, cache
|
||||
toolPath = await acquireOssutil(version)
|
||||
}
|
||||
|
||||
core.info(`ossutil is cached under ${toolPath}`)
|
||||
core.addPath(toolPath)
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire ossutil and install it into the tool cache
|
||||
* @param version the version of ossutil to acquire
|
||||
* @returns the path to the tool directory
|
||||
*/
|
||||
async function acquireOssutil(version: string): Promise<string> {
|
||||
// download
|
||||
let downloadFile: string
|
||||
try {
|
||||
const downloadUrl = getDownloadUrl(version)
|
||||
core.info(`Downloading ossutil from: ${downloadUrl}`)
|
||||
downloadFile = await tc.downloadTool(downloadUrl)
|
||||
} catch (error) {
|
||||
core.error(error)
|
||||
throw new Error('Failed to download ossutil')
|
||||
}
|
||||
core.debug(`ossutil downloaded to: ${downloadFile}`)
|
||||
|
||||
// extract (if needed)
|
||||
let toolFile = downloadFile
|
||||
if (process.platform === 'win32') {
|
||||
const extractFolder = await tc.extractZip(downloadFile)
|
||||
toolFile = path.join(extractFolder, 'ossutil64', 'ossutil64.exe')
|
||||
core.debug(`ossutil extracted to: ${toolFile}`)
|
||||
}
|
||||
|
||||
// cache
|
||||
const fileName = process.platform === 'win32' ? 'ossutil.exe' : 'ossutil'
|
||||
const toolPath = await tc.cacheFile(toolFile, fileName, TOOL_NAME, version)
|
||||
core.debug(`ossutil cached to: ${toolPath}`)
|
||||
return toolPath
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL of the specific version of ossutil
|
||||
* @param version the version of ossutil to download
|
||||
* @returns the URL
|
||||
*/
|
||||
function getDownloadUrl(version: string): string {
|
||||
let downloadUrl = `http://gosspublic.alicdn.com/ossutil/${version}/`
|
||||
|
||||
switch (process.platform) {
|
||||
case 'linux':
|
||||
downloadUrl += 'ossutil64'
|
||||
break
|
||||
case 'win32':
|
||||
downloadUrl += 'ossutil64.zip'
|
||||
break
|
||||
case 'darwin':
|
||||
downloadUrl += 'ossutilmac64'
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unknown platform ${process.platform}`)
|
||||
}
|
||||
|
||||
return downloadUrl
|
||||
}
|
||||
19
src/main.ts
19
src/main.ts
@@ -1,19 +0,0 @@
|
||||
import * as core from '@actions/core'
|
||||
import {wait} from './wait'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const ms: string = core.getInput('milliseconds')
|
||||
core.debug(`Waiting ${ms} milliseconds ...`)
|
||||
|
||||
core.debug(new Date().toTimeString())
|
||||
await wait(parseInt(ms, 10))
|
||||
core.debug(new Date().toTimeString())
|
||||
|
||||
core.setOutput('time', new Date().toTimeString())
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
32
src/setup-ossutil.ts
Normal file
32
src/setup-ossutil.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as exec from '@actions/exec'
|
||||
import * as installer from './installer'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
// download
|
||||
const version = core.getInput('ossutil-version')
|
||||
await installer.getOssutil(version)
|
||||
|
||||
// config
|
||||
const endpoint = core.getInput('endpoint')
|
||||
const accessKeyId = core.getInput('access-key-id')
|
||||
const accessKeySecret = core.getInput('access-key-secret')
|
||||
const stsToken = core.getInput('sts-token')
|
||||
const args = [
|
||||
'--endpoint',
|
||||
endpoint,
|
||||
'--access-key-id',
|
||||
accessKeyId,
|
||||
'--access-key-secret',
|
||||
accessKeySecret,
|
||||
'--sts-token',
|
||||
stsToken
|
||||
]
|
||||
await exec.exec('ossutil', args)
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
@@ -1,9 +0,0 @@
|
||||
export async function wait(milliseconds: number): Promise<string> {
|
||||
return new Promise(resolve => {
|
||||
if (isNaN(milliseconds)) {
|
||||
throw new Error('milliseconds not a number')
|
||||
}
|
||||
|
||||
setTimeout(() => resolve('done!'), milliseconds)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user