on: [ push, pull_request ]

env:
  #
  # List of tests to run as found in testdata/example-$test. The
  # directory will be used to create a git repository, uploaded to a
  # Forgejo instance. The test will be a success once the status of
  # the commit is success, as set by the Forgejo Action run.
  #
  TESTS: 'echo service container expression local-action docker-action'

jobs:
  integration:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v3
      - run: |
          set -x
          LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh
          ./forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo 1.19
          #
          # Uncomment the following for a shortcut to debugging the Forgejo runner.
          # It will build the runner from a designated repository and branch instead of
          # downloading it from a canonical release.
          #
          #./forgejo-test-helper.sh build_runner http://code.forgejo.org/earl-warren/runner wip-sync
          #export PATH=$(pwd)/forgejo-runner:$PATH
          #
          ./forgejo-runner.sh setup
          export FORGEJO_RUNNER_LOGS=forgejo-runner.log
          for example in $TESTS ; do

            if test $example = service ; then
               > /srv/example-service-volume-valid
               > /srv/example-service-volume-invalid
            fi

            config=$(pwd)/testdata/example-$example/runner-config.yaml
            if test -f $config ; then
              FORGEJO_RUNNER_CONFIG=$config ./forgejo-runner.sh reload
            fi

            echo "============================ BEGIN example-$example ==================="
            ./forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token)
            echo "============================ END example-$example ==================="

            if test -f $config ; then
              ./forgejo-runner.sh reload
            fi
          done
          echo "============================ demo ==================="
          ./forgejo-test-helper.sh run_workflow testdata/demo http://root:admin1234@$(cat forgejo-ip):3000 root demo setup-forgejo $(cat forgejo-token) > /tmp/output
          grep '^sha=' /tmp/output