Installing Sway on an Alpine machine. What am I misunderstanding?

The Alpine wiki has a great tutorial for getting Sway up and running on Alpine, but I am still having some trouble. I follow all the command related steps, then add the following:

#! /bin/bash
if test -z "${XDG_RUNTIME_DIR}"; then
  export XDG_RUNTIME_DIR=/tmp/$(id -u)-runtime-dir
  if ! test -d "${XDG_RUNTIME_DIR}"; then
    mkdir "${XDG_RUNTIME_DIR}"
    chmod 0700 "${XDG_RUNTIME_DIR}"
  fi
fi

and save it as XDG_RUNTIME_DIR under /etc/profile.d. When I run the command sway, it returns the following error: XDG_RUNTIME_DIR is not set in the environment. Aborting.

What am I misunderstanding about the XDG_RUNTIME_DIR step?