Compare commits

..

2 Commits
v0.1.2 ... main

Author SHA1 Message Date
a9a08c3855 删除docker buildx version命令测试
All checks were successful
Continuous Integration / GitHub Actions Test (push) Successful in 7s
2024-03-18 14:29:13 +08:00
9ad6913340 修改为docker cli插件安装模式
Some checks failed
Continuous Integration / GitHub Actions Test (push) Failing after 30s
2024-03-18 14:26:14 +08:00
3 changed files with 22 additions and 19 deletions

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View File

@ -1,14 +1,12 @@
import * as core from '@actions/core'
import * as io from '@actions/io'
import * as cache from '@actions/cache'
import os from 'os'
import fs from 'fs'
import path from 'path'
import cp from 'child_process'
import { getFileName, download } from './install'
const BinDir = '/denv/docker-plugin'
const BinName = 'buildx'
// const BinDir = '/denv/docker-plugin'
// const BinName = 'buildx'
/**
* The main function for the action.
@ -29,12 +27,16 @@ export async function run(): Promise<void> {
}
// 构建文件名
const dfn = getFileName(version, arch)
if (!fs.existsSync(BinDir)) {
fs.mkdirSync(BinDir, { recursive: true })
const dest = path.join(os.homedir(), '.docker')
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) {
core.info(`Cache not found for input key: ${dfn}`)
// 缓存中没有找到,下载解压安装
@ -42,23 +44,24 @@ export async function run(): Promise<void> {
if (!filepath) {
throw new Error(`Failed to download ${dfn}`)
}
core.info(`copy file from ${filepath} to ${cachePath}`)
fs.copyFileSync(filepath, cachePath)
core.info(`Success Installed to ${cachePath}`)
core.info(`copy file from ${filepath} to ${pluginPath}`)
fs.copyFileSync(filepath, pluginPath)
core.info(`Success Installed docker-cli-plugin to ${pluginPath}`)
// 保存到缓存
await cache.saveCache([cachePath], dfn)
await cache.saveCache([pluginPath], dfn)
}
// 设置可执行权限
fs.chmodSync(cachePath, '0755')
// 将bin目录添加到PATH
core.addPath(BinDir)
fs.chmodSync(pluginPath, '0755')
// // 将bin目录添加到PATH
// core.addPath(BinDir)
// 测试输出版本
const binPath = await io.which(BinName)
const binVersion = (cp.execSync(`${binPath} version`) || '').toString()
core.info(`${binPath} version cmd result is: ${binVersion}`)
// const binPath = await io.which(BinName)
// const cmd = `docker buildx version`
// const binVersion = (cp.execSync(`${cmd}`) || '').toString()
// core.info(`${cmd} version cmd result is: ${binVersion}`)
// 设置输出参数
core.setOutput('version', binVersion)
core.setOutput('version', version)
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)