Skip to content

GuillaumeFalourd/assert-command-line-output

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Assert Command Line Output

Public workflows that use this action. Action test on Ubuntu Action test on MacOs Action test on Windows

title

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.


📚 Usage

How does the action work?

how does the action work

Requirements

⚠️ 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.


♻️ Scenarios

1️⃣ Assert file content

Expecting command output to be EQUAL to assert.txt file content

steps:
  - uses: actions/checkout@v3
  - uses: GuillaumeFalourd/[email protected]
    with:
      command_line: ls -lha
      assert_file_path: path/to/assert.txt
      expected_result: PASSED

Expecting command output to be DIFFERENT than the assert.txt file content

steps:
  - uses: actions/checkout@v3
  - uses: GuillaumeFalourd/[email protected]
    with:
      command_line: ls -lha
      assert_file_path: path/to/assert.txt
      expected_result: FAILED

2️⃣ Assert specific file line

Expecting command output line 3 to be EQUAL than the assert.txt file content in line 3

steps:
  - uses: actions/checkout@v3
  - uses: GuillaumeFalourd/[email protected]
    with:
      command_line: ls -lha
      assert_file_path: path/to/assert.txt
      expected_result: PASSED
      specific_line: 3

Expecting command output line 3 to be DIFFERENT than the assert.txt file content in line 3

steps:
  - uses: actions/checkout@v3
  - 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

Expecting command output to contain specific expression

steps:
  - uses: actions/checkout@v3
  - uses: GuillaumeFalourd/[email protected]
    with:
      command_line: ls -lha
      contains: runner
      expected_result: PASSED

Expecting command output NOT to contain specific expression

steps:
  - uses: actions/checkout@v3
  - 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@v3
  - 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

▶️ Action Inputs

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

🔎 Good to know

  • 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:

    • 1️⃣ contains
    • 2️⃣ specific_line
    • 3️⃣ assert_file_path
  • You can access the output.txt file in the repository directory after running the action.


🤝 Contributing

Guidelines

🏅 Licensed

☞ This repository uses the Apache License 2.0