Skip to content

test: add CTest to cmake to enable testing #8935

test: add CTest to cmake to enable testing

test: add CTest to cmake to enable testing #8935

name: Awesome CI Workflow
on: [push, pull_request]
permissions:
pull-requests: write
contents: write
jobs:
MainSequence:
name: Code Formatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
- name: requirements
run: |
sudo apt-get -qq update
sudo apt-get -qq install clang-tidy clang-format
# checks are passing with less errors when used with this version.
# The default installs v6.0 which did not work out well in my tests
- name: Setup Git Specs
run: |
git config --global user.name github-actions[bot]
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Filename Formatter
run: |
wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/filename_formatter.sh
chmod +x filename_formatter.sh
./filename_formatter.sh . .cpp,.hpp
- name: Get file changes
run: |
git branch
git diff --diff-filter=dr --name-only origin/master > git_diff.txt
echo "Files changed-- `cat git_diff.txt`"
- name: Configure for static lint checks
# compiling first gives clang-tidy access to all the header files and settings used to compile the programs.
# This will check for macros, if any, on linux and not for Windows. But the use of portability checks should
# be able to catch any errors for other platforms.
run: cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
- name: Lint modified files
shell: bash
run: python3 scripts/file_linter.py
- name: Commit and push changes
run: |
git diff DIRECTORY.md
git commit -am "clang-format and clang-tidy fixes for ${GITHUB_SHA::8}" || true
git push origin HEAD:$GITHUB_REF || true
build:
name: Compile checks
runs-on: ${{ matrix.os }}
needs: [MainSequence]
permissions:
pull-requests: write
issues: write
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- run: |
cmake -B ./build -S .
cmake --build build --parallel 4
- name: Label on PR fail
uses: actions-ecosystem/action-add-labels@v1
if: ${{ failure() && matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }}
with:
labels: "automated build is failing"
test:
name: Testing pull request
runs-on: ${{ matrix.os }}
needs: [build]
permissions:
pull-requests: write
issues: write
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: checkout
uses: actions/checkout@v4
- name: build
run: |
cmake -B build -S . -DBENABLE_TESTING=ON
cmake --build build --parallel 4
# The timeout below is to catch the files with user input in their main function.
# It should be removed eventually when all the files are clear of user input.
- name: test
run: |
ctest --test-dir build --timeout 5 --parallel 4
- name: Label on PR fail
uses: actions-ecosystem/action-add-labels@v1
if: ${{ failure() && github.event_name == 'pull_request' }}
with:
labels: "automated tests are failing"