Create multiple workflows for different actions
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
name: 'Scripting Compiler Action'
|
||||
description: 'Runs the custom ScriptCompiler as a GitHub Action.'
|
||||
inputs:
|
||||
source-root:
|
||||
description: 'The root directory of the source files to compile.'
|
||||
required: true
|
||||
default: 'src'
|
||||
output-file:
|
||||
description: 'The path to the output file for the compiled script.'
|
||||
required: true
|
||||
default: 'output/compiled.lua'
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Build action
|
||||
run: |
|
||||
npm ci
|
||||
npm run build
|
||||
shell: bash
|
||||
working-directory: ${{ github.action_path }}
|
||||
|
||||
- name: Run compiler
|
||||
run: node ${{ github.action_path }}/dist/index.js
|
||||
shell: bash
|
||||
working-directory: ${{ github.workspace }}
|
||||
env:
|
||||
INPUT_SOURCE-ROOT: ${{ inputs.source-root }}
|
||||
INPUT_OUTPUT-FILE: ${{ inputs.output-file }}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
const esbuild = require("esbuild");
|
||||
|
||||
const production = process.argv.includes('--production');
|
||||
const watch = process.argv.includes('--watch');
|
||||
|
||||
async function main() {
|
||||
const ctx = await esbuild.context({
|
||||
entryPoints: [
|
||||
'src/index.ts'
|
||||
],
|
||||
bundle: true,
|
||||
format: 'cjs',
|
||||
minify: production,
|
||||
sourcemap: !production,
|
||||
sourcesContent: false,
|
||||
platform: 'node',
|
||||
outfile: 'dist/index.js',
|
||||
external: ['@actions/core'],
|
||||
logLevel: 'silent',
|
||||
});
|
||||
if (watch) {
|
||||
await ctx.watch();
|
||||
} else {
|
||||
await ctx.rebuild();
|
||||
await ctx.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "gh-scripting-compiler",
|
||||
"version": "1.0.0",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "node esbuild.js",
|
||||
"watch": "node esbuild.js --watch",
|
||||
"package": "node esbuild.js --production"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "7.0.2",
|
||||
"esbuild": "0.28.2"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import * as core from '@actions/core';
|
||||
import { ScriptCompiler, ScriptCompilerOptions, CompilationError, ICompilationLogger } from 'dcs-script-compiler';
|
||||
|
||||
class Logger implements ICompilationLogger {
|
||||
info(message: string): void {
|
||||
core.info(message);
|
||||
}
|
||||
|
||||
error(message: string): void {
|
||||
core.error(message);
|
||||
}
|
||||
|
||||
writeLine(message: string): void {
|
||||
core.info(message);
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
|
||||
const sourceRoot = core.getInput('source-root');
|
||||
if (!sourceRoot) {
|
||||
core.setFailed('Source root is required.');
|
||||
return;
|
||||
}
|
||||
const outputFile = core.getInput('output-file');
|
||||
if (!outputFile) {
|
||||
core.setFailed('Output file path is required.');
|
||||
return;
|
||||
}
|
||||
|
||||
const logger = new Logger();
|
||||
|
||||
const outputFileName = outputFile.split('/').pop() || 'compiled.lua';
|
||||
const outputFolderPath = outputFile.substring(0, outputFile.lastIndexOf('/'));
|
||||
|
||||
const options: ScriptCompilerOptions = {
|
||||
sourcePath: sourceRoot,
|
||||
outputPath: outputFolderPath,
|
||||
outputFileName: outputFileName,
|
||||
minify: false,
|
||||
onError: (error: CompilationError) => {
|
||||
logger.error(`Error in file ${error.filePath} at line ${error.line}: ${error.message}`);
|
||||
core.setFailed(`Compilation error in file ${error.filePath} at line ${error.line}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
const compiler = new ScriptCompiler(options, logger);
|
||||
await compiler.compile(false);
|
||||
core.info('Compilation completed successfully.');
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
core.setFailed(error.message);
|
||||
} else {
|
||||
core.setFailed('An unknown error occurred.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"paths": {
|
||||
"dcs-script-compiler":[
|
||||
"../compiler/src/ScriptCompiler.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user