Skip to content

Commit 04a1ab0

Browse files
feat: improve the Awesome Workflow (#2408)
* fix: Awesome Workflow issues Thanks to @tjgurwara99 for the original fix: TheAlgorithms/C#1176 * chore: apply suggestions from code review Co-authored-by: Taj <[email protected]> * feat: various improvements * chore: apply suggestions from code review Co-authored-by: Taj <[email protected]>
1 parent 9ef438f commit 04a1ab0

File tree

4 files changed

+71
-89
lines changed

4 files changed

+71
-89
lines changed

.github/workflows/awesome_workflow.yml

+18-39
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,40 @@
11
name: Awesome CI Workflow
2-
32
on: [push, pull_request]
4-
# push:
5-
# branches: [ master ]
6-
# pull_request:
7-
# branches: [ master ]
3+
permissions:
4+
contents: write
85

96
jobs:
107
MainSequence:
118
name: Code Formatter
129
runs-on: ubuntu-latest
1310
steps:
14-
- uses: actions/checkout@v1 # v2 is broken for git diff
15-
- uses: actions/setup-python@v2
11+
- uses: actions/checkout@v3
12+
with:
13+
fetch-depth: 0
14+
- uses: actions/setup-python@v4
1615
- name: requirements
1716
run: |
18-
sudo apt -qq -y update
19-
sudo apt -qq install clang-tidy-10 clang-format-10
17+
sudo apt-get -qq update
18+
sudo apt-get -qq install clang-tidy clang-format
2019
# checks are passing with less errors when used with this version.
2120
# The default installs v6.0 which did not work out well in my tests
2221
- name: Setup Git Specs
2322
run: |
24-
git config --global user.name David Leal
25-
git config --global user.email '[email protected]'
26-
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
23+
git config --global user.name github-actions[bot]
24+
git config --global user.email '[email protected]'
2725
- name: Filename Formatter
2826
run: |
29-
IFS=$'\n'
30-
for fname in `find . -type f -name '*.cpp' -o -name '*.cc' -o -name '*.h'`
31-
do
32-
echo "${fname}"
33-
new_fname=`echo ${fname} | tr ' ' '_'`
34-
echo " ${new_fname}"
35-
new_fname=`echo ${new_fname} | tr 'A-Z' 'a-z'`
36-
echo " ${new_fname}"
37-
new_fname=`echo ${new_fname} | tr '-' '_'`
38-
echo " ${new_fname}"
39-
new_fname=${new_fname/.cc/.cpp}
40-
echo " ${new_fname}"
41-
if [ ${fname} != ${new_fname} ]
42-
then
43-
echo " ${fname} --> ${new_fname}"
44-
git "mv" "${fname}" ${new_fname}
45-
fi
46-
done
47-
git commit -am "formatting filenames ${GITHUB_SHA::8}" || true
48-
27+
wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/filename_formatter.sh
28+
chmod +x filename_formatter.sh
29+
./filename_formatter.sh . .cpp,.hpp
4930
- name: Update DIRECTORY.md
5031
run: |
5132
wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/build_directory_md.py
5233
python3 build_directory_md.py C-Plus-Plus . .cpp,.hpp,.h > DIRECTORY.md
5334
git commit -m "updating DIRECTORY.md" DIRECTORY.md || true
5435
- name: Get file changes
5536
run: |
56-
git remote -v
5737
git branch
58-
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
5938
git diff --diff-filter=dr --name-only origin/master > git_diff.txt
6039
echo "Files changed-- `cat git_diff.txt`"
6140
- name: Configure for static lint checks
@@ -81,10 +60,10 @@ jobs:
8160
if not cpp_files:
8261
sys.exit(0)
8362
84-
subprocess.run(["clang-tidy-10", "--fix", "-p=build", "--extra-arg=-std=c++11", *cpp_files, "--"],
63+
subprocess.run(["clang-tidy", "--fix", "-p=build", "--extra-arg=-std=c++11", *cpp_files, "--"],
8564
check=True, text=True, stderr=subprocess.STDOUT)
8665
87-
subprocess.run(["clang-format-10", "-i", "-style=file", *cpp_files],
66+
subprocess.run(["clang-format", "-i", "-style=file", *cpp_files],
8867
check=True, text=True, stderr=subprocess.STDOUT)
8968
9069
upper_files = [file for file in cpp_files if file != file.lower()]
@@ -108,8 +87,8 @@ jobs:
10887
- name: Commit and push changes
10988
run: |
11089
git diff DIRECTORY.md
111-
git commit -am "clang-format and clang-tidy fixes for ${GITHUB_SHA::8}" || true
112-
git push --force origin HEAD:$GITHUB_REF || true
90+
git commit -am "clang-format and clang-tidy fixes for ${GITHUB_SHA::8}" || true
91+
git push origin HEAD:$GITHUB_REF || true
11392
11493
build:
11594
name: Compile checks
@@ -119,7 +98,7 @@ jobs:
11998
matrix:
12099
os: [ubuntu-latest, windows-latest, macOS-latest]
121100
steps:
122-
- uses: actions/checkout@master
101+
- uses: actions/checkout@v3
123102
with:
124103
submodules: true
125104
- run: cmake -B ./build -S .

.github/workflows/codeql.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
analyze:
11+
name: Analyze
12+
runs-on: ubuntu-latest
13+
permissions:
14+
actions: read
15+
contents: read
16+
security-events: write
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v3
20+
- name: Initialize CodeQL
21+
uses: github/codeql-action/init@v2
22+
with:
23+
languages: cpp
24+
# If you wish to specify custom queries, you can do so here or in a config file.
25+
# By default, queries listed here will override any specified in a config file.
26+
# Prefix the list here with "+" to use these queries and those in the config file.
27+
28+
# 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
29+
# queries: security-extended,security-and-quality
30+
31+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
32+
# If this step fails, then you should remove it and run the build manually (see below)
33+
- name: Autobuild
34+
uses: github/codeql-action/autobuild@v2
35+
36+
# ℹ️ Command-line programs to run using the OS shell.
37+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
38+
39+
# If the Autobuild fails above, remove it and uncomment the following three lines.
40+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
41+
42+
# - run: |
43+
# echo "Run, Build Application using script"
44+
# ./location_of_script_within_repo/buildscript.sh
45+
#
46+
# In our case, this would be a CMake build step.
47+
48+
- name: Perform CodeQL Analysis
49+
uses: github/codeql-action/analyze@v2
50+
with:
51+
category: "/language:cpp"

.github/workflows/codeql_analysis.yml

-48
This file was deleted.

.github/workflows/gh-pages.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99
runs-on: macos-latest
1010
steps:
11-
- uses: actions/checkout@master
11+
- uses: actions/checkout@v3
1212
with:
1313
submodules: true
1414
- name: Install requirements
@@ -19,7 +19,7 @@ jobs:
1919
- name: build
2020
run: cmake --build build -t doc
2121
- name: gh-pages
22-
uses: actions/checkout@master
22+
uses: actions/checkout@v3
2323
with:
2424
ref: "gh-pages"
2525
clean: false

0 commit comments

Comments
 (0)