Support latest version of ossutil (#17)

* support latest version
* bump up version to 1.1.0
This commit is contained in:
Rimo
2022-08-20 21:11:31 +08:00
committed by GitHub
parent 3d11e1d509
commit 23656db23a
19 changed files with 12223 additions and 11876 deletions

View File

@@ -1,3 +1,4 @@
dist/ dist/
lib/ lib/
node_modules/ node_modules/
jest.config.js

View File

@@ -8,6 +8,7 @@
"project": "./tsconfig.json" "project": "./tsconfig.json"
}, },
"rules": { "rules": {
"i18n-text/no-en": "off",
"eslint-comments/no-use": "off", "eslint-comments/no-use": "off",
"import/no-namespace": "off", "import/no-namespace": "off",
"no-unused-vars": "off", "no-unused-vars": "off",

6
.github/codeql/codeql-config.yml vendored Normal file
View File

@@ -0,0 +1,6 @@
name: "CodeQL config"
queries:
- uses: security-extended
- uses: security-and-quality
paths:
- src

11
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
- package-ecosystem: npm
directory: /
schedule:
interval: daily

53
.github/workflows/check-dist.yml vendored Normal file
View File

@@ -0,0 +1,53 @@
# `dist/index.js` is a special file in Actions.
# When you reference an action with `uses:` in a workflow,
# `index.js` is the code that will run.
# For our project, we generate this file through a build process from other source files.
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
name: Check dist/
on:
push:
branches:
- master
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:
jobs:
check-dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set Node.js 16.x
uses: actions/setup-node@v2.5.1
with:
node-version: 16.x
- name: Install dependencies
run: npm ci
- name: Rebuild the dist/ directory
run: |
npm run build
npm run package
- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff
# If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v2
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: dist/

View File

@@ -45,6 +45,7 @@ jobs:
uses: github/codeql-action/init@v2 uses: github/codeql-action/init@v2
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml
# If you wish to specify custom queries, you can do so here or in a config file. # If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file. # By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file. # Prefix the list here with "+" to use these queries and those in the config file.

View File

@@ -4,13 +4,12 @@ on: # rebuild any PRs and main branch changes
push: push:
branches: branches:
- master - master
- 'releases/*'
jobs: jobs:
build: # make sure build/ci work properly build: # make sure build/ci work properly
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v3
- run: npm ci - run: npm ci
- run: npm run all - run: npm run all
@@ -20,7 +19,7 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest] os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v3
- uses: ./ - uses: ./
with: with:
endpoint: ${{ secrets.OSS_ENDPOINT }} endpoint: ${{ secrets.OSS_ENDPOINT }}

View File

@@ -16,7 +16,7 @@ steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: yizhoumo/setup-ossutil@v1 - uses: yizhoumo/setup-ossutil@v1
with: with:
ossutil-version: '1.7.0' # Optional, default to '1.7.0' ossutil-version: '1.7.0' # Optional, default to 'latest'
endpoint: ${{ secrets.OSS_ENDPOINT }} endpoint: ${{ secrets.OSS_ENDPOINT }}
access-key-id: ${{ secrets.OSS_ACCESS_KEY_ID }} access-key-id: ${{ secrets.OSS_ACCESS_KEY_ID }}
access-key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }} access-key-secret: ${{ secrets.OSS_ACCESS_KEY_SECRET }}

View File

@@ -5,47 +5,31 @@ const TEMP_DIR = path.join(__dirname, 'runner', 'temp')
process.env['RUNNER_TOOL_CACHE'] = TOOL_DIR process.env['RUNNER_TOOL_CACHE'] = TOOL_DIR
process.env['RUNNER_TEMP'] = TEMP_DIR process.env['RUNNER_TEMP'] = TEMP_DIR
import * as core from '@actions/core'
import * as io from '@actions/io' import * as io from '@actions/io'
import * as fs from 'fs'
import * as installer from '../src/installer' import * as installer from '../src/installer'
const FILE_NAME = process.platform === 'win32' ? 'ossutil.exe' : 'ossutil'
jest.setTimeout(60000) jest.setTimeout(60000)
describe('installer tests', () => { describe('installer tests', () => {
beforeAll(async () => { beforeEach(async () => {
await io.rmRF(TOOL_DIR) await io.rmRF(TOOL_DIR)
await io.rmRF(TEMP_DIR) await io.rmRF(TEMP_DIR)
}) })
afterAll(async () => { afterEach(async () => {
await io.rmRF(TOOL_DIR) await io.rmRF(TOOL_DIR)
await io.rmRF(TEMP_DIR) await io.rmRF(TEMP_DIR)
}) })
it('install ossutil 1.7.0', async () => { const versions = ['1.7.0', 'latest']
const version = '1.7.0'
it.each(versions)('install ossutil %s', async version => {
await installer.getOssutil(version) 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)
expect(await io.which('ossutil', true)).toBeTruthy() expect(await io.which('ossutil', true)).toBeTruthy()
}) })
it('throw if wrong version', async () => { it('throw if wrong version', async () => {
let thrown = false await expect(installer.getOssutil('1000.0.0')).rejects.toThrowError()
try {
await installer.getOssutil('1000.0.0')
} catch (error) {
core.error(error)
thrown = true
}
expect(thrown).toBe(true)
}) })
}) })

View File

@@ -5,7 +5,7 @@ inputs:
ossutil-version: ossutil-version:
description: 'The OSSUTIL version to download and use' description: 'The OSSUTIL version to download and use'
required: false required: false
default: '1.7.0' default: 'latest'
endpoint: endpoint:
description: 'The endpoint of your bucket' description: 'The endpoint of your bucket'
required: true required: true
@@ -19,7 +19,7 @@ inputs:
description: 'The STS Token of the credentials' description: 'The STS Token of the credentials'
required: false required: false
runs: runs:
using: 'node12' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'
branding: branding:
icon: 'download-cloud' icon: 'download-cloud'

2915
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

47
dist/licenses.txt generated vendored
View File

@@ -12,6 +12,15 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
@actions/exec @actions/exec
MIT MIT
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@actions/http-client @actions/http-client
MIT MIT
@@ -40,9 +49,27 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@actions/io @actions/io
MIT MIT
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@actions/tool-cache @actions/tool-cache
MIT MIT
The MIT License (MIT)
Copyright 2019 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
semver semver
ISC ISC
@@ -92,22 +119,10 @@ uuid
MIT MIT
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2010-2016 Robert Kieffer and other contributors Copyright (c) 2010-2020 Robert Kieffer and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3911
dist/sourcemap-register.js generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,9 +1,7 @@
module.exports = { module.exports = {
clearMocks: true, clearMocks: true,
moduleFileExtensions: ['js', 'ts'], moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'], testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: { transform: {
'^.+\\.ts$': 'ts-jest' '^.+\\.ts$': 'ts-jest'
}, },

17256
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "setup-ossutil", "name": "setup-ossutil",
"version": "1.0.2", "version": "1.1.0",
"private": true, "private": true,
"description": "setup ossutil action", "description": "setup ossutil action",
"main": "lib/setup-ossutil.js", "main": "lib/setup-ossutil.js",
@@ -25,22 +25,21 @@
"author": "Rimo", "author": "Rimo",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.6.0",
"@actions/tool-cache": "^1.3.0" "@actions/tool-cache": "^2.0.1"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.15", "@types/jest": "^27.0.0",
"@types/node": "^14.14.9", "@types/node": "^16.10.5",
"@typescript-eslint/parser": "^4.8.1", "@typescript-eslint/parser": "^5.8.1",
"@vercel/ncc": "^0.25.1", "@vercel/ncc": "^0.31.1",
"eslint": "^7.13.0", "eslint": "^8.0.1",
"eslint-plugin-github": "^4.1.1", "eslint-plugin-github": "^4.3.2",
"eslint-plugin-jest": "^23.20.0", "eslint-plugin-jest": "^25.3.2",
"jest": "^24.9.0", "jest": "^27.2.5",
"jest-circus": "^26.4.2", "js-yaml": "^4.1.0",
"js-yaml": "^3.14.0", "prettier": "2.5.1",
"prettier": "2.1.1", "ts-jest": "^27.1.2",
"ts-jest": "^24.3.0", "typescript": "^4.4.4"
"typescript": "^4.0.2"
} }
} }

View File

@@ -1,55 +1,54 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import * as tc from '@actions/tool-cache' import * as tc from '@actions/tool-cache'
import * as path from 'path'
import * as fs from 'fs' import * as fs from 'fs'
import {HttpClient} from '@actions/http-client'
const TOOL_NAME = 'ossutil' const ToolName = 'ossutil'
const UpdateEndpoint =
'https://ossutil-version-update.oss-cn-hangzhou.aliyuncs.com'
/** /**
* Get ossutil ready for use * Get ossutil ready for use
* @param version the version of ossutil * @param version the version of ossutil
*/ */
export async function getOssutil(version: string): Promise<void> { export async function getOssutil(version: string): Promise<void> {
let toolPath = tc.find(TOOL_NAME, version) if (version.toLowerCase() === 'latest') {
if (!toolPath) { version = await getLatestVersion()
// download, extract, cache core.info(`Using the latest version of ossutil: ${version}`)
toolPath = await acquireOssutil(version) }
let toolPath = tc.find(ToolName, version)
if (!toolPath) {
toolPath = await downloadOssutil(version)
} }
core.debug(`ossutil is cached under ${toolPath}`)
core.addPath(toolPath) core.addPath(toolPath)
} }
/** /**
* Acquire ossutil and install it into the tool cache * Download ossutil and install it into the tool cache
* @param version the version of ossutil to acquire * @param version the version of ossutil to download
* @returns the path to the tool directory * @returns the path to the tool directory
*/ */
async function acquireOssutil(version: string): Promise<string> { async function downloadOssutil(version: string): Promise<string> {
// download // download
let downloadFile: string let toolFile: string
try { try {
const downloadUrl = getDownloadUrl(version) const downloadUrl = getDownloadUrl(version)
core.info(`Downloading ossutil from: ${downloadUrl}`) core.info(`Downloading ossutil from: ${downloadUrl}`)
downloadFile = await tc.downloadTool(downloadUrl) toolFile = await tc.downloadTool(downloadUrl)
} catch (error) { } catch (error) {
core.error(error) core.error('Failed to download ossutil')
throw new Error('Failed to download ossutil') throw error
} }
core.debug(`ossutil downloaded to: ${downloadFile}`) core.debug(`ossutil downloaded to: ${toolFile}`)
// extract (if needed) // change permission
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}`)
}
fs.chmodSync(toolFile, 0o755) fs.chmodSync(toolFile, 0o755)
// cache // cache
const fileName = process.platform === 'win32' ? 'ossutil.exe' : 'ossutil' const fileName = process.platform === 'win32' ? `${ToolName}.exe` : ToolName
const toolPath = await tc.cacheFile(toolFile, fileName, TOOL_NAME, version) const toolPath = await tc.cacheFile(toolFile, fileName, ToolName, version)
core.debug(`ossutil cached to: ${toolPath}`) core.debug(`ossutil cached to: ${toolPath}`)
return toolPath return toolPath
} }
@@ -60,14 +59,13 @@ async function acquireOssutil(version: string): Promise<string> {
* @returns the URL * @returns the URL
*/ */
function getDownloadUrl(version: string): string { function getDownloadUrl(version: string): string {
let downloadUrl = `http://gosspublic.alicdn.com/ossutil/${version}/` let downloadUrl = `${UpdateEndpoint}/${version}/`
switch (process.platform) { switch (process.platform) {
case 'linux': case 'linux':
downloadUrl += 'ossutil64' downloadUrl += 'ossutil64'
break break
case 'win32': case 'win32':
downloadUrl += 'ossutil64.zip' downloadUrl += 'ossutil64.exe'
break break
case 'darwin': case 'darwin':
downloadUrl += 'ossutilmac64' downloadUrl += 'ossutilmac64'
@@ -78,3 +76,14 @@ function getDownloadUrl(version: string): string {
return downloadUrl return downloadUrl
} }
/**
* Get the latest version of ossutil
* @returns the latest version
*/
async function getLatestVersion(): Promise<string> {
const http = new HttpClient()
const response = await http.get(`${UpdateEndpoint}/ossutilversion`)
const content = await response.readBody()
return content.trim()
}

View File

@@ -32,8 +32,10 @@ async function run(): Promise<void> {
core.info('ossutil config is done') core.info('ossutil config is done')
} }
} catch (error) { } catch (error) {
if (error instanceof Error) {
core.setFailed(error.message) core.setFailed(error.message)
} }
} }
}
run() run()