Skip to content

Commit

Permalink
add a github action to publish a release with the autoconf file attac…
Browse files Browse the repository at this point in the history
…hed.
  • Loading branch information
rubensayshi committed Oct 21, 2020
1 parent a345bf9 commit 210742c
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 94 deletions.
50 changes: 0 additions & 50 deletions .github/duwrap/Dockerfile

This file was deleted.

7 changes: 0 additions & 7 deletions .github/duwrap/Makefile

This file was deleted.

23 changes: 0 additions & 23 deletions .github/duwrap/README.md

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/wrap-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Wrap and Release
on:
push:
branches: master
jobs:
wrap-and-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Detect Version Number
if: github.ref == 'refs/heads/master' # ONLY ON MASTER
run: |
./scripts/version-number-from-src.sh
echo "VERSION_NUMBER=$( ./scripts/version-number-from-src.sh )" >> $GITHUB_ENV
- name: Create Release Notes
if: github.ref == 'refs/heads/master' # ONLY ON MASTER
run: |
cat ./scripts/ReleaseNotesTemplate.md > ReleaseNotes.md
./scripts/latest-changes.sh >> ReleaseNotes.md
- name: Create Release
if: github.ref == 'refs/heads/master' # ONLY ON MASTER
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.VERSION_NUMBER }}
release_name: Release v${{ env.VERSION_NUMBER }}
body_path: ReleaseNotes.md

- name: Upload Autoconf as Release Asset
if: github.ref == 'refs/heads/master' # ONLY ON MASTER
id: upload-autoconf
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above
asset_path: ./ButtonHUD.conf
asset_name: ButtonHUD.conf
asset_content_type: text/yaml
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ ButtonHUD.min.lua
ButtonHUD.wrapped.conf
ButtonHUD.exports
ButtonHUD.extracted.lua
ButtonHUD.conf.version
scripts/node_modules/**
scripts/work/**
src/du
src/du/**
log.txt
log.txt
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Check the [changelog](./ChangeLog.md) file for information about the most recent

# Installation
## While a databank element is not required, it is strongly recommended. They are cheap, or easy to make, and take up 1x1x1 cube space and fit nicely in front of seat. Having one on your ship prior to doing the below steps will save your user preferences and some longterm variables, as well as flight status if you get up and sit back down in some situations.
1. Click on **`ButtonHUD.conf`** above. The Button HUD is the latest and most recent version but comes with a few caveats (read below). Then on the top right, right click the `RAW` button and click `Save Link As`...
1. Download the latest version of [ButtonHUD.conf](https://github.com/Dimencia/DU-Orbital-Hud/releases/latest/download/ButtonHUD.conf).
1. Save the file to *`%ProgramData%\Dual Universe\Game\data\lua\autoconf\custom`*, the filename does not matter (as long as it's still .conf)
1. In-game, right click your seat and go to *Advanced -> Update custom autoconf list* - If you get a YAML error, you did not follow the above directions corretly.
1. In-game, right click your seat and go to *Advanced -> Update custom autoconf list* - If you get a YAML error, you did not follow the above directions correctly.
1. Again, right click your seat and select *Advanced -> Run Custom Autoconfigure -> ButtonsHud - Dimencia and Archaegeo*
1. IMPORTANT: Right click the ship and set the user control scheme to `Keyboard` (*Advanced -> Change Control Scheme -> Keyboard*). This is necessary for the HUD to work, but you can change the actual control scheme in the next step - fear not virtual joystick aces!
1. Right click the seat, choose *Advanced -> Edit LUA Parameters*. Change the `userControlScheme` to the actual control scheme you wish to use (e.g. `Virtual Joystick`). You may mouse over the other parameters and set them as you wish - there are many, you should familiarize yourself with them.
Expand Down
12 changes: 12 additions & 0 deletions scripts/ReleaseNotesTemplate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## How to Install
1. Scroll down the the **Assets** and click on **`ButtonHUD.conf`**, this should trigger a download for this file.
1. Save the file to *`%ProgramData%\Dual Universe\Game\data\lua\autoconf\custom`*, the filename does not matter (as long as it's still .conf)
1. In-game, right click your seat and go to *Advanced -> Update custom autoconf list* - If you get a YAML error, you did not follow the above directions corretly.
1. Again, right click your seat and select *Advanced -> Run Custom Autoconfigure -> ButtonsHud - Dimencia and Archaegeo*
1. IMPORTANT: Right click the ship and set the user control scheme to `Keyboard` (*Advanced -> Change Control Scheme -> Keyboard*). This is necessary for the HUD to work, but you can change the actual control scheme in the next step - fear not virtual joystick aces!
1. Right click the seat, choose *Advanced -> Edit LUA Parameters*. Change the `userControlScheme` to the actual control scheme you wish to use (e.g. `Virtual Joystick`). You may mouse over the other parameters and set them as you wish - there are many, you should familiarize yourself with them.
1. If you have a Databank installed on your vehicle you may save your parameters using the `Option 7` key (normally mapped to `ALT-7`). Saved parameters will be restored any time you upgrade the HUD to a new version.

At this point you should be ready to fly!

# Latest Changes
24 changes: 24 additions & 0 deletions scripts/latest-changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -e # exit on any error

# determine rootdir
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
ROOTDIR="$(dirname $DIR)"

VERSIONS=()
while read -r VERSION; do
echo "[$VERSION]" 1>&2

VERSIONS+=("$VERSION")
done < <(cat ${ROOTDIR}/ChangeLog.md | grep -n "^Version *[0-9]*\.[0-9]* *- *.*$")

LATEST="${VERSIONS[0]}"
PREVIOUS="${VERSIONS[1]}"

echo "LATEST: [$LATEST], PREVIOUS: [$PREVIOUS]" 1>&2

LATESTLNO=$(echo "$LATEST" | grep -o '^[0-9]*')
PREVIOUSLNO=$(echo "$PREVIOUS" | grep -o '^[0-9]*')

cat ${ROOTDIR}/ChangeLog.md | head -n $(( $PREVIOUSLNO - 1)) | tail -n $(( $PREVIOUSLNO - $LATESTLNO ))
16 changes: 16 additions & 0 deletions scripts/version-number-from-src.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e # Exit on any error

# Determine rootdir based on our script location
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
ROOTDIR="$(dirname $DIR)"

LUA_SRC=${1:-$ROOTDIR/src/ButtonHUD.lua}

VERSION_NUMBER=`grep "VERSION_NUMBER = .*" $LUA_SRC | sed -E "s/\s*VERSION_NUMBER = (.*)/\1/"`
if [[ "${VERSION_NUMBER}" == "" ]]; then
echo "ERROR: Failed to detect version number" 2>&1; exit 1
fi

echo "$VERSION_NUMBER"
74 changes: 63 additions & 11 deletions scripts/wrap.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,81 @@
#!/bin/bash

set -e # Exit on any error

# Determine rootdir based on our script location
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
ROOTDIR="$(dirname $DIR)"

# Detect luamin binary, preferably use the local luamin, otherwise default to the global luamin
LUAMIN="${ROOTDIR}/scripts/node_modules/.bin/luamin"
if ! which $LUAMIN 1> /dev/null; then
LUAMIN="luamin"
fi
if ! which $LUAMIN 1> /dev/null; then
echo "ERROR: Need luamin in PATH (run \`npm install\` from the scripts/ folder)"; exit 1
fi

# Parse args, or use defaults
MINIFY="${1:-false}"
# We expect this file to be run from the <repo>/scripts directory
LUA_SRC=../src/ButtonHUD.lua
CONF_DST=../ButtonHUD.conf
mkdir -p work
LUA_SRC=${2:-$ROOTDIR/src/ButtonHUD.lua}
CONF_DST=${3:-$ROOTDIR/ButtonHUD.conf}

# Make a fresh work dir
WORK_DIR=${ROOTDIR}/scripts/work
(rm -rf $WORK_DIR/* || true) && mkdir -p $WORK_DIR

# Extract the exports because the minifier will eat them.
grep "\-- \?export:" $LUA_SRC | sed -e 's/^[ \t]*/ /' -e 's/-- export:/--export:/' > work/ButtonHUD.exports
grep "\-- \?export:" $LUA_SRC | sed -e 's/^[ \t]*/ /' -e 's/-- export:/--export:/' > $WORK_DIR/ButtonHUD.exports

VERSION_NUMBER=`grep "VERSION_NUMBER = .*" $LUA_SRC | sed -E "s/\s*VERSION_NUMBER = (.*)/\1/"`
if [[ "${VERSION_NUMBER}" == "" ]]; then
echo "ERROR: Failed to detect version number"; exit 1
fi

sed "/-- \?export:/d;/require 'src.slots'/d" $LUA_SRC > work/ButtonHUD.extracted.lua
sed "/-- \?export:/d;/require 'src.slots'/d" $LUA_SRC > $WORK_DIR/ButtonHUD.extracted.lua

# Minify the lua
if "$1" == "true"; then
node_modules/.bin/luamin --file work/ButtonHUD.extracted.lua > work/ButtonHUD.min.lua
if [[ "$MINIFY" == "true" ]]; then
echo "Minifying ... "
# Using stdin pipe to avoid a bug in luamin complaining about "No such file: ``"
echo "$WORK_DIR/ButtonHUD.extracted.lua" | $LUAMIN --file > $WORK_DIR/ButtonHUD.min.lua
else
cp work/ButtonHUD.extracted.lua work/ButtonHUD.min.lua
cp $WORK_DIR/ButtonHUD.extracted.lua $WORK_DIR/ButtonHUD.min.lua
fi

# Wrap in AutoConf
lua wrap.lua --handle-errors --output yaml --name "ButtonsHud - Dimencia and Archaegeo v$VERSION_NUMBER (Minified)" work/ButtonHUD.min.lua work/ButtonHUD.wrapped.conf --slots core:class=CoreUnit radar:class=RadarPVPUnit,select=manual antigrav:class=AntiGravityGeneratorUnit warpdrive:class=WarpDriveUnit gyro:class=GyroUnit weapon:class=WeaponUnit,select=manual dbHud:class=databank vBooster:class=VerticalBooster hover:class=Hovercraft door:class=DoorUnit,select=manual forcefield:class=ForceFieldUnit,select=manual atmofueltank:class=AtmoFuelContainer,select=manual spacefueltank:class=SpaceFuelContainer,select=manual rocketfueltank:class=RocketFuelContainer,select=manual
SLOTS=(
core:class=CoreUnit
radar:class=RadarPVPUnit,select=manual
antigrav:class=AntiGravityGeneratorUnit
warpdrive:class=WarpDriveUnit
gyro:class=GyroUnit
weapon:class=WeaponUnit,select=manual
dbHud:class=databank
vBooster:class=VerticalBooster
hover:class=Hovercraft
door:class=DoorUnit,select=manual
forcefield:class=ForceFieldUnit,select=manual
atmofueltank:class=AtmoFuelContainer,select=manual
spacefueltank:class=SpaceFuelContainer,select=manual
rocketfueltank:class=RocketFuelContainer,select=manual
)

echo "Wrapping ..."
lua ${ROOTDIR}/scripts/wrap.lua --handle-errors --output yaml \
--name "ButtonsHud - Dimencia and Archaegeo v$VERSION_NUMBER (Minified)" \
$WORK_DIR/ButtonHUD.min.lua $WORK_DIR/ButtonHUD.wrapped.conf \
--slots ${SLOTS[*]}

# Re-insert the exports
sed '/script={}/e cat work/ButtonHUD.exports' work/ButtonHUD.wrapped.conf > $CONF_DST
sed "/script={}/e cat $WORK_DIR/ButtonHUD.exports" $WORK_DIR/ButtonHUD.wrapped.conf > $CONF_DST

# Fix up minified L_TEXTs which requires a space after the comma
sed -i -E 's/L_TEXT\(("[^"]*"),("[^"]*")\)/L_TEXT(\1, \2)/g' $CONF_DST

rm work/*
echo "$VERSION_NUMBER" > ${ROOTDIR}/ButtonHUD.conf.version

echo "Compiled v$VERSION_NUMBER at ${CONF_DST}"

rm $WORK_DIR/*

0 comments on commit 210742c

Please sign in to comment.