# Workflow for testing multiple bash versions with Docker
name: bash

on:
  workflow_dispatch:
  pull_request:
    paths-ignore:
      - '.github/workflows/*.ya?ml'
      - '!.github/workflows/bash.yml'
      - 'cylc/flow/etc/syntax/**'
      - 'etc/syntax/**'
      - 'tests/unit/**'
      - 'tests/integration/**'
      - '**.md'
      - '**/README*/**'
  push:
    branches:
      - master
      - '8.*.x'
    paths-ignore:
      - '.github/workflows/*.ya?ml'
      - '!.github/workflows/bash.yml'
      - 'cylc/flow/etc/syntax/**'
      - 'etc/syntax/**'
      - 'tests/unit/**'
      - 'tests/integration/**'
      - '**.md'
      - '**/README*/**'

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

defaults:
  run:
    shell: bash

env:
  FORCE_COLOR: 2
  PIP_PROGRESS_BAR: off

jobs:
  bash-docker:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    strategy:
      fail-fast: false
      matrix:
        bash-version:
          - '3.2'
          - '4.2'
          # if you use a value like 5.0, YAML will round it to 5, which will cause an error later on
          - '5.0'
    env:
      IMAGE: 'ghcr.io/cylc/cylc-bash-testing-2:master'
    steps:
      - name: Checkout
        uses: actions/checkout@v5

      - name: Run Docker container
        run: |
          docker pull "$IMAGE"
          docker run --name bash -v $(pwd -P):/root/cylc-flow --rm -t -d -m 1G --memory-swap 1G "$IMAGE" /bin/bash
          docker ps -a

      - name: Install Cylc dependencies in the container
        run: |
          docker exec -w /root/cylc-flow bash python3.12 -m pip install .[all] --break-system-packages

      - name: Set the container bash version
        run: docker exec bash update-alternatives --set bash /bash/bash-${{ matrix.bash-version }}

      - name: Run functional tests that validate or are related to how Cylc uses bash
        run: |
          docker exec -w /root/cylc-flow bash \
            ./etc/bin/run-functional-tests -v \
            tests/functional/broadcast/00-simple.t \
            tests/functional/cylc-poll/11-event-time.t \
            tests/functional/cylc-poll/15-job-st-file-no-batch.t \
            tests/functional/events/28-inactivity.t \
            tests/functional/events/34-task-abort.t \
            tests/functional/job-file-trap/00-sigusr1.t \
            tests/functional/job-file-trap/02-pipefail.t \
            tests/functional/job-file-trap/03-user-trap.t \
            tests/functional/jobscript/00-torture.t \
            tests/functional/pause-resume/12-pause-then-retry.t \
            tests/functional/shutdown/09-now2.t \
            tests/functional/shutdown/13-no-port-file-check.t \
            tests/functional/shutdown/14-no-dir-check.t

      - name: Copy cylc-run out of container
        if: failure()
        run: |
          docker cp bash:/root/cylc-run .

      - name: Upload artifact
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: 'cylc-run (bash-${{ matrix.bash-version }})'
          path: cylc-run
          include-hidden-files: true
