Call GitHub API to get the latest version info (#31)

* call github api to get the latest version info

* remove latest case from installer.tests

* update dist
This commit is contained in:
Rimo
2022-09-29 01:08:14 +08:00
committed by GitHub
parent 7771e4ad5d
commit 9dba6ec80f
10 changed files with 7801 additions and 44 deletions

View File

@@ -1,18 +1,16 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import * as tc from '@actions/tool-cache'
import * as fs from 'fs'
import {HttpClient} from '@actions/http-client'
const ToolName = 'ossutil'
const UpdateUrl =
'https://ossutil-version-update.oss-cn-hangzhou.aliyuncs.com/ossutilversion'
const DownloadEndpoint = 'https://gosspublic.alicdn.com/ossutil'
/**
* Get ossutil ready for use
* Install ossutil to PATH
* @param version the version of ossutil
*/
export async function getOssutil(version: string): Promise<void> {
export async function installOssutil(version: string): Promise<void> {
if (version.toLowerCase() === 'latest') {
version = await getLatestVersion()
core.info(`Using the latest version of ossutil: ${version}`)
@@ -83,11 +81,17 @@ function getDownloadUrl(version: string): string {
* @returns the latest version
*/
async function getLatestVersion(): Promise<string> {
const http = new HttpClient('setup-ossutil', [], {
allowRetries: true,
maxRetries: 5
const token = core.getInput('github-token', {required: true})
const octokit = github.getOctokit(token)
const response = await octokit.rest.repos.getLatestRelease({
owner: 'aliyun',
repo: 'ossutil'
})
const response = await http.get(UpdateUrl)
const content = await response.readBody()
return content.trim()
const tag = response.data.tag_name.trim()
if (tag[0].toLowerCase() === 'v') {
return tag.substring(1)
} else {
return tag
}
}

View File

@@ -6,7 +6,7 @@ async function run(): Promise<void> {
try {
// download
const version = core.getInput('ossutil-version')
await installer.getOssutil(version)
await installer.installOssutil(version)
core.info('ossutil is successfully installed')
// config