Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: creating dest dir #527

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
39 changes: 39 additions & 0 deletions lib/exec-child.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
if (require.main !== module) {
throw new Error('This file should not be required');
}

var childProcess = require('child_process');
var fs = require('fs');

var paramFilePath = process.argv[2];

var serializedParams = fs.readFileSync(paramFilePath, 'utf8');
var params = JSON.parse(serializedParams);

var cmd = params.command;
var execOptions = params.execOptions;
var pipe = params.pipe;
var stdoutFile = params.stdoutFile;
var stderrFile = params.stderrFile;

var c = childProcess.exec(cmd, execOptions, function (err) {
if (!err) {
process.exitCode = 0;
} else if (err.code === undefined) {
process.exitCode = 1;
} else {
process.exitCode = err.code;
}
});

var stdoutStream = fs.createWriteStream(stdoutFile);
var stderrStream = fs.createWriteStream(stderrFile);

c.stdout.pipe(stdoutStream);
c.stderr.pipe(stderrStream);
c.stdout.pipe(process.stdout);
c.stderr.pipe(process.stderr);

if (pipe) {
c.stdin.end(pipe);
}
1 change: 1 addition & 0 deletions lib/index.js

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions src/git-utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import * as glob from '@actions/glob';
import path from 'path';
import fs from 'fs';
import {Inputs, CmdResult} from './interfaces';
import {createDir} from './utils';
import {cp} from 'shelljs';
import {cp, rm, ls} from 'shelljs';

export async function createBranchForce(branch: string): Promise<void> {
await exec.exec('git', ['init']);
Expand All @@ -25,9 +24,12 @@ export async function deleteExcludedAssets(destDir: string, excludeAssets: strin
return paths;
})();
const globber = await glob.create(excludedAssetPaths.join('\n'));
console.log(excludedAssetNames);
console.log(excludedAssetPaths);
console.log(globber);
for await (const asset of globber.globGenerator()) {
core.info(`[INFO] delete ${asset}`);
io.rmRF(asset);
rm('-rf', asset);
}
return;
}
Expand All @@ -39,19 +41,17 @@ export async function copyAssets(
): Promise<void> {
core.info(`[INFO] prepare publishing assets`);

if (fs.existsSync(destDir) === false) {
core.info(`[INFO] create ${destDir}`);
await createDir(destDir);
}

const dotGitPath = path.join(publishDir, '.git');
if (fs.existsSync(dotGitPath)) {
core.info(`[INFO] delete .git`);
io.rmRF(dotGitPath);
core.info(`[INFO] delete ${dotGitPath}`);
rm('-rf', dotGitPath);
}

console.log(ls('-A', publishDir));
console.log(ls('-A', destDir));
core.info(`[INFO] copy ${publishDir} to ${destDir}`);
cp('-RfL', [`${publishDir}/*`, `${publishDir}/.*`], destDir);
console.log(ls('-A', destDir));

await deleteExcludedAssets(destDir, excludeAssets);

Expand All @@ -60,8 +60,8 @@ export async function copyAssets(

export async function setRepo(inps: Inputs, remoteURL: string, workDir: string): Promise<void> {
const publishDir = path.isAbsolute(inps.PublishDir)
? inps.PublishDir
: path.join(`${process.env.GITHUB_WORKSPACE}`, inps.PublishDir);
? path.resolve(inps.PublishDir)
: path.resolve(`${process.env.GITHUB_WORKSPACE}`, inps.PublishDir);

if (path.isAbsolute(inps.DestinationDir)) {
throw new Error('destination_dir should be a relative path');
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function getWorkDirName(unixTime: string): Promise<string> {

export async function createDir(dirPath: string): Promise<void> {
await io.mkdirP(dirPath);
core.debug(`Created directory ${dirPath}`);
core.info(`[INFO] Created directory ${dirPath}`);
return;
}

Expand Down