|
1 | 1 | name: ci-unittest |
2 | 2 |
|
3 | | -on: [push, pull_request] |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
4 | 8 |
|
5 | 9 | jobs: |
6 | 10 | test: |
7 | 11 | runs-on: ${{ matrix.os }} |
8 | | - name: ${{ matrix.os }} / ${{ matrix.shell }} |
| 12 | + container: ${{ matrix.container }} |
| 13 | + name: ${{ matrix.label }} |
| 14 | + defaults: |
| 15 | + run: |
| 16 | + shell: bash |
| 17 | + # Mirror alexzhangs/xsh's shell matrix: bash 3.2 / 4.4 / 5.x + zsh 5.x. |
| 18 | + # Utilities run under zsh's ksh emulation (provided by xsh >= 0.7.0). |
9 | 19 | strategy: |
10 | 20 | fail-fast: false |
11 | 21 | matrix: |
12 | | - os: [ubuntu-latest, macos-latest] |
13 | | - # bash is the historical target; zsh is the macOS default login shell. |
14 | | - # Utilities run under zsh's ksh emulation (provided by xsh). |
15 | | - shell: [bash, zsh] |
| 22 | + include: |
| 23 | + - { os: ubuntu-latest, container: '', shell_path: /bin/bash, label: bash-5.x-linux } |
| 24 | + - { os: macos-latest, container: '', shell_path: /bin/bash, label: bash-3.2-macos } |
| 25 | + - { os: macos-latest, container: '', shell_path: brew, label: bash-5.x-macos } |
| 26 | + - { os: ubuntu-latest, container: rockylinux:8, shell_path: /bin/bash, label: bash-4.4-linux } |
| 27 | + - { os: macos-latest, container: '', shell_path: /bin/zsh, label: zsh-5.x-macos } |
| 28 | + - { os: ubuntu-latest, container: '', shell_path: /usr/bin/zsh, label: zsh-5.x-linux } |
16 | 29 |
|
17 | 30 | steps: |
18 | | - - uses: actions/checkout@v4 |
19 | | - |
20 | | - - name: Install zsh (Linux) |
21 | | - if: matrix.shell == 'zsh' && runner.os == 'Linux' |
22 | | - run: sudo apt-get update && sudo apt-get install -y zsh |
23 | | - |
24 | | - - name: Install xsh |
25 | | - run: | |
26 | | - git clone --depth=50 https://github.com/alexzhangs/xsh.git xsh-source |
27 | | - bash xsh-source/install.sh |
28 | | -
|
29 | | - - name: Load deps |
30 | | - run: | |
31 | | - # shellcheck disable=SC1090 |
32 | | - source ~/.xshrc |
33 | | - xsh load xsh-lib/core |
34 | | - # Load this lib at the branch under test. xsh load does a full clone |
35 | | - # from origin and checks out the branch, so the workflow exercises the |
36 | | - # commit that triggered it. Fork PRs fall back to the default branch |
37 | | - # (the source branch isn't on the main repo). |
38 | | - BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" |
39 | | - xsh load -b "$BRANCH" xsh-lib/git || xsh load xsh-lib/git |
40 | | -
|
41 | | - - name: Run tests (${{ matrix.shell }}) |
42 | | - run: | |
43 | | - # shellcheck disable=SC1090 |
44 | | - source ~/.xshrc |
45 | | - xsh version |
46 | | - xsh list |
47 | | - # test.sh self-sources ~/.xshrc, so running it under the matrix shell |
48 | | - # makes the utilities execute under that shell (bash, or zsh's ksh |
49 | | - # emulation). |
50 | | - ${{ matrix.shell }} test.sh |
| 31 | + - name: Pre-install git (rockylinux container) |
| 32 | + if: matrix.container != '' |
| 33 | + run: dnf install -y git |
| 34 | + |
| 35 | + - name: Install dependencies (rockylinux container) |
| 36 | + if: matrix.container != '' |
| 37 | + run: | |
| 38 | + dnf install -y --allowerasing coreutils |
| 39 | + dnf install -y gawk sed file findutils diffutils procps-ng which tar gzip python3 |
| 40 | + command -v python >/dev/null 2>&1 || ln -sf "$(command -v python3)" /usr/local/bin/python |
| 41 | + git config --global --add safe.directory '*' |
| 42 | +
|
| 43 | + - name: Install zsh (Linux) |
| 44 | + if: matrix.container == '' && runner.os == 'Linux' && contains(matrix.shell_path, 'zsh') |
| 45 | + run: sudo apt-get update && sudo apt-get install -y zsh |
| 46 | + |
| 47 | + - name: Install Homebrew bash (macOS bash 5.x) |
| 48 | + if: matrix.shell_path == 'brew' |
| 49 | + run: | |
| 50 | + brew install bash |
| 51 | + echo "SHELL_PATH=$(brew --prefix)/bin/bash" >> "$GITHUB_ENV" |
| 52 | +
|
| 53 | + - name: Set shell path |
| 54 | + if: matrix.shell_path != 'brew' |
| 55 | + run: echo "SHELL_PATH=${{ matrix.shell_path }}" >> "$GITHUB_ENV" |
| 56 | + |
| 57 | + - name: Install xsh |
| 58 | + run: | |
| 59 | + git clone --depth=50 --branch=master https://github.com/alexzhangs/xsh.git /tmp/xsh |
| 60 | + bash /tmp/xsh/install.sh |
| 61 | +
|
| 62 | + - name: Load dependency library xsh-lib/core |
| 63 | + run: | |
| 64 | + source ~/.xshrc |
| 65 | + xsh load xsh-lib/core |
| 66 | +
|
| 67 | + - name: Load library from current branch |
| 68 | + run: | |
| 69 | + source ~/.xshrc |
| 70 | + # Fork PRs fall back to the default branch (the source branch isn't on |
| 71 | + # the main repo). |
| 72 | + xsh load -b "${{ github.head_ref || github.ref_name }}" xsh-lib/git || xsh load xsh-lib/git |
| 73 | +
|
| 74 | + - name: Run tests (${{ matrix.label }}) |
| 75 | + run: "$SHELL_PATH" ~/.xsh/repo/xsh-lib/git/test.sh |
0 commit comments