From ad8f8784c7b4758d1f57b52038e35ac58496e8df Mon Sep 17 00:00:00 2001 From: Gajo Petrovic Date: Sun, 31 Jul 2022 01:43:55 +0900 Subject: [PATCH] Setup GitHub CI (#425) * switch from DO to GitHub/prd for editor, engine & asset distribution * setup GitHub CI for distribution --- .github/workflows/launcher.yml | 73 ++++++++++++++++++++++++++++++++++ .luacheckrc | 2 + build/make_package_json.js | 39 ++++++++++++++++++ dist_cfg/config.json | 22 +++++----- scen_edit/model/model.lua | 2 +- 5 files changed, 126 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/launcher.yml create mode 100644 build/make_package_json.js diff --git a/.github/workflows/launcher.yml b/.github/workflows/launcher.yml new file mode 100644 index 00000000..7d4d44cc --- /dev/null +++ b/.github/workflows/launcher.yml @@ -0,0 +1,73 @@ +name: Launcher + +on: + push: + paths: + - 'dist_cfg/**' + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +defaults: + run: + shell: bash + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-20.04 + build_cmd: "build-linux" + arch: "--x64" + + - os: windows-latest + build_cmd: "build-win" + arch: "--x64" + + steps: + - uses: actions/checkout@v2 + with: + # This should fix git rev-list --count HEAD + # https://stackoverflow.com/a/65056108 + fetch-depth: 0 + path: repo-folder + + - uses: actions/checkout@v2 + with: + repository: gajop/spring-launcher + path: spring-launcher + + - name: Setup NodeJs + uses: actions/setup-node@v1 + with: + node-version: '17.x' + + - name: Prepare folder structure + run: | + mkdir build + cp spring-launcher/* -r build/ + cp repo-folder/dist_cfg/* -r build/src/ + mkdir -p build/{bin,files,build} + [ -d build/src/bin/ ] && mv build/src/bin/* build/bin/ + [ -d build/src/files/ ] && mv build/src/files/* build/files/ + [ -d build/src/build/ ] && mv build/src/build/* build/build/ + rm -rf build/src/{bin,files,build} + exit 0 + + - name: Make package.json + run: | + cd repo-folder + export PACKAGE_VERSION=1.$(git rev-list --count HEAD).0 + echo "Making build for version: $PACKAGE_VERSION" + cd .. + node ./repo-folder/build/make_package_json.js build/package.json repo-folder/dist_cfg/config.json Spring-SpringBoard/SpringBoard-Core $PACKAGE_VERSION + + - name: Build + run: | + cd build + npm install + npm run ${{ matrix.build_cmd }} -- ${{ matrix.arch }} --publish always + env: + GH_TOKEN: ${{ secrets.github_token }} \ No newline at end of file diff --git a/.luacheckrc b/.luacheckrc index 2ee147f4..579221e5 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -19,6 +19,8 @@ codes = true -- Default is probably fine, but anyway std=lua51 +files["libs_sb/utils/luaunit.lua"] = { ignore = {"581"} } + globals = { -- std extensions "math.round", "math.bit_or", diff --git a/build/make_package_json.js b/build/make_package_json.js new file mode 100644 index 00000000..ff997c9f --- /dev/null +++ b/build/make_package_json.js @@ -0,0 +1,39 @@ +'use strict'; + +const fs = require('fs'); +const assert = require('assert'); + +function createPackagejson (packageJson, configJson, repoFullName, version) { + const configStr = fs.readFileSync(configJson); + const config = JSON.parse(configStr); + + assert(config.title != null, 'Missing config title'); + + const repoDotName = repoFullName.replace(/\//g, '.'); + + const packageTemplate = JSON.parse(fs.readFileSync(packageJson).toString()); + packageTemplate.name = config.title.replace(/ /g, '-'); + // eslint-disable-next-line no-template-curly-in-string + packageTemplate.build.artifactName = config.title + '-${version}.${ext}'; // '' is used on purpose, we want the spring to contain ${ext} as text + packageTemplate.version = version; + packageTemplate.repository = `github:${repoFullName}`; + packageTemplate.build.appId = `com.springrts.launcher.${repoDotName}`; + packageTemplate.build.publish = undefined; + if (config.dependencies != null) { + for (const dependency in config.dependencies) { + packageTemplate.dependencies[dependency] = config.dependencies[dependency]; + } + } + + fs.writeFileSync(packageJson, JSON.stringify(packageTemplate), 'utf8'); +} + +if (require.main === module) { + const args = process.argv; + if (args.length < 6) { + console.log('Wrong arguments'); + process.exit(-1); + } + + createPackagejson(args[2], args[3], args[4], args[5]) +} \ No newline at end of file diff --git a/dist_cfg/config.json b/dist_cfg/config.json index 32f7e2ab..3e101e87 100644 --- a/dist_cfg/config.json +++ b/dist_cfg/config.json @@ -11,17 +11,17 @@ "platform": "win32" }, "downloads": { - "nextgen" : ["Spring-SpringBoard/SpringBoard-Core"], + "games": ["sbc:test"], "resources": [ { - "url": "https://content.spring-launcher.com/engines/spring_%7Bmaintenance%7D104.0.1-1553-gd3c0012_win32-minimal-portable.7z", + "url": "https://github.com/Spring-SpringBoard/SpringBoard-Resources/releases/download/resources/spring_.maintenance.104.0.1-1553-gd3c0012_win32-minimal-portable.7z", "destination": "engine/104.0.1-1553-gd3c0012 maintenance", "extract": true } ] }, "launch": { - "game": "rapid://sbc:test", + "games": ["sbc:test"], "map": "sb_initial_blank_10x8", "engine": "104.0.1-1553-gd3c0012 maintenance", "map_options": { @@ -41,17 +41,17 @@ "platform": "linux" }, "downloads": { - "nextgen" : ["Spring-SpringBoard/SpringBoard-Core"], + "games": ["sbc:test"], "resources": [ { - "url": "https://content.spring-launcher.com/engines/spring_%7Bmaintenance%7D104.0.1-1553-gd3c0012_minimal-portable-linux64-static.7z", + "url": "https://github.com/Spring-SpringBoard/SpringBoard-Resources/releases/download/resources/spring_.maintenance.104.0.1-1553-gd3c0012_minimal-portable-linux64-static.7z", "destination": "engine/104.0.1-1553-gd3c0012 maintenance", "extract": true } ] }, "launch": { - "game": "rapid://sbc:test", + "games": ["sbc:test"], "map": "sb_initial_blank_10x8", "engine": "104.0.1-1553-gd3c0012 maintenance", "map_options": { @@ -71,7 +71,7 @@ "platform": "win32" }, "downloads": { - "nextgen" : ["Spring-SpringBoard/SpringBoard-Core"], + "games": ["sbc:test"], "resources": [ { "url": "https://github.com/beyond-all-reason/spring/releases/download/spring_bar_%7BBAR%7D104.0.1-1977-g12700e0/spring_bar_.BAR.104.0.1-1977-g12700e0_windows-64-minimal-portable.7z", @@ -81,7 +81,7 @@ ] }, "launch": { - "game": "rapid://sbc:test", + "games": ["sbc:test"], "map": "sb_initial_blank_10x8", "engine": "104.0.1-1977-g12700e0 bar", "map_options": { @@ -101,7 +101,7 @@ "platform": "linux" }, "downloads": { - "nextgen" : ["Spring-SpringBoard/SpringBoard-Core"], + "games": ["sbc:test"], "resources": [ { "url": "https://github.com/beyond-all-reason/spring/releases/download/spring_bar_%7BBAR%7D104.0.1-1977-g12700e0/spring_bar_.BAR.104.0.1-1977-g12700e0_linux-64-minimal-portable.7z", @@ -111,7 +111,7 @@ ] }, "launch": { - "game": "rapid://sbc:test", + "games": ["sbc:test"], "map": "sb_initial_blank_10x8", "engine": "104.0.1-1977-g12700e0 bar", "map_options": { @@ -172,7 +172,7 @@ "downloads": { "resources": [ { - "url": "https://content.spring-launcher.com/core_v1.zip", + "url": "https://github.com/Spring-SpringBoard/SpringBoard-Resources/releases/download/resources/core_v1.zip", "destination": "springboard/assets/core-v1", "extract": true } diff --git a/scen_edit/model/model.lua b/scen_edit/model/model.lua index f4ccc93f..2527229a 100644 --- a/scen_edit/model/model.lua +++ b/scen_edit/model/model.lua @@ -38,7 +38,7 @@ function Model:Clear() Spring.SetProjectileCollision(projectileID) end - if not Script.GetName() == "LuaUI" then + if Script.GetName() ~= "LuaUI" then SB.commandManager:execute(ClearUndoRedoCommand()) end end