# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2026 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

# NOTE: see https://gitea.evergreencrypto.co/EvergreenCrypto/dfi-docs for CI setup

name: docker-finance

run-name: ${{ gitea.actor }} ${{ gitea.event_name }} ${{ gitea.ref }} ${{ gitea.repository }}

on:
  push:
    paths:
      - 'client/**'
      - 'container/**'
      - 'docker-finance.dox'
      - '.gitea/**'
      - '!.gitea/ISSUE_TEMPLATE/**'
      - '!.gitea/PULL_REQUEST_TEMPLATE.yaml'
      - '!.gitignore'
      - '!.img/**'
      - '!CHANGELOG.md'
      - '!LICENSE.md'
      - '!README.md'

cache:
  enable: false

jobs:
  all:
    runs-on: archlinux_vm
    steps:

      ##
      ## Host (act_runner)
      ##

      - name: Host preparation (clone)
        uses: actions/checkout@v4

      # Rationale: in case of failures, cleanup here (instead of later)
      - name: Host preparation (cleanup)
        run: |
          ${{ gitea.workspace }}/.gitea/workflows/dfi.bash host::clean

      # Rationale: it's preferred to work with DOCKER_FINANCE_CLIENT_REPO pointing
      # toward the runner's actual home rather than the job's temporary cache home
      - name: Host preparation (workspace)
        run: |
          mkdir "${HOME}"/docker-finance && cp -aR ${{ gitea.workspace }} "${HOME}"/docker-finance/repo

      ##
      ## Client (host)
      ##

      - name: client::install
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::install

      ##
      ## Client (finance)
      ##

      - name: client::finance::gen
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::gen

      - name: client::finance::edit
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::edit

      - name: client::finance::build
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::build

      - name: client::finance::backup
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::backup

      - name: client::finance::up
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::up

      - name: client::finance::stop
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::stop

      - name: client::finance::start
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::start

      - name: client::finance::down
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::down

      - name: client::finance::shell
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::shell

      - name: client::finance::exec
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::exec

      - name: client::finance::plugins
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::plugins

      - name: client::finance::run
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::run

      - name: client::finance::version
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::version

      - name: client::finance::update
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::update

      - name: client::finance::rm
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::finance::rm

      ##
      ## Container (finance)
      ##

      - name: container::finance::edit
        run: |
          CI_DFI_FETCH_MOBULA=${{ secrets.CI_DFI_FETCH_MOBULA }} \
          CI_DFI_FETCH_COINGECKO=${{ secrets.CI_DFI_FETCH_COINGECKO }} \
          CI_DFI_FETCH_ETHERSCAN=${{ secrets.CI_DFI_FETCH_ETHERSCAN }} \
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::edit

      - name: container::finance::fetch
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::fetch

      - name: container::finance::import
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::import

      - name: container::finance::hledger
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::hledger

      - name: container::finance::hledger-ui
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::hledger-ui

      - name: container::finance::hledger-vui
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::hledger-vui

      - name: container::finance::hledger-web
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::hledger-web

      - name: container::finance::meta
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::meta

      - name: container::finance::reports
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::reports

      - name: container::finance::taxes
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::taxes

      - name: container::finance::times
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::times

      - name: container::finance::plugins
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::plugins

      - name: container::finance::root
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash container::finance::root

      ##
      ## Client (dev-tools)
      ##

      - name: client::dev-tools::gen
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::gen

      - name: client::dev-tools::edit
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::edit

      - name: client::dev-tools::build
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::build

      - name: client::dev-tools::backup
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::backup

      - name: client::dev-tools::up
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::up

      - name: client::dev-tools::stop
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::stop

      - name: client::dev-tools::start
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::start

      - name: client::dev-tools::down
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::down

      - name: client::dev-tools::shell
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::shell

      - name: client::dev-tools::exec
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::exec

      - name: client::dev-tools::plugins
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::plugins

      - name: client::dev-tools::run
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::run

      - name: client::dev-tools::version
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::version

      - name: client::dev-tools::update
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::update

      - name: client::dev-tools::license
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::license

      - name: client::dev-tools::linter
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::linter

      - name: client::dev-tools::doxygen
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::doxygen

      - name: client::dev-tools::rm
        run: |
          "${HOME}"/docker-finance/repo/.gitea/workflows/dfi.bash client::dev-tools::rm

      ##
      ## Host (act_runner)
      ##

      - name: Job status
        run: echo "${{ job.status }}"
