mirror of
https://github.com/JonasKruckenberg/tauri-build.git
synced 2025-08-14 12:55:07 +00:00
add logic
This commit is contained in:
parent
3af9f0e188
commit
116ed3b140
24
.github/workflows/test.yml
vendored
24
.github/workflows/test.yml
vendored
@ -1,24 +0,0 @@
|
||||
name: 'build-test'
|
||||
on: # rebuild any PRs and main branch changes
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- 'releases/*'
|
||||
|
||||
jobs:
|
||||
build: # make sure build/ci work properly
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: |
|
||||
npm install
|
||||
- run: |
|
||||
npm run all
|
||||
test: # make sure the action works on a clean machine without building
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
milliseconds: 1000
|
@ -1,29 +0,0 @@
|
||||
import {wait} from '../src/wait'
|
||||
import * as process from 'process'
|
||||
import * as cp from 'child_process'
|
||||
import * as path from 'path'
|
||||
import {expect, test} from '@jest/globals'
|
||||
|
||||
test('throws invalid number', async () => {
|
||||
const input = parseInt('foo', 10)
|
||||
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
|
||||
})
|
||||
|
||||
test('wait 500 ms', async () => {
|
||||
const start = new Date()
|
||||
await wait(500)
|
||||
const end = new Date()
|
||||
var delta = Math.abs(end.getTime() - start.getTime())
|
||||
expect(delta).toBeGreaterThan(450)
|
||||
})
|
||||
|
||||
// shows how the runner will run a javascript action with env / stdout protocol
|
||||
test('test runs', () => {
|
||||
process.env['INPUT_MILLISECONDS'] = '500'
|
||||
const np = process.execPath
|
||||
const ip = path.join(__dirname, '..', 'lib', 'main.js')
|
||||
const options: cp.ExecFileSyncOptions = {
|
||||
env: process.env
|
||||
}
|
||||
console.log(cp.execFileSync(np, [ip], options).toString())
|
||||
})
|
26
action.yml
26
action.yml
@ -1,11 +1,23 @@
|
||||
name: 'Your name here'
|
||||
description: 'Provide a description here'
|
||||
author: 'Your name or organization here'
|
||||
name: 'tauri-action'
|
||||
description: 'Build tauri binaries for MacOS, Windows and Linux'
|
||||
icon: 'download-cloud'
|
||||
color: 'blue'
|
||||
author: 'Tauri Programme within The Commons Conservancy'
|
||||
inputs:
|
||||
milliseconds: # change this
|
||||
required: true
|
||||
description: 'input description here'
|
||||
default: 'default value if applicable'
|
||||
runner:
|
||||
description: 'Binary to use to build the application'
|
||||
args:
|
||||
description: 'Additional arguments for the build command'
|
||||
projectPath:
|
||||
description: 'Path to the root of the project'
|
||||
configPath:
|
||||
description: 'Path to the tauri.conf.json file if you want a configuration different from the default one'
|
||||
default: 'tauri.conf.json'
|
||||
target:
|
||||
description: 'The target triple to build against'
|
||||
outputs:
|
||||
artifacts:
|
||||
description: ''
|
||||
runs:
|
||||
using: 'node16'
|
||||
main: 'dist/index.js'
|
||||
|
@ -1,9 +0,0 @@
|
||||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testMatch: ['**/*.test.ts'],
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true
|
||||
}
|
7691
package-lock.json
generated
7691
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -25,7 +25,11 @@
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.6.0"
|
||||
"@actions/core": "^1.6.0",
|
||||
"@tauri-apps/cli": "1.0.0-rc.9",
|
||||
"execa": "^6.1.0",
|
||||
"string-argv": "^0.3.1",
|
||||
"tiny-glob": "^0.2.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.10.5",
|
||||
@ -33,11 +37,8 @@
|
||||
"@vercel/ncc": "^0.31.1",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-plugin-github": "^4.3.2",
|
||||
"eslint-plugin-jest": "^25.3.2",
|
||||
"jest": "^27.2.5",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "2.5.1",
|
||||
"ts-jest": "^27.1.2",
|
||||
"typescript": "^4.4.4"
|
||||
}
|
||||
}
|
||||
|
1913
pnpm-lock.yaml
generated
Normal file
1913
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
43
src/build-project.ts
Normal file
43
src/build-project.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import {execa} from 'execa'
|
||||
import {join} from 'path'
|
||||
import glob from 'tiny-glob'
|
||||
|
||||
interface BuildOptions {
|
||||
runner?: string
|
||||
projectPath?: string
|
||||
configPath?: string
|
||||
args?: string[]
|
||||
target?: string
|
||||
}
|
||||
|
||||
export async function buildProject(options: BuildOptions): Promise<string[]> {
|
||||
const projectPath = options.configPath || process.cwd()
|
||||
const runner = options.runner || 'tauri'
|
||||
let args: string[] = options.args || []
|
||||
|
||||
if (options.configPath) {
|
||||
args.push('--config', options.configPath)
|
||||
}
|
||||
|
||||
if (options.target) {
|
||||
args.push('--target', options.target)
|
||||
}
|
||||
|
||||
await execa(runner, args, {cwd: projectPath})
|
||||
|
||||
const outDir = options.target
|
||||
? `./target/${options.target}/release/bundle`
|
||||
: `./target/release/bundle`
|
||||
const macOSExts = ['app', 'app.tar.gz', 'app.tar.gz.sig', 'dmg']
|
||||
const linuxExts = [
|
||||
'AppImage',
|
||||
'AppImage.tar.gz',
|
||||
'AppImage.tar.gz.sig',
|
||||
'deb'
|
||||
]
|
||||
const windowsExts = ['msi', 'msi.zip', 'msi.zip.sig']
|
||||
|
||||
return glob(
|
||||
join(outDir, `*/*.{${[...macOSExts, linuxExts, windowsExts].join(',')}}`)
|
||||
)
|
||||
}
|
18
src/main.ts
18
src/main.ts
@ -1,16 +1,18 @@
|
||||
import * as core from '@actions/core'
|
||||
import {wait} from './wait'
|
||||
import {buildProject} from './build-project'
|
||||
import stringArgv from 'string-argv';
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const ms: string = core.getInput('milliseconds')
|
||||
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_STEP_DEBUG` to true
|
||||
const artifacts = await buildProject({
|
||||
runner: core.getInput('runner'),
|
||||
args: stringArgv(core.getInput('args')),
|
||||
projectPath: core.getInput('projectPath'),
|
||||
configPath: core.getInput('configPath'),
|
||||
target: core.getInput('target')
|
||||
})
|
||||
|
||||
core.debug(new Date().toTimeString())
|
||||
await wait(parseInt(ms, 10))
|
||||
core.debug(new Date().toTimeString())
|
||||
|
||||
core.setOutput('time', new Date().toTimeString())
|
||||
core.setOutput('artifacts', artifacts.join('\n'))
|
||||
} catch (error) {
|
||||
if (error instanceof Error) core.setFailed(error.message)
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
export async function wait(milliseconds: number): Promise<string> {
|
||||
return new Promise(resolve => {
|
||||
if (isNaN(milliseconds)) {
|
||||
throw new Error('milliseconds not a number')
|
||||
}
|
||||
|
||||
setTimeout(() => resolve('done!'), milliseconds)
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user