From 470933beed9abecb37688f38eb74206f3f97cff0 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Fri, 20 Mar 2020 22:53:43 +0800 Subject: [PATCH] fix scripts --- dist/git.js | 17 ++++++++++------- dist/index.js | 2 +- package.json | 11 +++++++---- src/git.ts | 17 ++++++++++------- src/index.ts | 2 +- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/dist/git.js b/dist/git.js index 016fee7..4b39d06 100644 --- a/dist/git.js +++ b/dist/git.js @@ -4,8 +4,9 @@ const exec_1 = require("@actions/exec"); const io = require("@actions/io"); const os = require("os"); const path = require("path"); -exports.folder = path.join(os.tmpdir(), `xmake${Date.now()}`); -const opt = { cwd: exports.folder }; +function makeOpt(ref) { + return { cwd: path.join(os.tmpdir(), `xmake-${ref}`) }; +} async function lsRemote() { let out = ''; await exec_1.exec('git', ['ls-remote', '--tags', 'https://github.com/xmake-io/xmake.git'], { @@ -25,17 +26,19 @@ async function lsRemote() { } exports.lsRemote = lsRemote; async function create(ref) { - await io.rmRF(exports.folder); - await io.mkdirP(exports.folder); + const opt = makeOpt(ref); + await io.rmRF(opt.cwd); + await io.mkdirP(opt.cwd); await exec_1.exec('git', ['init'], opt); await exec_1.exec('git', ['remote', 'add', 'origin', 'https://github.com/xmake-io/xmake.git'], opt); await exec_1.exec('git', ['fetch'], opt); await exec_1.exec('git', ['checkout', ref], opt); await exec_1.exec('git', ['submodule', 'update', '--init', '--recursive'], opt); - return exports.folder; + return opt.cwd; } exports.create = create; -async function cleanup() { - await io.rmRF(exports.folder); +async function cleanup(ref) { + const opt = makeOpt(ref); + await io.rmRF(opt.cwd); } exports.cleanup = cleanup; diff --git a/dist/index.js b/dist/index.js index 8f0b274..04fe902 100644 --- a/dist/index.js +++ b/dist/index.js @@ -47,7 +47,7 @@ async function unixInstall(version, sha) { await exec_1.exec('make', ['install', `prefix=${binDir}`], { cwd: sourceDir }); const cacheDir = await toolCache.cacheDir(binDir, 'xmake', version); await io.rmRF(binDir); - await git.cleanup(); + await git.cleanup(sha); return cacheDir; }); } diff --git a/package.json b/package.json index ac3a871..494df35 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,19 @@ { "name": "github-action-setup-xmake", - "version": "1.0.1", + "version": "1.0.3", "description": "Set up your GitHub Actions workflow with a specific version of xmake", "main": "dist/index.js", "author": "OpportunityLiu", "license": "GPL-3.0-or-later", + "repository": "https://github.com/xmake-io/github-action-setup-xmake.git", + "homepage": "https://github.com/xmake-io/github-action-setup-xmake", "scripts": { - "clean": "rimraf dist", + "init": "yarn install && yarn clean", "watch": "tsc --watch", - "lint": "eslint --fix src/**/*", "build": "tsc --build ./tsconfig.build.json", - "rebuild":"yarn clean && yarn build", + "rebuild": "yarn clean && yarn build", + "clean": "rimraf dist", + "lint": "eslint --fix src/**/*", "test": "jest", "release": "yarn rebuild && yarn lint && yarn install --production" }, diff --git a/src/git.ts b/src/git.ts index 6493981..73ef8c6 100644 --- a/src/git.ts +++ b/src/git.ts @@ -3,8 +3,9 @@ import * as io from '@actions/io'; import * as os from 'os'; import * as path from 'path'; -export const folder = path.join(os.tmpdir(), `xmake${Date.now()}`); -const opt = { cwd: folder }; +function makeOpt(ref: string): { cwd: string } { + return { cwd: path.join(os.tmpdir(), `xmake-${ref}`) }; +} export async function lsRemote(): Promise> { let out = ''; @@ -25,16 +26,18 @@ export async function lsRemote(): Promise> { } export async function create(ref: string): Promise { - await io.rmRF(folder); - await io.mkdirP(folder); + const opt = makeOpt(ref); + await io.rmRF(opt.cwd); + await io.mkdirP(opt.cwd); await exec('git', ['init'], opt); await exec('git', ['remote', 'add', 'origin', 'https://github.com/xmake-io/xmake.git'], opt); await exec('git', ['fetch'], opt); await exec('git', ['checkout', ref], opt); await exec('git', ['submodule', 'update', '--init', '--recursive'], opt); - return folder; + return opt.cwd; } -export async function cleanup(): Promise { - await io.rmRF(folder); +export async function cleanup(ref: string): Promise { + const opt = makeOpt(ref); + await io.rmRF(opt.cwd); } diff --git a/src/index.ts b/src/index.ts index e48e2c2..f2511cf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,7 +47,7 @@ async function unixInstall(version: string, sha: string): Promise { await exec('make', ['install', `prefix=${binDir}`], { cwd: sourceDir }); const cacheDir = await toolCache.cacheDir(binDir, 'xmake', version); await io.rmRF(binDir); - await git.cleanup(); + await git.cleanup(sha); return cacheDir; }); }