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.
⚠️ The 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.
1️⃣ Assert file content
assert.txt
file contentsteps:
- uses: actions/checkout@v4
- uses: GuillaumeFalourd/[email protected]
with:
command_line: ls -lha
assert_file_path: path/to/assert.txt
expected_result: PASSED
assert.txt
file contentsteps:
- uses: actions/checkout@v4
- uses: GuillaumeFalourd/[email protected]
with:
command_line: ls -lha
assert_file_path: path/to/assert.txt
expected_result: FAILED
2️⃣ Assert specific file line
assert.txt
file content in line 3steps:
- uses: actions/checkout@v4
- uses: GuillaumeFalourd/[email protected]
with:
command_line: ls -lha
assert_file_path: path/to/assert.txt
expected_result: PASSED
specific_line: 3
assert.txt
file content in line 3steps:
- uses: actions/checkout@v4
- uses: GuillaumeFalourd/[email protected]
with:
command_line: ls -lha
assert_file_path: path/to/assert.txt
expected_result: FAILED
specific_line: 3
3️⃣ Assert specific expression
steps:
- uses: actions/checkout@v4
- uses: GuillaumeFalourd/[email protected]
with:
command_line: ls -lha
contains: runner
expected_result: PASSED
steps:
- uses: actions/checkout@v4
- uses: GuillaumeFalourd/[email protected]
with:
command_line: ls -lha
contains: error
expected_result: FAILED
4️⃣ Multiple-line commands
The assert may fail while using multiple-line commands. When this is necessary, use single quotes '
.
steps:
- uses: actions/checkout@v4
- uses: GuillaumeFalourd/[email protected]
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
|
work_dir | NO | Use the input as working directory to run the action. |
At least one type of assert between contains
, specific_line
and assert_file_path
has to be configured.
If more than one type of assert is set, the priority between them is:
contains
specific_line
assert_file_path
You can access the output.txt file in the repository directory after running the action.
☞ This repository uses the Apache License 2.0