orchestrate all workflows

This commit is contained in:
Krishna Vedala 2020-05-29 21:23:17 -04:00
parent 01183cc5b5
commit e9d29caf6b
5 changed files with 94 additions and 172 deletions

View File

@ -1,23 +0,0 @@
name: C/C++ CI
on: [push]
# push:
# branches: [ master ]
# pull_request:
# branches: [ master ]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@master
with:
submodules: true
- name: configure
run: cmake -B ./build -S .
- name: build
run: cmake --build build

View File

@ -1,4 +1,4 @@
name: Code Formatting
name: Long CI Workflow
on: [push]
# push:
@ -7,7 +7,8 @@ on: [push]
# branches: [ master ]
jobs:
build:
code_format:
name: Code Formatter
runs-on: ubuntu-latest
steps:
- name: requirements
@ -55,3 +56,94 @@ jobs:
line4: "ColumnLimit: 80, AccessModifierOffset: -3 }"
- name: Git Push
run: git pull && git push
update_directory_md:
name: Update Directory.md
needs: code_format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- name: update_directory_md
shell: python
run: |
import os
from typing import Iterator
URL_BASE = "https://github.com/TheAlgorithms/C-Plus-Plus/blob/master"
g_output = []
def good_filepaths(top_dir: str = ".") -> Iterator[str]:
cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
for dirpath, dirnames, filenames in os.walk(top_dir):
dirnames[:] = [d for d in dirnames if d[0] not in "._"]
for filename in filenames:
if os.path.splitext(filename)[1].lower() in cpp_exts:
yield os.path.join(dirpath, filename).lstrip("./")
def md_prefix(i):
return f"{i * ' '}*" if i else "\n##"
def print_path(old_path: str, new_path: str) -> str:
global g_output
old_parts = old_path.split(os.sep)
for i, new_part in enumerate(new_path.split(os.sep)):
if i + 1 > len(old_parts) or old_parts[i] != new_part:
if new_part:
g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}")
return new_path
def build_directory_md(top_dir: str = ".") -> str:
global g_output
old_path = ""
for filepath in sorted(good_filepaths(), key=str.lower):
filepath, filename = os.path.split(filepath)
if filepath != old_path:
old_path = print_path(old_path, filepath)
indent = (filepath.count(os.sep) + 1) if filepath else 0
url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
filename = os.path.splitext(filename.replace("_", " ").title())[0]
g_output.append(f"{md_prefix(indent)} [{filename}]({url})")
return "\n".join(g_output)
with open("DIRECTORY.md", "w") as out_file:
out_file.write(build_directory_md(".") + "\n")
- name: Update DIRECTORY.md
run: |
cat DIRECTORY.md
git config --global user.name github-actions
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git add DIRECTORY.md
git commit -am "updating DIRECTORY.md" || true
git push --force origin HEAD:$GITHUB_REF || true
cpplint:
name: CPPLINT
needs: code_format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
- run: pip install cpplint
- run: cpplint --filter=-legal --recursive .
build:
runs-on: ${{ matrix.os }}
needs: [cpplint, update_directory_md]
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@master
with:
submodules: true
- name: configure
run: cmake -B ./build -S .
- name: build
run: cmake --build build

View File

@ -1,13 +0,0 @@
name: cpplint
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
- run: pip install cpplint
# - run: cpplint --filter= # print out all cpplint rules
- run: cpplint --recursive . || true # all issues to be fixed
# TODO: Remove each filter one at a time and fix those failures
- run: cpplint --filter=-build,-legal,-readability,-runtime,-whitespace --recursive .

View File

@ -1,66 +0,0 @@
# GitHub Action that enables a repo to achieve gradual compliance with cpplint by
# linting only those files that have been added or modified (vs. origin/master).
# 1. runs cpplint only on those files that have been modified vs. origin/master.
# 2. compiles with g++ only those files that have been modified vs. origin/master.
# 3. other optional filepath verifications may be commented out at the end of this file.
# From: https://github.com/cpplint/GitHub-Action-for-cpplint
name: cpplint_modified_files
on: [push, pull_request]
jobs:
cpplint_modified_files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1 # v2 is broken for git diff
- uses: actions/setup-python@v1
- run: python -m pip install cpplint
- run: git remote -v
- run: git branch
- run: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
- run: git diff --diff-filter=dr --name-only origin/master > git_diff.txt
- name: cpplint_modified_files
shell: python
run: |
import os
import subprocess
import sys
print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8
with open("git_diff.txt") as in_file:
modified_files = sorted(in_file.read().splitlines())
print("{} files were modified.".format(len(modified_files)))
cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)]
print(f"{len(cpp_files)} C++ files were modified.")
if not cpp_files:
sys.exit(0)
print("cpplint:")
for cpp_file in cpp_files:
subprocess.run(["cpplint", "--filter=-legal/copyright", cpp_file], check=True, text=True)
print("g++:")
# compile_exts = tuple(".c .c++ .cc .cpp .cu .cxx".split())
# compile_files = [file for file in cpp_files if file.lower().endswith(compile_exts)]
for cpp_file in cpp_files:
subprocess.run(["g++", cpp_file], check=True, text=True)
upper_files = [file for file in cpp_files if file != file.lower()]
if upper_files:
print(f"{len(upper_files)} files contain uppercase characters:")
print("\n".join(upper_files) + "\n")
space_files = [file for file in cpp_files if " " in file or "-" in file]
if space_files:
print(f"{len(space_files)} files contain space or dash characters:")
print("\n".join(space_files) + "\n")
nodir_files = [file for file in cpp_files if file.count(os.sep) != 1]
if nodir_files:
print(f"{len(nodir_files)} files are not in one and only one directory:")
print("\n".join(nodir_files) + "\n")
bad_files = len(upper_files + space_files + nodir_files)
if bad_files:
sys.exit(bad_files)

View File

@ -1,68 +0,0 @@
# This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push
name: update_directory_md
on: [push]
jobs:
update_directory_md:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- name: update_directory_md
shell: python
run: |
import os
from typing import Iterator
URL_BASE = "https://github.com/TheAlgorithms/C-Plus-Plus/blob/master"
g_output = []
def good_filepaths(top_dir: str = ".") -> Iterator[str]:
cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
for dirpath, dirnames, filenames in os.walk(top_dir):
dirnames[:] = [d for d in dirnames if d[0] not in "._"]
for filename in filenames:
if os.path.splitext(filename)[1].lower() in cpp_exts:
yield os.path.join(dirpath, filename).lstrip("./")
def md_prefix(i):
return f"{i * ' '}*" if i else "\n##"
def print_path(old_path: str, new_path: str) -> str:
global g_output
old_parts = old_path.split(os.sep)
for i, new_part in enumerate(new_path.split(os.sep)):
if i + 1 > len(old_parts) or old_parts[i] != new_part:
if new_part:
g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}")
return new_path
def build_directory_md(top_dir: str = ".") -> str:
global g_output
old_path = ""
for filepath in sorted(good_filepaths(), key=str.lower):
filepath, filename = os.path.split(filepath)
if filepath != old_path:
old_path = print_path(old_path, filepath)
indent = (filepath.count(os.sep) + 1) if filepath else 0
url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
filename = os.path.splitext(filename.replace("_", " ").title())[0]
g_output.append(f"{md_prefix(indent)} [{filename}]({url})")
return "\n".join(g_output)
with open("DIRECTORY.md", "w") as out_file:
out_file.write(build_directory_md(".") + "\n")
- name: Update DIRECTORY.md
run: |
cat DIRECTORY.md
git config --global user.name github-actions
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git add DIRECTORY.md
git commit -am "updating DIRECTORY.md" || true
git push --force origin HEAD:$GITHUB_REF || true