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

Resolve workspace target dir from cargo metadata output #200

Merged
merged 1 commit into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11488,7 +11488,7 @@ function getCliValue(args, key) {
}
return undefined;
}
function getCargoTargetDir(args) {
async function getCargoTargetDir(args) {
let targetDir = 'target';
const val = getCliValue(args, '--target-dir');
const manifestPath = getCliValue(args, '--manifest-path') || getCliValue(args, '-m');
Expand All @@ -11500,7 +11500,16 @@ function getCargoTargetDir(args) {
targetDir = process.env.CARGO_TARGET_DIR;
}
else if (manifestPath && manifestPath.length > 0) {
targetDir = path.join(path.dirname(manifestPath), 'target');
const res = await mexec.exec('cargo', ['metadata', '--format-version', '1', '--manifest-path', manifestPath], true);
if (res.success) {
const metadata = JSON.parse(res.stdout);
targetDir = metadata.target_directory;
}
else {
core.warning('Failed to get Cargo target directory from `cargo metadata`');
core.debug(res.stderr);
targetDir = path.join(path.dirname(manifestPath), 'target');
}
}
return targetDir;
}
Expand Down Expand Up @@ -11715,7 +11724,7 @@ async function dockerBuild(container, maturinRelease, args) {
const scriptPath = path.join(os.tmpdir(), 'run-maturin-action.sh');
(0, fs_1.writeFileSync)(scriptPath, commands.join('\n'));
await fs_1.promises.chmod(scriptPath, 0o755);
const targetDir = getCargoTargetDir(args);
const targetDir = await getCargoTargetDir(args);
core.startGroup('Cleanup build scripts artifact directory');
const debugBuildDir = path.join(targetDir, 'debug', 'build');
if ((0, fs_1.existsSync)(debugBuildDir)) {
Expand Down
18 changes: 15 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function getCliValue(args: string[], key: string): string | undefined {
return undefined
}

function getCargoTargetDir(args: string[]): string {
async function getCargoTargetDir(args: string[]): Promise<string> {
let targetDir = 'target'
const val = getCliValue(args, '--target-dir')
const manifestPath =
Expand All @@ -233,7 +233,19 @@ function getCargoTargetDir(args: string[]): string {
) {
targetDir = process.env.CARGO_TARGET_DIR
} else if (manifestPath && manifestPath.length > 0) {
targetDir = path.join(path.dirname(manifestPath), 'target')
const res = await mexec.exec(
'cargo',
['metadata', '--format-version', '1', '--manifest-path', manifestPath],
true
)
if (res.success) {
const metadata = JSON.parse(res.stdout)
targetDir = metadata.target_directory
} else {
core.warning('Failed to get Cargo target directory from `cargo metadata`')
core.debug(res.stderr)
targetDir = path.join(path.dirname(manifestPath), 'target')
}
}
return targetDir
}
Expand Down Expand Up @@ -537,7 +549,7 @@ async function dockerBuild(
writeFileSync(scriptPath, commands.join('\n'))
await fs.chmod(scriptPath, 0o755)

const targetDir = getCargoTargetDir(args)
const targetDir = await getCargoTargetDir(args)

core.startGroup('Cleanup build scripts artifact directory')
const debugBuildDir = path.join(targetDir, 'debug', 'build')
Expand Down
Loading