Skip to content

Commit

Permalink
OS-specific composite actions (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Feb 27, 2024
1 parent b91eeb9 commit fe2d5fc
Show file tree
Hide file tree
Showing 9 changed files with 1,526 additions and 62 deletions.
198 changes: 180 additions & 18 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ jobs:
with:
sarif_file: ${{ steps.scan.outputs.sarif }}

publish-composite:
publish-linux:
name: Publish Test Results (${{ matrix.os-label }} python ${{ matrix.python }})
runs-on: ${{ matrix.os }}
permissions:
Expand All @@ -224,10 +224,72 @@ jobs:

strategy:
fail-fast: false
max-parallel: 3
max-parallel: 2
matrix:
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
include:
- os: ubuntu-latest
os-label: Linux
python: "3.8"
- os: ubuntu-latest
os-label: Linux
python: "venv"
- os: ubuntu-latest
os-label: Linux
python: "installed"
- os: ubuntu-20.04
os-label: Linux 20.04
python: "installed"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
if: matrix.python != 'installed' && matrix.python != 'venv'
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install virtualenv
if: matrix.python == 'venv'
run: python3 -m pip install virtualenv
shell: bash

- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Publish Test Results
id: test-results
uses: ./linux
with:
check_name: Test Results (${{ matrix.os-label }} python ${{ matrix.python }})
files: artifacts/**/*.xml
json_file: "tests.json"
json_suite_details: true
json_test_case_results: true
report_suite_logs: "any"

- name: JSON output
uses: ./misc/action/json-output
with:
json: '${{ steps.test-results.outputs.json }}'
json_file: 'tests.json'

publish-macos:
name: Publish Test Results (${{ matrix.os-label }} python ${{ matrix.python }})
runs-on: ${{ matrix.os }}
permissions:
checks: write
pull-requests: write

strategy:
fail-fast: false
max-parallel: 2
matrix:
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
# test *-latest and newer (because newer eventually become 'latest' and should be tested to work before that)
include:
- os: macos-latest
os-label: macOS
Expand All @@ -248,19 +310,56 @@ jobs:
os-label: macOS 14
python: "installed"

- os: ubuntu-latest
os-label: Linux
python: "3.8"
- os: ubuntu-latest
os-label: Linux
python: "venv"
- os: ubuntu-latest
os-label: Linux
python: "installed"
- os: ubuntu-20.04
os-label: Linux 20.04
python: "installed"
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
if: matrix.python != 'installed' && matrix.python != 'venv'
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install virtualenv
if: matrix.python == 'venv'
run: python3 -m pip install virtualenv
shell: bash

- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Publish Test Results
id: test-results
uses: ./macos
with:
check_name: Test Results (${{ matrix.os-label }} python ${{ matrix.python }})
files: artifacts/**/*.xml
json_file: "tests.json"
json_suite_details: true
json_test_case_results: true
report_suite_logs: "any"

- name: JSON output
uses: ./misc/action/json-output
with:
json: '${{ steps.test-results.outputs.json }}'
json_file: 'tests.json'

publish-windows:
name: Publish Test Results (${{ matrix.os-label }} python ${{ matrix.python }})
runs-on: ${{ matrix.os }}
permissions:
checks: write
pull-requests: write

strategy:
fail-fast: false
max-parallel: 2
matrix:
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
include:
- os: windows-latest
os-label: Windows
python: "installed"
Expand All @@ -283,8 +382,7 @@ jobs:

- name: Install virtualenv
if: matrix.python == 'venv'
run: |
python3 -m pip install virtualenv
run: python3 -m pip install virtualenv
shell: bash

- name: Download Artifacts
Expand All @@ -294,9 +392,73 @@ jobs:

- name: Publish Test Results
id: test-results
uses: ./composite
uses: ./windows
with:
check_name: Test Results (${{ matrix.os-label }} python ${{ matrix.python }})
files: artifacts\**\*.xml
json_file: "tests.json"
json_suite_details: true
json_test_case_results: true
report_suite_logs: "any"

- name: JSON output
uses: ./misc/action/json-output
with:
json: '${{ steps.test-results.outputs.json }}'
json_file: 'tests.json'

- name: Publish Test Results (Bash)
id: test-results-bash
uses: ./windows/bash
with:
check_name: Test Results (${{ matrix.os-label }} bash python ${{ matrix.python }})
files: artifacts\**\*.xml
json_file: "tests.json"
json_suite_details: true
json_test_case_results: true
report_suite_logs: "any"

- name: JSON output (Bash)
uses: ./misc/action/json-output
with:
json: '${{ steps.test-results-bash.outputs.json }}'
json_file: 'tests.json'

publish-composite:
name: Publish Test Results (${{ matrix.os-label }} composite)
runs-on: ${{ matrix.os }}
permissions:
checks: write
pull-requests: write

strategy:
fail-fast: false
max-parallel: 1
matrix:
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
# test *-latest and newer (because newer eventually become 'latest' and should be tested to work before that)
include:
- os: macos-latest
os-label: macOS
- os: ubuntu-latest
os-label: Linux
- os: windows-latest
os-label: Windows

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Publish Test Results
id: test-results
uses: ./composite
with:
check_name: Test Results (${{ matrix.os-label }} composite python ${{ matrix.python }})
files: |
artifacts/**/*.xml
artifacts\**\*.xml
Expand Down
79 changes: 61 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ publishes the results on GitHub. It supports [JSON (Dart, Mocha), TRX (MSTest, V
and runs on Linux, macOS and Windows.

You can use this action with ![Ubuntu Linux](misc/badge-ubuntu.svg) runners (e.g. `runs-on: ubuntu-latest`)
or ![ARM Linux](misc/badge-arm.svg) self-hosted runners:
or ![ARM Linux](misc/badge-arm.svg) self-hosted runners that support Docker:

```yaml
- name: Publish Test Results
Expand All @@ -36,12 +36,34 @@ or ![ARM Linux](misc/badge-arm.svg) self-hosted runners:
See the [notes on running this action with absolute paths](#running-with-absolute-paths) if you cannot use relative test result file paths.
Use this for ![macOS](misc/badge-macos.svg) (e.g. `runs-on: macos-latest`)
and ![Windows](misc/badge-windows.svg) (e.g. `runs-on: windows-latest`) runners:
Use this for ![macOS](misc/badge-macos.svg) (e.g. `runs-on: macos-latest`) runners:
```yaml
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/macos@v2
if: always()
with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json
```

… and ![Windows](misc/badge-windows.svg) (e.g. `runs-on: windows-latest`) runners:
```yaml
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/composite@v2
uses: EnricoMi/publish-unit-test-result-action/windows@v2
if: always()
with:
files: |
test-results\**\*.xml
test-results\**\*.trx
test-results\**\*.json
```

For **self-hosted** Linux GitHub Actions runners **without Docker** installed, please use:
```yaml
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/linux@v2
if: always()
with:
files: |
Expand All @@ -50,7 +72,7 @@ and ![Windows](misc/badge-windows.svg) (e.g. `runs-on: windows-latest`) runners:
test-results/**/*.json
```

See the [notes on running this action as a composite action](#running-as-a-composite-action) if you run it on Windows or macOS.
See the [notes on running this action as a non-Docker action](#running-as-a-non-docker-action).

If you see the `"Resource not accessible by integration"` error, you have to grant additional [permissions](#permissions), or
[setup the support for pull requests from fork repositories and branches created by Dependabot](#support-fork-repositories-and-dependabot-branches).
Expand Down Expand Up @@ -273,7 +295,7 @@ The list of most notable options:

|Option|Default Value|Description|
|:-----|:-----:|:----------|
|`files`|_no default_|File patterns of test result files. Relative paths are known to work best, while the composite action [also works with absolute paths](#running-with-absolute-paths). Supports `*`, `**`, `?`, and `[]` character ranges. Use multiline string for multiple patterns. Patterns starting with `!` exclude the matching files. There have to be at least one pattern starting without a `!`.|
|`files`|_no default_|File patterns of test result files. Relative paths are known to work best, while the non-Docker action [also works with absolute paths](#running-with-absolute-paths). Supports `*`, `**`, `?`, and `[]` character ranges. Use multiline string for multiple patterns. Patterns starting with `!` exclude the matching files. There have to be at least one pattern starting without a `!`.|
|`check_name`|`"Test Results"`|An alternative name for the check result. Required to be unique for each instance in one workflow.|
|`comment_title`|same as `check_name`|An alternative name for the pull request comment.|
|`comment_mode`|`always`|The action posts comments to pull requests that are associated with the commit. Set to:<br/>`always` - always comment<br/>`changes` - comment when changes w.r.t. the target branch exist<br/>`changes in failures` - when changes in the number of failures and errors exist<br/>`changes in errors` - when changes in the number of (only) errors exist<br/>`failures` - when failures or errors exist<br/>`errors` - when (only) errors exist<br/>`off` - to not create pull request comments.|
Expand Down Expand Up @@ -783,10 +805,14 @@ You can then use the badge via this URL: https://gist.githubusercontent.com/{use
## Running with absolute paths

It is known that this action works best with relative paths (e.g. `test-results/**/*.xml`),
but most absolute paths (e.g. `/tmp/test-results/**/*.xml`) require to use the composite variant
of this action (`uses: EnricoMi/publish-unit-test-result-action/composite@v2`).
but most absolute paths (e.g. `/tmp/test-results/**/*.xml`) require to use the non-Docker variant
of this action:

If you have to use absolute paths with the non-composite variant of this action (`uses: EnricoMi/publish-unit-test-result-action@v2`),
uses: EnricoMi/publish-unit-test-result-action/linux@v2
uses: EnricoMi/publish-unit-test-result-action/macos@v2
uses: EnricoMi/publish-unit-test-result-action/windows@v2

If you have to use absolute paths with the Docker variant of this action (`uses: EnricoMi/publish-unit-test-result-action@v2`),
you have to copy files to a relative path first, and then use the relative path:

```yaml
Expand All @@ -806,14 +832,18 @@ you have to copy files to a relative path first, and then use the relative path:
test-results/**/*.json
```

Using the non-composite variant of this action is recommended as it starts up much quicker.
Using the Docker variant of this action is recommended as it starts up much quicker.

## Running as a composite action
## Running as a non-Docker action

Running this action as a composite action allows to run it on various operating systems as it
does not require Docker. The composite action, however, requires a Python3 environment to be setup
on the action runner. All GitHub-hosted runners (Ubuntu, Windows Server and macOS) provide a suitable
Python3 environment out-of-the-box.
Running this action as below allows to run it on action runners that do not provide Docker:

uses: EnricoMi/publish-unit-test-result-action/linux@v2
uses: EnricoMi/publish-unit-test-result-action/macos@v2
uses: EnricoMi/publish-unit-test-result-action/windows@v2

These actions, however, require a Python3 environment to be setup on the action runner.
All GitHub-hosted runners (Ubuntu, Windows Server and macOS) provide a suitable Python3 environment out-of-the-box.

Self-hosted runners may require setting up a Python environment first:

Expand All @@ -824,6 +854,19 @@ Self-hosted runners may require setting up a Python environment first:
python-version: 3.8
```

Self-hosted runners for Windows require Bash shell to be installed. Easiest way to have one is by installing
Git for Windows, which comes with Git BASH. Make sure that the location of `bash.exe` is part of the `PATH`
environment variable seen by the self-hosted runner.
Start-up of the action is faster with `virtualenv` or `venv`, as well as `wheel` packages are installed.

## Running as a composite action

Running this action via:

uses: EnricoMi/publish-unit-test-result-action/composite@v2

is **deprecated**, please use an action appropriate for your operating system and shell:

- Linux (Bash shell): `uses: EnricoMi/publish-unit-test-result-action/linux@v2`
- macOS (Bash shell): `uses: EnricoMi/publish-unit-test-result-action/macos@v2`
- Windows (PowerShell): `uses: EnricoMi/publish-unit-test-result-action/windows@v2`
- Windows (Bash shell): `uses: EnricoMi/publish-unit-test-result-action/windows/bash@v2`

These are non-Docker variations of this action. For details, see section ["Running as a non-Docker action"](#running-as-a-non-docker-action) above.
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ inputs:
default: 'false'
required: false
files:
description: 'File patterns of test result files. Relative paths are known to work best, while the composite action also works with absolute paths. Supports "*", "**", "?", and "[]" character ranges. Use multiline string for multiple patterns. Patterns starting with "!" exclude the matching files. There have to be at least one pattern starting without a "!".'
description: 'File patterns of test result files. Relative paths are known to work best, while the non-Docker action also works with absolute paths. Supports "*", "**", "?", and "[]" character ranges. Use multiline string for multiple patterns. Patterns starting with "!" exclude the matching files. There have to be at least one pattern starting without a "!".'
required: false
junit_files:
description: 'Deprecated, use "files" option instead.'
Expand Down Expand Up @@ -142,6 +142,7 @@ inputs:
description: 'Prior to v2.6.0, the action used the "/search/issues" REST API to find pull requests related to a commit. If you need to restore that behaviour, set this to "true". Defaults to "false".'
default: 'false'
required: false

outputs:
json:
description: "Test results as JSON"
Expand Down
Loading

0 comments on commit fe2d5fc

Please sign in to comment.