Skip to content

feat: improve the Awesome Workflow #2408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 18 additions & 39 deletions .github/workflows/awesome_workflow.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,40 @@
name: Awesome CI Workflow

on: [push, pull_request]
# push:
# branches: [ master ]
# pull_request:
# branches: [ master ]
permissions:
contents: write

jobs:
MainSequence:
name: Code Formatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1 # v2 is broken for git diff
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
- name: requirements
run: |
sudo apt -qq -y update
sudo apt -qq install clang-tidy-10 clang-format-10
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 David Leal
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git config --global user.name github-actions[bot]
git config --global user.email '[email protected]'
- name: Filename Formatter
run: |
IFS=$'\n'
for fname in `find . -type f -name '*.cpp' -o -name '*.cc' -o -name '*.h'`
do
echo "${fname}"
new_fname=`echo ${fname} | tr ' ' '_'`
echo " ${new_fname}"
new_fname=`echo ${new_fname} | tr 'A-Z' 'a-z'`
echo " ${new_fname}"
new_fname=`echo ${new_fname} | tr '-' '_'`
echo " ${new_fname}"
new_fname=${new_fname/.cc/.cpp}
echo " ${new_fname}"
if [ ${fname} != ${new_fname} ]
then
echo " ${fname} --> ${new_fname}"
git "mv" "${fname}" ${new_fname}
fi
done
git commit -am "formatting filenames ${GITHUB_SHA::8}" || true

wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/filename_formatter.sh
chmod u=rwx,g=r,o=r filename_formatter.sh
./filename_formatter.sh . .cpp,.hpp
- name: Update DIRECTORY.md
run: |
wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/build_directory_md.py
python3 build_directory_md.py C-Plus-Plus . .cpp,.hpp,.h > DIRECTORY.md
git commit -m "updating DIRECTORY.md" DIRECTORY.md || true
- name: Get file changes
run: |
git remote -v
git branch
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
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
Expand All @@ -81,10 +60,10 @@ jobs:
if not cpp_files:
sys.exit(0)

subprocess.run(["clang-tidy-10", "--fix", "-p=build", "--extra-arg=-std=c++11", *cpp_files, "--"],
subprocess.run(["clang-tidy", "--fix", "-p=build", "--extra-arg=-std=c++11", *cpp_files, "--"],
check=True, text=True, stderr=subprocess.STDOUT)

subprocess.run(["clang-format-10", "-i", "-style=file", *cpp_files],
subprocess.run(["clang-format", "-i", "-style=file", *cpp_files],
check=True, text=True, stderr=subprocess.STDOUT)

upper_files = [file for file in cpp_files if file != file.lower()]
Expand All @@ -108,8 +87,8 @@ jobs:
- 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 --force origin HEAD:$GITHUB_REF || true
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
Expand All @@ -119,7 +98,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3
with:
submodules: true
- run: cmake -B ./build -S .
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "CodeQL"

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: cpp
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
#
# In our case, this would be a CMake build step.

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:cpp"
48 changes: 0 additions & 48 deletions .github/workflows/codeql_analysis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3
with:
submodules: true
- name: Install requirements
Expand All @@ -19,7 +19,7 @@ jobs:
- name: build
run: cmake --build build -t doc
- name: gh-pages
uses: actions/checkout@master
uses: actions/checkout@v3
with:
ref: "gh-pages"
clean: false
Expand Down