.aur_base:
    image: archlinux:latest
    dependencies:
    needs: []
    before_script:
        - pacman -Syu --noconfirm
        - pacman -S --noconfirm git base-devel fakeroot openssh namcap xorg-xauth cmake # Base system stuff and dev tools
        - pacman -S --noconfirm 'python' 'zlib' 'hicolor-icon-theme' 'potrace' 'ffmpeg' 'libarchive' 'qt6-tools' 'qt6-base' 'qt6-imageformats' 'qt6-svg' # Deps
        - pacman -S --noconfirm clang qt6-declarative # lupdate deps (for some reason they don't get installed automativally)
    script:
        # Check
        - test -n "$PACK_NAME" -a -n "$AUR_SSH_KEY"
        # Setup
        - useradd -m foo
        - chmod 600 "$AUR_SSH_KEY"
        - mkdir -p build
        - cd build
        - cmake .. -DVERSION_SUFFIX=
        # Settings
        - PROJECT_VERSION="$(../deploy/get_version.sh CMakeCache.txt)"
        - git config --global user.name "Glaxnimate CI"
        - git config --global user.email "glaxnimate-ci@mattbas.org"
        - git config --global --add safe.directory '*'
        # Build
        - GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -i $AUR_SSH_KEY" git clone ssh://aur@aur.archlinux.org/$PACK_NAME.git
        - cd $PACK_NAME
        - sed ../../deploy/PKGBUILD -e "/^pkgname=/s/\".*\"/\"$PACK_NAME\"/" -e "/^pkgver=/s/=.*/=$PROJECT_VERSION/" -e "/^_git_branch=/s/=.*/=$CI_COMMIT_BRANCH/"> PKGBUILD
        - chown -R foo .
        - sudo -u foo makepkg -f
        - namcap PKGBUILD
        - sudo -u foo makepkg --printsrcinfo > .SRCINFO
        - chown -R root .
        - git diff
        - if ! git diff-index --quiet HEAD -- ; then git commit -am "Update to version $PROJECT_VERSION" ; GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -i $AUR_SSH_KEY" git push || $IGNORE_PUSH_FAIL ; fi

linux:aur:
    extends: .aur_base
    stage: deploy
    # Build on release instead of tag so we can trigger it again
    only:
        - release
    variables:
        PACK_NAME: glaxnimate
        IGNORE_PUSH_FAIL: "false"

linux:aur_build:
    extends: .aur_base
    stage: build
    only:
        - master
    variables:
        PACK_NAME: glaxnimate-git
        IGNORE_PUSH_FAIL: "true"
