diff --git a/.changes/fix-artifact-detection.md b/.changes/fix-artifact-detection.md new file mode 100644 index 0000000..d7ba867 --- /dev/null +++ b/.changes/fix-artifact-detection.md @@ -0,0 +1,5 @@ +--- +"tauri-build": patch +--- + +Use proper cargo command to detect the artifact directory. \ No newline at end of file diff --git a/package.json b/package.json index c0f3434..7667cfd 100644 --- a/package.json +++ b/package.json @@ -25,11 +25,11 @@ "dependencies": { "@actions/core": "^1.6.0", "@tauri-apps/cli": "1.0.0-rc.10", - "string-argv": "^0.3.1", - "tiny-glob": "^0.2.9", - "@tauri-apps/cli-win32-x64-msvc": "1.0.0-rc.10", "@tauri-apps/cli-darwin-x64": "1.0.0-rc.10", - "@tauri-apps/cli-linux-x64-gnu": "1.0.0-rc.10" + "@tauri-apps/cli-linux-x64-gnu": "1.0.0-rc.10", + "@tauri-apps/cli-win32-x64-msvc": "1.0.0-rc.10", + "string-argv": "^0.3.1", + "tiny-glob": "^0.2.9" }, "devDependencies": { "@types/node": "16.11.33", diff --git a/src/build-project.ts b/src/build-project.ts index bfacff5..4292798 100644 --- a/src/build-project.ts +++ b/src/build-project.ts @@ -1,8 +1,13 @@ -import { run } from '@tauri-apps/cli' -import {join, resolve} from 'path' +import {run} from '@tauri-apps/cli' +import {dirname, join, resolve} from 'path' import glob from 'tiny-glob' import * as core from '@actions/core' -import { spawn } from 'child_process' +import { + exec, + ExecOptionsWithStringEncoding, + spawn, + SpawnOptionsWithoutStdio +} from 'child_process' interface BuildOptions { runner?: string @@ -32,16 +37,21 @@ export async function buildProject(options: BuildOptions): Promise { if (options.runner) { core.info(`running ${options.runner} with args: build ${args.join(' ')}`) - await execRunnerCmd(options.runner, ['build', ...args]) + await spawnCmd(options.runner, ['build', ...args]) } else { core.info(`running builtin runner with args: build ${args.join(' ')}`) await run(['build', ...args], '') } + const crateDir = await glob(`./**/Cargo.toml`).then(([manifest]) => join(process.cwd(), dirname(manifest))) + const metaRaw = await execCmd('cargo', ['metadata', '--no-deps', '--format-version', '1'], { cwd: crateDir }) + const meta = JSON.parse(metaRaw) + const targetDir = meta.target_directory + const profile = options.debug ? 'debug' : 'release' - const outDir = options.target - ? `./target/${options.target}/${profile}/bundle` - : `./target/${profile}/bundle` + const bundleDir = options.target + ? join(targetDir, options.target, profile, 'bundle') + : join(targetDir, profile, 'bundle') const macOSExts = ['app', 'app.tar.gz', 'app.tar.gz.sig', 'dmg'] const linuxExts = [ @@ -52,29 +62,52 @@ export async function buildProject(options: BuildOptions): Promise { ] const windowsExts = ['msi', 'msi.zip', 'msi.zip.sig'] - const artifactsLookupPattern = join(outDir, `*/*.{${[...macOSExts, linuxExts, windowsExts].join(',')}}`) + const artifactsLookupPattern = join(bundleDir, `*/*.{${[...macOSExts, linuxExts, windowsExts].join(',')}}`) core.debug(`Looking for artifacts using this pattern: ${artifactsLookupPattern}`) - return glob(artifactsLookupPattern) + return glob(artifactsLookupPattern, { absolute: true, filesOnly: false }) } -async function execRunnerCmd(runner: string, args: string[]) { +async function spawnCmd( + cmd: string, + args: string[], + options: SpawnOptionsWithoutStdio = {} +) { return new Promise((resolve, reject) => { - const child = spawn(runner, args, { stdio: 'inherit', shell: true }) + const child = spawn(cmd, args, {...options, stdio: ['pipe', 'inherit', 'inherit'], shell: true}) + + child.on('exit', () => resolve) - child.on('exit', (exitCode, signal) => { - resolve({exitCode, signal}); - }); - child.on('error', error => { - reject(error); - }); - + reject(error) + }) + if (child.stdin) { child.stdin.on('error', error => { - reject(error); - }); + reject(error) + }) } }) -} \ No newline at end of file +} + +async function execCmd( + cmd: string, + args: string[], + options: Omit +): Promise { + return new Promise((resolve, reject) => { + exec( + `${cmd} ${args.join(' ')}`, + {...options, encoding: 'utf-8'}, + (error, stdout, stderr) => { + if (error) { + console.error(`Failed to execute cmd ${cmd} with args: ${args.join(' ')}. reason: ${error}`); + reject(stderr) + } else { + resolve(stdout) + } + } + ) + }) +} diff --git a/src/main.ts b/src/main.ts index 384d903..5c68725 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,7 +13,7 @@ async function run(): Promise { debug: core.getBooleanInput('debug') }) - core.setOutput('artifacts', artifacts.join('\n')) + core.setOutput('artifacts', artifacts) } catch (error) { if (error instanceof Error) core.setFailed(error.message) }