Skip to content

nwn2-tools

nwn2-tools #113

Workflow file for this run

name: nwn2-tools
on:
push:
schedule:
- cron: '0 0 * * 6'
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
platform: ["linux-gnu", "windows-msvc"]
arch: ["i686", "x86_64"]
steps:
- uses: actions/checkout@v2
- name: Install requirements
run: |
sudo apt install -q -y p7zip libxml2-dev make gcc-multilib mingw-w64
echo "========= Install latest LDC ========="
wget -q https://dlang.org/install.sh -O /tmp/install.sh
bash /tmp/install.sh install ldc
echo "========= Create LDC activation symlink ========="
ln -s "$(bash /tmp/install.sh install ldc -a)" ~/dlang/activate
source ~/dlang/activate
echo "========= Install LDC windows libs for cross compiling ========="
cd ~/dlang/
LDC_VERSION=$(ldc2 --version | head -n1 | grep -oE '[0-9]+(\.[0-9]+){2}')
wget -q "https://github.com/ldc-developers/ldc/releases/download/v$LDC_VERSION/ldc2-$LDC_VERSION-windows-multilib.7z"
7zr x "ldc2-$LDC_VERSION-windows-multilib.7z" -bd
echo "========= Configure LDC for cross compiling for windows targets ========="
cat >> ~/dlang/ldc-$LDC_VERSION/etc/ldc2.conf << EOF
"i686-.*-windows-msvc":
{
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
"-link-defaultlib-shared=false",
];
lib-dirs = [
"$HOME/dlang/ldc2-$LDC_VERSION-windows-multilib/lib32",
];
};
"x86_64-.*-windows-msvc":
{
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
"-link-defaultlib-shared=false",
];
lib-dirs = [
"$HOME/dlang/ldc2-$LDC_VERSION-windows-multilib/lib64",
];
};
EOF
cd -
# Print ldc compiler version
echo "================================"
ldc2 --version | head -n6
echo "================================"
- name: Create bin output dir
run: mkdir -p bin/
- name: Build nwn2-moduleinstaller
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
cd moduleinstaller
dub build --compiler=ldc2 --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
mv nwn2-moduleinstaller$BIN_SUFFIX ../bin/
- name: Build nwn2-stagingtool
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
# Mingw is not able to generate i686 windows binaries with SEH (exception handling)
# However ldc2 requires SEH-enabled object files (/SAFESEH)
# See http://mingw-w64.org/doku.php/contribute#seh_for_32bits
if [[ "${{ matrix.arch }}-${{ matrix.platform }}" == "i686-windows-msvc" ]]; then
echo "Skipping Windows 32-bit staging tool"
exit 0
fi
cd stagingtool
if [[ "${{ matrix.platform }}" == windows-* ]]; then
make mingw-${{ matrix.arch }}
else
if [[ "${{ matrix.arch }}" == "i686" ]]; then
make CFLAGS="-m32" LDFLAGS="-melf_i386"
else
make CFLAGS="-m64"
fi
fi
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
mv nwn2-stagingtool$BIN_SUFFIX ../bin/
- name: Build nwn2-itemupdater
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
cd itemupdater
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
mv nwn2-itemupdater$BIN_SUFFIX ../bin/
- name: Build nwn2-camtosql
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
cd camtosql
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release :upgrade-scripts
mv nwn2-camtosql$BIN_SUFFIX nwn2-camtosql-upgrade-scripts$BIN_SUFFIX ../bin/
- name: Build nwn2-adjust-item-prices
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
cd adjust-item-prices
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
mv nwn2-adjust-item-prices$BIN_SUFFIX ../bin/
- name: Build nwn2-update-module-arealist
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
cd update-module-arealist
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
mv nwn2-update-module-arealist$BIN_SUFFIX ../bin/
- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: "nwn2-tools-${{ matrix.arch }}-${{ matrix.platform }}"
path: bin
create_release:
name: Create release if tagged
needs: build
runs-on: ubuntu-latest
steps:
- name: Get release info
id: rel_info
run: |
TAG=$(echo '${{ github.ref }}' | grep -oE '\bv[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$' || true)
echo "::set-output name=tag::$TAG"
[[ "$TAG" =~ '-rc[0-9]+$' ]] && PRERELEASE=true || PRERELEASE=false
echo "::set-output name=prerelease::$PRERELEASE"
if [[ "$TAG" != "" ]]; then
echo "Deploying $TAG (prerelease=$PRERELEASE)"
else
echo "Not a tagged release"
fi
- name: Delete any existing release
if: steps.rel_info.outputs.tag != ''
run: |
RELEASE_JSON=$(
curl -sL --header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.rel_info.outputs.tag }}"
)
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r .id)
if [[ "$RELEASE_ID" != "null" ]]; then
echo "Removing existing release ID=$RELEASE_ID"
curl -sL --header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-XDELETE "https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID"
fi
- name: Create Release
if: steps.rel_info.outputs.tag != ''
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.rel_info.outputs.tag }}
release_name: ${{ steps.rel_info.outputs.tag }}
prerelease: ${{ steps.rel_info.outputs.prerelease }}
body: |
Automated release with GitHub Actions
> The windows-i686 package does not provide the nwn2-stagingtool executable.
release:
name: Release if tagged
runs-on: ubuntu-latest
needs: create_release
strategy:
matrix:
platform: ["linux-gnu", "windows-msvc"]
arch: ["i686", "x86_64"]
steps:
- name: Get release info
id: rel_info
run: |
TAG=$(echo '${{ github.ref }}' | grep -oE '\bv[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$' || true)
echo "::set-output name=tag::$TAG"
[[ "$TAG" =~ '-rc[0-9]+$' ]] && PRERELEASE=true || PRERELEASE=false
echo "::set-output name=prerelease::$PRERELEASE"
if [[ "$TAG" != "" ]]; then
echo "Deploying $TAG (prerelease=$PRERELEASE)"
else
echo "Not a tagged release"
fi
- name: Install requirements & setup env
if: steps.rel_info.outputs.tag != ''
run: sudo apt install -q -y xz-utils zip
- name: Download artifacts
if: steps.rel_info.outputs.tag != ''
uses: actions/download-artifact@v1
with:
name: "nwn2-tools-${{ matrix.arch }}-${{ matrix.platform }}"
- name: Package artifacts
if: steps.rel_info.outputs.tag != ''
id: create_pkg
run: |
BASENAME="nwn2-tools-$(echo "${{ matrix.platform }}" | cut -d '-' -f 1)-${{ matrix.arch }}"
cd "nwn2-tools-${{ matrix.arch }}-${{ matrix.platform }}"
if [[ "${{ matrix.platform }}" == windows-* ]]; then
PKG="$BASENAME.zip"
zip -9 ../$PKG *
echo "::set-output name=mime_type::application/zip"
else
PKG="$BASENAME.tar.xz"
tar cfJ ../$PKG *
echo "::set-output name=mime_type::application/x-xz"
fi
cd -
echo "::set-output name=file::$PKG"
- name: Get release upload URL
if: steps.rel_info.outputs.tag != ''
id: get_release_url
run: |
RELEASE_JSON=$(
curl -sL --header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.rel_info.outputs.tag }}"
)
echo "::set-output name=upload_url::$(echo "$RELEASE_JSON" | jq -er .upload_url)"
- name: Upload Release Assets
if: steps.rel_info.outputs.tag != ''
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release_url.outputs.upload_url }}
asset_path: ${{ steps.create_pkg.outputs.file }}
asset_name: ${{ steps.create_pkg.outputs.file }}
asset_content_type: ${{ steps.create_pkg.outputs.mime_type }}