|
| 1 | +name: Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + pull_request: |
| 7 | + branches: [main, master] |
| 8 | + |
| 9 | +# This workflow is copied verbatim by cookiecutter (see _copy_without_render in |
| 10 | +# cookiecutter.json) so GitHub's ${{ ... }} expressions survive generation. It |
| 11 | +# is self-describing — it loads whatever repo it lives in via |
| 12 | +# ${{ github.repository }}, so no per-library edits are needed. |
| 13 | + |
| 14 | +jobs: |
| 15 | + test: |
| 16 | + runs-on: ${{ matrix.os }} |
| 17 | + container: ${{ matrix.container }} |
| 18 | + name: ${{ matrix.label }} |
| 19 | + defaults: |
| 20 | + run: |
| 21 | + shell: bash |
| 22 | + # Mirror alexzhangs/xsh's shell matrix: bash 3.2 / 4.4 / 5.x + zsh 5.x. |
| 23 | + # Utilities run under zsh's ksh emulation (provided by xsh >= 0.7.0). |
| 24 | + strategy: |
| 25 | + fail-fast: false |
| 26 | + matrix: |
| 27 | + include: |
| 28 | + - { os: ubuntu-latest, container: '', shell_path: /bin/bash, label: bash-5.x-linux } |
| 29 | + - { os: macos-latest, container: '', shell_path: /bin/bash, label: bash-3.2-macos } |
| 30 | + - { os: macos-latest, container: '', shell_path: brew, label: bash-5.x-macos } |
| 31 | + - { os: ubuntu-latest, container: rockylinux:8, shell_path: /bin/bash, label: bash-4.4-linux } |
| 32 | + - { os: macos-latest, container: '', shell_path: /bin/zsh, label: zsh-5.x-macos } |
| 33 | + - { os: ubuntu-latest, container: '', shell_path: /usr/bin/zsh, label: zsh-5.x-linux } |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Pre-install git (rockylinux container) |
| 37 | + if: matrix.container != '' |
| 38 | + run: dnf install -y git |
| 39 | + |
| 40 | + - name: Install dependencies (rockylinux container) |
| 41 | + if: matrix.container != '' |
| 42 | + run: | |
| 43 | + dnf install -y --allowerasing coreutils |
| 44 | + dnf install -y gawk sed file findutils diffutils procps-ng which tar gzip python3 |
| 45 | + command -v python >/dev/null 2>&1 || ln -sf "$(command -v python3)" /usr/local/bin/python |
| 46 | + git config --global --add safe.directory '*' |
| 47 | +
|
| 48 | + - name: Install zsh (Linux) |
| 49 | + if: matrix.container == '' && runner.os == 'Linux' && contains(matrix.shell_path, 'zsh') |
| 50 | + run: sudo apt-get update && sudo apt-get install -y zsh |
| 51 | + |
| 52 | + - name: Install Homebrew bash (macOS bash 5.x) |
| 53 | + if: matrix.shell_path == 'brew' |
| 54 | + run: | |
| 55 | + brew install bash |
| 56 | + echo "SHELL_PATH=$(brew --prefix)/bin/bash" >> "$GITHUB_ENV" |
| 57 | +
|
| 58 | + - name: Set shell path |
| 59 | + if: matrix.shell_path != 'brew' |
| 60 | + run: echo "SHELL_PATH=${{ matrix.shell_path }}" >> "$GITHUB_ENV" |
| 61 | + |
| 62 | + - name: Install xsh |
| 63 | + run: | |
| 64 | + git clone --depth=50 --branch=master https://github.com/alexzhangs/xsh.git /tmp/xsh |
| 65 | + bash /tmp/xsh/install.sh |
| 66 | +
|
| 67 | + - name: Load dependency library xsh-lib/core |
| 68 | + run: | |
| 69 | + source ~/.xshrc |
| 70 | + xsh load xsh-lib/core |
| 71 | +
|
| 72 | + - name: Load library from current branch |
| 73 | + run: | |
| 74 | + source ~/.xshrc |
| 75 | + xsh load -b "${{ github.head_ref || github.ref_name }}" "${{ github.repository }}" |
| 76 | +
|
| 77 | + - name: Run tests (${{ matrix.label }}) |
| 78 | + # test.sh self-sources ~/.xshrc, so running it under $SHELL_PATH makes |
| 79 | + # the utilities execute under that shell (bash, or zsh's ksh emulation). |
| 80 | + run: | |
| 81 | + "$SHELL_PATH" ~/.xsh/repo/"${{ github.repository }}"/test.sh |
0 commit comments