name: docker build

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]
  workflow_dispatch:

permissions:
  contents: read

concurrency:
    group: ${{ github.workflow }}-${{ github.ref }}
    cancel-in-progress: true

jobs:
    build:
        runs-on: ubuntu-22.04
        strategy:
            fail-fast: false
            matrix:
                include:
                    - image: debian:stable

        container:
            image: ${{ matrix.image }}

        steps:
            - name: Checkout main repository
              uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744  # v3
              with:
                  persist-credentials: false
            # - name: Checkout developer-meta-files
            #   uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744  # v3
            #   with:
            #       repository: Kicksecure/developer-meta-files
            #       path: developer-meta-files
            - name: System Basic Packages
              run: |
                  apt-get update
                  apt-get install --yes --no-install-recommends adduser shellcheck libxml2-utils nsis fpc lazarus git ca-certificates libfile-mimeinfo-perl wget
            - name: Install Packages from Debian trixie
              run: |
                  echo 'Types: deb' | tee /etc/apt/sources.list.d/trixie.sources
                  echo 'URIs: https://deb.debian.org/debian' | tee -a /etc/apt/sources.list.d/trixie.sources
                  echo 'Suites: trixie' | tee -a /etc/apt/sources.list.d/trixie.sources
                  echo 'Components: main' | tee -a /etc/apt/sources.list.d/trixie.sources
                  echo 'Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg' | tee -a /etc/apt/sources.list.d/trixie.sources
                  echo 'Types: deb' | tee /etc/apt/sources.list.d/derivative.sources
                  echo 'URIs: https://deb.kicksecure.com' | tee -a /etc/apt/sources.list.d/derivative.sources
                  echo 'Suites: trixie' | tee -a /etc/apt/sources.list.d/derivative.sources
                  echo 'Components: main contrib non-free' | tee -a /etc/apt/sources.list.d/derivative.sources
                  echo 'Enabled: yes' | tee -a /etc/apt/sources.list.d/derivative.sources
                  echo 'Signed-By: /usr/share/keyrings/derivative.asc' | tee -a /etc/apt/sources.list.d/derivative.sources
                  wget -O /usr/share/keyrings/derivative.asc 'https://www.kicksecure.com/keys/derivative.asc'
                  apt-get update
                  apt-get install --yes --no-install-recommends fp-units-win-base fp-units-win-rtl fp-units-win-fcl fp-units-win-misc helper-scripts
            - name: System information
              run: |
                  whoami
                  cat /etc/os-release
                  uname -a
                  echo "${PATH}"
            - name: Create regular (non-root) user
              run: adduser --comment "" --disabled-password user
            - name: Linux user file permissions fix
              run: chown --recursive user:user /__w/Whonix-Starter
            # - name: ppcross_install
            #   run: ./developer-meta-files/usr/bin/ppcross_install all
            - name: Build Starter
              run: su -s /bin/bash user -- ./build_on_linux_for_win64
            - name: ShellCheck
              run: shellcheck -x ./build_on_linux_for_win64
