GitHub Action
Assert Command Line Output
Github Action to assert / check a command line output 🕵️⚙️🖥
This action allows to compare a command line output (success or error) with a file content located on the repository, or to check if it contains a specific expression.
actions/checkout
is mandatory to use this action, as it will be necessary to access the repository files, or to access the command line output file after the action execution.
☞ Note: This action gathers the logic from the command-output-file-action and the diff-action.
steps:
- uses: actions/checkout@v3
- uses: GuillaumeFalourd/assert-command-line-output@v2.2
with:
command_line: ls -lha
assert_file_path: path/to/assert.txt
expected_result: PASSED
steps:
- uses: actions/checkout@v3
- uses: GuillaumeFalourd/assert-command-line-output@v2.2
with:
command_line: ls -lha
assert_file_path: path/to/assert.txt
expected_result: FAILED
steps:
- uses: actions/checkout@v3
- uses: GuillaumeFalourd/assert-command-line-output@v2.2
with:
command_line: ls -lha
assert_file_path: path/to/assert.txt
expected_result: PASSED
specific_line: 3
steps:
- uses: actions/checkout@v3
- uses: GuillaumeFalourd/assert-command-line-output@v2.2
with:
command_line: ls -lha
assert_file_path: path/to/assert.txt
expected_result: FAILED
specific_line: 3
steps:
- uses: actions/checkout@v3
- uses: GuillaumeFalourd/assert-command-line-output@v2.2
with:
command_line: ls -lha
contains: runner
expected_result: PASSED
steps:
- uses: actions/checkout@v3
- uses: GuillaumeFalourd/assert-command-line-output@v2.2
with:
command_line: ls -lha
contains: error
expected_result: FAILED
The assert may fail while using multiple-line commands. When this is necessary, use single quotes '
.
steps:
- uses: actions/checkout@v3
- uses: GuillaumeFalourd/assert-command-line-output@v2.2
with:
command_line: |
'a_very_long_command --that --need
--multiple --lines --to --write'
assert_file_path: path/to/assert.txt
expected_result: PASSED
Field | Mandatory | Observation |
---|---|---|
command_line | YES | Command Line to assert / check. e.g: ls -lha |
assert_file_path | NO | Path to assert file that will be compared to command line output. e.g: path/to/assert.txt |
specific_line | NO | Specific line to check from output file with assert file. NEEDS assert_file_path configured. e.g: 1 (integer value only) |
contains | NO | String expression to check on the command line output. e.g: string expression |
expected_result | NO | Expected assert output. e.g: PASSED (default) or FAILED |
-
At least one type of assert between
contains
,specific_line
andassert_file_path
has to be configured. -
If more than one type of assert is set, the priority between them is:
- 1️⃣
contains
- 2️⃣
specific_line
- 3️⃣
assert_file_path
- 1️⃣
-
You can access the output.txt file in the repository directory after running the action.
☞ This repository uses the Apache License 2.0