add logic

This commit is contained in:
Jonas Kruckenberg 2022-05-07 12:45:53 +02:00
parent 3af9f0e188
commit 116ed3b140
No known key found for this signature in database
GPG Key ID: 21AD3B3C266BDE3D
10 changed files with 1990 additions and 7781 deletions

View File

@ -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

View File

@ -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())
})

View File

@ -1,11 +1,23 @@
name: 'Your name here' name: 'tauri-action'
description: 'Provide a description here' description: 'Build tauri binaries for MacOS, Windows and Linux'
author: 'Your name or organization here' icon: 'download-cloud'
color: 'blue'
author: 'Tauri Programme within The Commons Conservancy'
inputs: inputs:
milliseconds: # change this runner:
required: true description: 'Binary to use to build the application'
description: 'input description here' args:
default: 'default value if applicable' 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: runs:
using: 'node16' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,11 @@
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "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": { "devDependencies": {
"@types/node": "^16.10.5", "@types/node": "^16.10.5",
@ -33,11 +37,8 @@
"@vercel/ncc": "^0.31.1", "@vercel/ncc": "^0.31.1",
"eslint": "^7.32.0", "eslint": "^7.32.0",
"eslint-plugin-github": "^4.3.2", "eslint-plugin-github": "^4.3.2",
"eslint-plugin-jest": "^25.3.2",
"jest": "^27.2.5",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"prettier": "2.5.1", "prettier": "2.5.1",
"ts-jest": "^27.1.2",
"typescript": "^4.4.4" "typescript": "^4.4.4"
} }
} }

1913
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

43
src/build-project.ts Normal file
View 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(',')}}`)
)
}

View File

@ -1,16 +1,18 @@
import * as core from '@actions/core' 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> { async function run(): Promise<void> {
try { try {
const ms: string = core.getInput('milliseconds') const artifacts = await buildProject({
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_STEP_DEBUG` to true 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()) core.setOutput('artifacts', artifacts.join('\n'))
await wait(parseInt(ms, 10))
core.debug(new Date().toTimeString())
core.setOutput('time', new Date().toTimeString())
} catch (error) { } catch (error) {
if (error instanceof Error) core.setFailed(error.message) if (error instanceof Error) core.setFailed(error.message)
} }

View File

@ -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)
})
}