nwn-lib-d #159
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: nwn-lib-d | |
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 | |
with: | |
fetch-depth: 0 | |
- name: Dub cache | |
uses: actions/cache@v2 | |
with: | |
path: ~/.dub | |
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.json') }} | |
restore-keys: | | |
${{ runner.os }}-dub- | |
# Setup | |
- name: Install requirements | |
run: | | |
sudo apt update && 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 "================================" | |
# Testing | |
- name: Run unit tests | |
if: matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64' | |
run: | | |
source ~/dlang/activate | |
dub test --compiler=ldc2 --arch=${{ matrix.arch }}-${{ matrix.platform }} -b unittest-cov | |
cat source/nwn/ver.d | |
for MOD in tools/nwn-*; do | |
cd "$MOD" | |
dub test --compiler=ldc2 --arch=${{ matrix.arch }}-${{ matrix.platform }} -b unittest-cov | |
cd - | |
done | |
- name: "Upload coverage info" | |
if: matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64' | |
run: | | |
bash <(curl -s https://codecov.io/bash) | |
# Tooling | |
- name: Build nwn-lib-d tools | |
run: | | |
source ~/dlang/activate | |
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX="" | |
mkdir -p bin/ | |
for MOD in tools/nwn-*; do | |
cd "$MOD" | |
dub build --compiler=ldc2 --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release | |
mv "$(basename "$MOD")$BIN_SUFFIX" ../../bin/ | |
cd - | |
done | |
- name: Upload bin artifacts | |
uses: actions/upload-artifact@v2 | |
with: | |
name: "nwn-lib-d-tools-${{ matrix.platform }}-${{ matrix.arch }}" | |
path: bin | |
# Documentation | |
- name: "Generate documentation" | |
if: matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64' | |
run: | | |
source ~/dlang/activate | |
dub build --build=ddox | |
rm docs/nwn/nwscript/constants/* # | |
mkdir public/ | |
mv docs docs.json public/ | |
cp .github/index.html public/ | |
tar cfJ documentation.tar.xz public/ | |
- name: Upload documentation artifacts | |
if: matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64' | |
uses: actions/upload-artifact@v2 | |
with: | |
name: "documentation.tar.xz" | |
path: documentation.tar.xz | |
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 | |
- uses: actions/checkout@v2 | |
if: steps.rel_info.outputs.tag != '' | |
with: | |
fetch-depth: 0 | |
- name: Generate changelog | |
if: steps.rel_info.outputs.tag != '' | |
id: changelog | |
run: | | |
CHANGELOG=$(.github/workflows/gen-changelog.sh) | |
echo "$CHANGELOG" | |
CHANGELOG="${CHANGELOG//'%'/'%25'}" | |
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" | |
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" | |
echo "::set-output name=log::$CHANGELOG" | |
- 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 | |
${{ steps.changelog.log }} | |
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@v2 | |
with: | |
name: "nwn-lib-d-tools-${{ matrix.platform }}-${{ matrix.arch }}" | |
path: "nwn-lib-d-tools" | |
- name: Package artifacts | |
if: steps.rel_info.outputs.tag != '' | |
id: create_pkg | |
run: | | |
BASENAME="nwn-lib-d-tools-$(echo "${{ matrix.platform }}" | cut -d '-' -f 1)-${{ matrix.arch }}" | |
ARTIFACTS="nwn-lib-d-tools" | |
if [[ "${{ matrix.platform }}" == windows-* ]]; then | |
PKG="$BASENAME.zip" | |
zip -9 -r "$PKG" "$ARTIFACTS" | |
echo "::set-output name=mime_type::application/zip" | |
else | |
PKG="$BASENAME.tar.xz" | |
tar cfJ "$PKG" "$ARTIFACTS" | |
echo "::set-output name=mime_type::application/x-xz" | |
fi | |
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 }} | |
# GH pages | |
- name: Download documentation artifact | |
if: steps.rel_info.outputs.tag != '' && matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64' | |
uses: actions/download-artifact@v2 | |
with: | |
name: "documentation.tar.xz" | |
- name: Extract documentation | |
if: steps.rel_info.outputs.tag != '' && matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64' | |
run: | | |
tar xf documentation.tar.xz | |
- name: Deploy documentation | |
if: steps.rel_info.outputs.tag != '' && matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64' | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./public | |