Compare commits

...

3 Commits
v0.1.1 ... 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
1dd8cf04c9 删除无用代码,修改安装路径
All checks were successful
Continuous Integration / GitHub Actions Test (push) Successful in 30s
2024-03-18 13:51:49 +08:00
5 changed files with 27 additions and 27 deletions

View File

@ -29,4 +29,4 @@ jobs:
- name: Print Output - name: Print Output
id: output id: output
run: echo "${{ steps.test-action.outputs.go-version }}" run: echo "${{ steps.test-action.outputs.version }}"

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View File

@ -5,9 +5,6 @@ import os from 'os'
const DownloadBaseUrl = 'https://joylink.club/public-files/docker/' const DownloadBaseUrl = 'https://joylink.club/public-files/docker/'
export function getFileName(version: string, arch = os.arch()): string { export function getFileName(version: string, arch = os.arch()): string {
if (!version) {
version = 'v0.13.1'
}
return `buildx-${version}.linux-${arch}` return `buildx-${version}.linux-${arch}`
} }
@ -18,7 +15,7 @@ export function getFileName(version: string, arch = os.arch()): string {
*/ */
export async function download(fileName: string): Promise<string> { export async function download(fileName: string): Promise<string> {
const downloadUrl = `${DownloadBaseUrl}${fileName}` const downloadUrl = `${DownloadBaseUrl}${fileName}`
core.info(`Downloading go from ${downloadUrl}`) core.info(`Downloading docker buildx from ${downloadUrl}`)
const downloadPath = await tc.downloadTool(downloadUrl) const downloadPath = await tc.downloadTool(downloadUrl)
return downloadPath return downloadPath
} }

View File

@ -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/bin' // const BinDir = '/denv/docker-plugin'
const BinName = 'buildx' // const BinName = 'buildx'
/** /**
* The main function for the action. * The main function for the action.
@ -18,8 +16,7 @@ export async function run(): Promise<void> {
try { try {
// 获取输入的version // 获取输入的version
const version: string = resolveVersionInput() const version: string = resolveVersionInput()
// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true core.debug(`The version is: ${version}`)
core.debug(`The input version is: ${version}`)
// 获取输入的architecture // 获取输入的architecture
let arch = core.getInput('architecture') let arch = core.getInput('architecture')
if (!arch) { if (!arch) {
@ -30,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}`)
// 缓存中没有找到,下载解压安装 // 缓存中没有找到,下载解压安装
@ -43,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)
@ -71,6 +73,7 @@ function resolveVersionInput(): string {
if (version) { if (version) {
return version return version
} else {
return 'v0.13.1'
} }
throw new Error(`没有指定版本`)
} }