Validate committed tgui build in Travis (#47427)

* Validate committed build in Travis

* Something different

* Document installation of git hooks

* Grammar perhaps

* Call tgui hook installer from tools/hooks/install.sh
This commit is contained in:
Aleksej Komarov
2019-11-03 06:06:54 +02:00
committed by Rob Bailey
parent ccf136aa07
commit 133076afb0
7 changed files with 172 additions and 49 deletions

View File

@@ -7,4 +7,4 @@
*.json text eol=lf
## Treat bundles as binary and ignore them during conflicts
# *.bundle.* binary merge=theirs
*.bundle.* binary merge=tgui-merge-bundle

View File

@@ -47,26 +47,16 @@ You will need these programs to start developing in tgui:
> a "pacman" package manager, and you can install a text editor like "vim"
> for a full boomer experience.
## Workflow
## Usage
If you haven't opened the console already, you can do that by holding
Shift and right clicking on the `tgui-next` folder, then pressing
either `Open command window here` or `Open PowerShell window here`.
**For MSys2, Git Bash, WSL, Linux or macOS users:**
Run `yarn install`, then:
- `yarn run build` - build the project in production mode.
- `yarn run watch` - launch a development server, with live log collection,
cache reloading and hot module replacement.
- `yarn run lint` - show problems with the code.
- `yarn run lint --fix` - auto-fix problems with the code.
- `yarn run analyze` - run a bundle analyzer.
For MSys2, WSL, Linux or macOS users:
First and foremost, run `bin/tgui --install-git-hooks` to install merge
drivers which will help you resolve conflicts when rebasing your branches.
- `bin/tgui` - build the project in production mode.
- `bin/tgui --dev` - launch a development server, with live log collection,
cache reloading and hot module replacement.
- `bin/tgui --dev` - launch a development server, with live log
collection, byond cache reloading and hot module replacement.
- `bin/tgui --dev --reload` - reload byond cache once.
- `bin/tgui --dev --debug` - run server with debug logging enabled.
- `bin/tgui --dev --no-hot` - disable hot module replacement (helps when
@@ -78,16 +68,31 @@ doing development on IE8).
- `bin/tgui [webpack options]` - build the project with custom webpack
options.
We also got some batch files in store, which are simple to use:
**For everyone else:**
If you haven't opened the console already, you can do that by holding
Shift and right clicking on the `tgui-next` folder, then pressing
either `Open command window here` or `Open PowerShell window here`.
Run `yarn install`, then:
- `yarn run build` - build the project in production mode.
- `yarn run watch` - launch a development server, with live log
collection, byond cache reloading and hot module replacement.
- `yarn run lint` - show problems with the code.
- `yarn run lint --fix` - auto-fix problems with the code.
- `yarn run analyze` - run a bundle analyzer.
We also got some batch files in store, which are very simple to use:
- `bin/tgui-build.bat` - build the project in production mode.
- `bin/tgui-watch.bat` - launch a development server, with live log
- `bin/tgui-dev-server.bat` - launch a development server, with live log
collection, cache reloading and hot module replacement.
Remember to always run a full build before submitting a PR. It creates
a compressed javascript bundle which is then referenced from DM code.
We prefer to keep it version controlled, so that people could build the
game just by using Dream Maker.
> Remember to always run a full build before submitting a PR. It creates
> a compressed javascript bundle which is then referenced from DM code.
> We prefer to keep it version controlled, so that people could build the
> game just by using Dream Maker.
## Project structure

View File

@@ -1,52 +1,166 @@
#!/bin/bash
## Script for building tgui. Requires MSYS2 to run.
set -e
cd "$(dirname "${0}")/.."
base_dir="$(pwd)"
shopt -s globstar
shopt -s expand_aliases
## Initial set-up
## --------------------------------------------------------
## Returns an absolute path to file
alias tgui-realpath="readlink -f"
## Fallbacks for GNU readlink
## Detecting GNU coreutils http://stackoverflow.com/a/8748344/319952
if ! readlink --version >/dev/null 2>&1; then
if hash greadlink 2>/dev/null; then
alias tgui-realpath="greadlink -f"
else
alias tgui-realpath="perl -MCwd -le 'print Cwd::abs_path(shift)'"
fi
fi
## Find a canonical path to project root
base_dir="$(dirname "$(tgui-realpath "${0}")")/.."
base_dir="$(tgui-realpath "${base_dir}")"
## Add locally installed node programs to path
PATH="${PATH}:node_modules/.bin"
run-webpack() {
## Functions
## --------------------------------------------------------
## Installs node modules
task-install() {
cd "${base_dir}"
yarn install
}
## Runs webpack
task-webpack() {
cd "${base_dir}/packages/tgui"
exec webpack "${@}"
webpack "${@}"
}
## Runs a development server
task-dev-server() {
cd "${base_dir}/packages/tgui-dev-server"
exec node --experimental-modules index.js "${@}"
}
## Run a linter through all packages
task-eslint() {
cd "${base_dir}"
eslint ./packages "${@}"
}
## Mr. Proper
if [[ ${1} == "--clean" ]]; then
shopt -s globstar
task-clean() {
cd "${base_dir}"
rm -rf packages/tgui/public/.tmp
rm -rf **/node_modules
rm -f **/package-lock.json
}
## Validates current build against the build stored in git
task-validate-build() {
cd "${base_dir}"
local diff
diff="$(git diff packages/tgui/public/tgui.bundle.*)"
if [[ -n ${diff} ]]; then
echo "Error: our build differs from the build committed into git."
echo "Please rebuild tgui."
exit 1
fi
echo "tgui: build is ok"
}
## Installs merge drivers and git hooks
task-install-git-hooks() {
cd "${base_dir}"
local git_root
local git_base_dir
git_root="$(git rev-parse --show-toplevel)"
git_base_dir="${base_dir/${git_root}/.}"
git config --replace-all merge.tgui-merge-bundle.driver \
"${git_base_dir}/${0} --merge=bundle %O %A %B %L"
echo "tgui: Merge drivers have been successfully installed!"
}
## Bundle merge driver
task-merge-bundle() {
local file_ancestor="${1}"
local file_current="${2}"
local file_other="${3}"
local conflict_marker_size="${4}"
echo "tgui: Discarding a local tgui build"
## Do nothing (file_current will be merged and is what we want to keep).
exit 0
}
## Main
## --------------------------------------------------------
if [[ ${1} == "--merge"* ]]; then
if [[ ${1} == "--merge=bundle" ]]; then
shift 1
task-merge-bundle "${@}"
fi
echo "Unknown merge strategy: ${1}"
exit 1
fi
if [[ ${1} == "--install-git-hooks" ]]; then
shift 1
task-install-git-hooks
exit 0
fi
## Install dependencies
yarn install
## Run a development server
if [[ ${1} == "--dev" ]]; then
shift
cd "${base_dir}/packages/tgui-dev-server"
exec node --experimental-modules index.js "${@}"
## Continuous integration scenario
if [[ ${1} == "--ci" ]]; then
task-clean
task-install
task-eslint
task-webpack --mode=production
task-validate-build
exit 0
fi
## Run a linter through all packages
if [[ ${1} == '--lint' ]]; then
if [[ ${1} == "--clean" ]]; then
task-clean
exit 0
fi
if [[ ${1} == "--dev" ]]; then
shift
exec eslint ./packages "${@}"
task-install
task-dev-server "${@}"
exit 0
fi
if [[ ${1} == '--lint' ]]; then
shift 1
task-install
task-eslint "${@}"
exit 0
fi
## Analyze the bundle
if [[ ${1} == '--analyze' ]]; then
run-webpack --mode=production --analyze
task-install
task-webpack --mode=production --analyze
exit 0
fi
## Make a production webpack build
if [[ -z ${1} ]]; then
eslint packages
run-webpack --mode=production
task-install
task-eslint
task-webpack --mode=production
exit 0
fi
## Run webpack with custom flags
run-webpack "${@}"
task-install
task-webpack "${@}"

View File

@@ -6,8 +6,8 @@
"packages/*"
],
"scripts": {
"watch": "cd packages/tgui-dev-server && node --experimental-modules index.js",
"build": "eslint packages && cd packages/tgui && npx webpack --mode=production",
"watch": "cd packages/tgui-dev-server && node --experimental-modules index.js",
"analyze": "cd packages/tgui && npx webpack --mode=production --env.analyze=1",
"lint": "eslint packages"
},

View File

@@ -10,6 +10,11 @@ for f in *.merge; do
echo Installing merge driver: ${f%.merge}
git config --replace-all merge.${f%.merge}.driver "tools/hooks/$f %P %O %A %B %L"
done
echo Installing Python dependencies
echo "Installing tgui hooks"
../../tgui-next/bin/tgui --install-git-hooks
echo "Installing Python dependencies"
./python.sh -m pip install -r ../mapmerge2/requirements.txt
echo "Done"

View File

@@ -21,5 +21,4 @@ node node_modules/gulp/bin/gulp.js --min
echo "Building 'tgui-next'"
cd "${base_dir}/tgui-next"
bin/tgui --clean
bin/tgui
bin/tgui --ci