Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
a9a08c3855 | |||
9ad6913340 |
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
41
src/main.ts
41
src/main.ts
@ -1,14 +1,12 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as io from '@actions/io'
|
|
||||||
import * as cache from '@actions/cache'
|
import * as cache from '@actions/cache'
|
||||||
import os from 'os'
|
import os from 'os'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import cp from 'child_process'
|
|
||||||
import { getFileName, download } from './install'
|
import { getFileName, download } from './install'
|
||||||
|
|
||||||
const BinDir = '/denv/docker-plugin'
|
// const BinDir = '/denv/docker-plugin'
|
||||||
const BinName = 'buildx'
|
// const BinName = 'buildx'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main function for the action.
|
* The main function for the action.
|
||||||
@ -29,12 +27,16 @@ export async function run(): Promise<void> {
|
|||||||
}
|
}
|
||||||
// 构建文件名
|
// 构建文件名
|
||||||
const dfn = getFileName(version, arch)
|
const dfn = getFileName(version, arch)
|
||||||
if (!fs.existsSync(BinDir)) {
|
const dest = path.join(os.homedir(), '.docker')
|
||||||
fs.mkdirSync(BinDir, { recursive: true })
|
const pluginsDir: string = path.join(dest, 'cli-plugins')
|
||||||
|
if (!fs.existsSync(pluginsDir)) {
|
||||||
|
fs.mkdirSync(pluginsDir, { recursive: true })
|
||||||
}
|
}
|
||||||
const cachePath = path.join(BinDir, BinName)
|
const binName = 'docker-buildx'
|
||||||
|
const pluginPath: string = path.join(pluginsDir, binName)
|
||||||
|
// const cachePath = path.join(BinDir, BinName)
|
||||||
// 尝试从缓存中恢复
|
// 尝试从缓存中恢复
|
||||||
const rcr = await cache.restoreCache([cachePath], dfn)
|
const rcr = await cache.restoreCache([pluginPath], dfn)
|
||||||
if (!rcr) {
|
if (!rcr) {
|
||||||
core.info(`Cache not found for input key: ${dfn}`)
|
core.info(`Cache not found for input key: ${dfn}`)
|
||||||
// 缓存中没有找到,下载解压安装
|
// 缓存中没有找到,下载解压安装
|
||||||
@ -42,23 +44,24 @@ export async function run(): Promise<void> {
|
|||||||
if (!filepath) {
|
if (!filepath) {
|
||||||
throw new Error(`Failed to download ${dfn}`)
|
throw new Error(`Failed to download ${dfn}`)
|
||||||
}
|
}
|
||||||
core.info(`copy file from ${filepath} to ${cachePath}`)
|
core.info(`copy file from ${filepath} to ${pluginPath}`)
|
||||||
fs.copyFileSync(filepath, cachePath)
|
fs.copyFileSync(filepath, pluginPath)
|
||||||
core.info(`Success Installed to ${cachePath}`)
|
core.info(`Success Installed docker-cli-plugin to ${pluginPath}`)
|
||||||
// 保存到缓存
|
// 保存到缓存
|
||||||
await cache.saveCache([cachePath], dfn)
|
await cache.saveCache([pluginPath], dfn)
|
||||||
}
|
}
|
||||||
// 设置可执行权限
|
// 设置可执行权限
|
||||||
fs.chmodSync(cachePath, '0755')
|
fs.chmodSync(pluginPath, '0755')
|
||||||
// 将bin目录添加到PATH
|
// // 将bin目录添加到PATH
|
||||||
core.addPath(BinDir)
|
// core.addPath(BinDir)
|
||||||
// 测试输出版本
|
// 测试输出版本
|
||||||
const binPath = await io.which(BinName)
|
// const binPath = await io.which(BinName)
|
||||||
const binVersion = (cp.execSync(`${binPath} version`) || '').toString()
|
// const cmd = `docker buildx version`
|
||||||
core.info(`${binPath} version cmd result is: ${binVersion}`)
|
// const binVersion = (cp.execSync(`${cmd}`) || '').toString()
|
||||||
|
// core.info(`${cmd} version cmd result is: ${binVersion}`)
|
||||||
|
|
||||||
// 设置输出参数
|
// 设置输出参数
|
||||||
core.setOutput('version', binVersion)
|
core.setOutput('version', version)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Fail the workflow run if an error occurs
|
// Fail the workflow run if an error occurs
|
||||||
if (error instanceof Error) core.setFailed(error.message)
|
if (error instanceof Error) core.setFailed(error.message)
|
||||||
|
Loading…
Reference in New Issue
Block a user