mirror of
https://github.com/JonasKruckenberg/tauri-build.git
synced 2025-08-15 05:15:06 +00:00
fix: proper target dir detection using cargo
This commit is contained in:
parent
0c43d97746
commit
e21d218be1
5
.changes/fix-artifact-detection.md
Normal file
5
.changes/fix-artifact-detection.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"tauri-build": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Use proper cargo command to detect the artifact directory.
|
@ -25,11 +25,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.6.0",
|
"@actions/core": "^1.6.0",
|
||||||
"@tauri-apps/cli": "1.0.0-rc.10",
|
"@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-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": {
|
"devDependencies": {
|
||||||
"@types/node": "16.11.33",
|
"@types/node": "16.11.33",
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
import {run} from '@tauri-apps/cli'
|
import {run} from '@tauri-apps/cli'
|
||||||
import {join, resolve} from 'path'
|
import {dirname, join, resolve} from 'path'
|
||||||
import glob from 'tiny-glob'
|
import glob from 'tiny-glob'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import { spawn } from 'child_process'
|
import {
|
||||||
|
exec,
|
||||||
|
ExecOptionsWithStringEncoding,
|
||||||
|
spawn,
|
||||||
|
SpawnOptionsWithoutStdio
|
||||||
|
} from 'child_process'
|
||||||
|
|
||||||
interface BuildOptions {
|
interface BuildOptions {
|
||||||
runner?: string
|
runner?: string
|
||||||
@ -32,16 +37,21 @@ export async function buildProject(options: BuildOptions): Promise<string[]> {
|
|||||||
|
|
||||||
if (options.runner) {
|
if (options.runner) {
|
||||||
core.info(`running ${options.runner} with args: build ${args.join(' ')}`)
|
core.info(`running ${options.runner} with args: build ${args.join(' ')}`)
|
||||||
await execRunnerCmd(options.runner, ['build', ...args])
|
await spawnCmd(options.runner, ['build', ...args])
|
||||||
} else {
|
} else {
|
||||||
core.info(`running builtin runner with args: build ${args.join(' ')}`)
|
core.info(`running builtin runner with args: build ${args.join(' ')}`)
|
||||||
await run(['build', ...args], '')
|
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 profile = options.debug ? 'debug' : 'release'
|
||||||
const outDir = options.target
|
const bundleDir = options.target
|
||||||
? `./target/${options.target}/${profile}/bundle`
|
? join(targetDir, options.target, profile, 'bundle')
|
||||||
: `./target/${profile}/bundle`
|
: join(targetDir, profile, 'bundle')
|
||||||
|
|
||||||
const macOSExts = ['app', 'app.tar.gz', 'app.tar.gz.sig', 'dmg']
|
const macOSExts = ['app', 'app.tar.gz', 'app.tar.gz.sig', 'dmg']
|
||||||
const linuxExts = [
|
const linuxExts = [
|
||||||
@ -52,29 +62,52 @@ export async function buildProject(options: BuildOptions): Promise<string[]> {
|
|||||||
]
|
]
|
||||||
const windowsExts = ['msi', 'msi.zip', 'msi.zip.sig']
|
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}`)
|
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) => {
|
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', (exitCode, signal) => {
|
child.on('exit', () => resolve)
|
||||||
resolve({exitCode, signal});
|
|
||||||
});
|
|
||||||
|
|
||||||
child.on('error', error => {
|
child.on('error', error => {
|
||||||
reject(error);
|
reject(error)
|
||||||
});
|
})
|
||||||
|
|
||||||
if (child.stdin) {
|
if (child.stdin) {
|
||||||
child.stdin.on('error', error => {
|
child.stdin.on('error', error => {
|
||||||
reject(error);
|
reject(error)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function execCmd(
|
||||||
|
cmd: string,
|
||||||
|
args: string[],
|
||||||
|
options: Omit<ExecOptionsWithStringEncoding, 'encoding'>
|
||||||
|
): Promise<string> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -13,7 +13,7 @@ async function run(): Promise<void> {
|
|||||||
debug: core.getBooleanInput('debug')
|
debug: core.getBooleanInput('debug')
|
||||||
})
|
})
|
||||||
|
|
||||||
core.setOutput('artifacts', artifacts.join('\n'))
|
core.setOutput('artifacts', artifacts)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) core.setFailed(error.message)
|
if (error instanceof Error) core.setFailed(error.message)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user